vis-config

lua scripts to configure vis editor

git clone https://9o.is/git/vis-config.git

lspc.lua

(4531B)


      1 --- State and methods of the language server client.
      2 -- This module table is returned when requiring the vis-lspc plugin.
      3 -- @module lspc
      4 -- @author Florian Fischer
      5 -- @license GPL-3
      6 -- @copyright Florian Fischer 2021-2024
      7 --- Initial state of the client.
      8 -- This includes the default configuration that can be modified in
      9 -- your visrc.lua file.
     10 local lspc = {
     11   -- mapping language server names to their state tables
     12   running = {},
     13   open_files = {},
     14   name = 'vis-lspc',
     15   version = '0.1.8',
     16   -- write log messages to lspc.log_file
     17   logging = false,
     18   log_file = nil,
     19   -- automatically start a language server when a new window is opened
     20   autostart = true,
     21   -- program used to let the user make choices
     22   -- The available choices are passed to <menu_cmd> on stdin separated by '\n'
     23   menu_cmd = 'vis-menu -l 10',
     24   -- program used to ask the user for confirmation
     25   confirm_cmd = 'vis-menu',
     26 
     27   -- should diagnostics be highlighted if available
     28   highlight_diagnostics = 'line',
     29   -- style id used by lspc to register the style used to highlight diagnostics
     30   -- by default win.STYLE_LEXER_MAX is used (the last style id available for the lexer styles). See vis/ui.h.
     31   diagnostic_style_id = nil,
     32   -- styles used by lspc to highlight the diagnostic range
     33   -- must be set by the user
     34   diagnostic_styles = {
     35     error = 'fore:red,italics,reverse',
     36     warning = 'fore:yellow,italics,reverse',
     37     information = 'fore:yellow,italics,reverse',
     38     hint = 'fore:yellow,italics,reverse',
     39   },
     40 
     41   -- restore the position of the primary curser after applying a workspace edit
     42   workspace_edit_remember_cursor = true,
     43 
     44   -- message level to show in the UI when receiving messages from the server
     45   -- Error = 1, Warning = 2, Info = 3, Log = 4
     46   message_level = 3,
     47 
     48   -- How to present messages to the user.
     49   -- 'message': use vis:message; 'open': use a new split window allowing for syntax highlighting
     50   show_message = 'message',
     51 
     52   -- Globs that are considered to be workspace roots (e.g. ".git" or ".hg")
     53   universal_root_globs = {},
     54 
     55   -- Should a file's directory be used as workspace root if no explicit root was found.
     56   fallback_dirname_as_root = false,
     57 
     58   -- events
     59   events = {
     60     LS_INITIALIZED = 'LspcEvent::LS_INITIALIZED',
     61     LS_DID_OPEN = 'LspcEvent::LS_DID_OPEN',
     62   },
     63 }
     64 
     65 -- check if fzf is available and use fzf instead of vis-menu per default
     66 if os.execute('type fzf >/dev/null 2>/dev/null') then
     67   lspc.menu_cmd = 'fzf'
     68 end
     69 
     70 local supported_markup_kind = {'markdown'}
     71 
     72 local goto_methods_capabilities = {
     73   linkSupport = true,
     74   dynamicRegistration = false,
     75 }
     76 
     77 --- ClientCapabilities we tell the language server when calling "initialize".
     78 local client_capabilites = {
     79   workspace = {
     80     configuration = true,
     81     didChangeConfiguration = {dynamicRegistration = false},
     82   },
     83   textDocument = {
     84     synchronization = {dynamicRegistration = false, didSave = true},
     85     -- ask the server to send us only markdown completionItems
     86     completion = {
     87       dynamicRegistration = false,
     88       completionItem = {documentationFormat = supported_markup_kind},
     89     },
     90     -- ask the server to send us only markdown hover results
     91     hover = {dynamicRegistration = false, contentFormat = supported_markup_kind},
     92     -- ask the server to send us only markdown signatureHelp results
     93     signatureHelp = {
     94       dynamicRegistration = false,
     95       signatureInformation = {documentationFormat = supported_markup_kind},
     96     },
     97     declaration = {dynamicRegistration = false, linkSupport = true},
     98     definition = goto_methods_capabilities,
     99     publishDiagnostics = {relatedInformation = false},
    100     typeDefinition = goto_methods_capabilities,
    101     implementation = goto_methods_capabilities,
    102     references = {dynamicRegistration = false},
    103     rename = {
    104       dynamicRegistration = false,
    105       prepareSupport = false,
    106       honorsChangeAnnotations = false,
    107     },
    108   },
    109   window = {workDoneProgress = false, showDocument = {support = false}},
    110 }
    111 
    112 lspc.client_capabilites = client_capabilites
    113 
    114 local Lspc = {}
    115 
    116 --- Log a message.
    117 -- @string: the message to log
    118 function Lspc:log(msg)
    119   self.logger:log(msg)
    120 end
    121 
    122 --- Present a warning to the user.
    123 -- @string: the warning message
    124 function Lspc:warn(msg)
    125   local warning = 'LSPC Warning: ' .. msg
    126   self.logger:log(warning)
    127   vis:info(warning)
    128 end
    129 
    130 --- Present an error to the user.
    131 -- @string: the error message
    132 function Lspc:err(msg)
    133   local warning = 'LSPC Error: ' .. msg
    134   self.logger:log(warning)
    135   vis:info(warning)
    136 end
    137 
    138 setmetatable(lspc, {__index = Lspc})
    139 
    140 return lspc