autoload/lsp/lsp.vim | 7 ++++++- autoload/lsp/lspserver.vim | 15 ++++++--------- doc/lsp.txt | 24 +++++++++++++++++++++--- diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 8dd73dcfc3b4ad468b1be1aa955a58dcafdbe3e8..c29f1c451bf0bd7347d2103dd4ff6c53cd370c2c 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -497,7 +497,12 @@ util.ErrMsg('Error: Setting of omnicompl ' .. server.omnicompl .. ' is not a Boolean') return endif - var lspserver: dict = lserver.NewLspServer(server.path, args) + if !server->has_key('sync') + server['sync'] = v:false + endif + + var lspserver: dict = lserver.NewLspServer(server.path, args, + \ server.sync) if server.filetype->type() == v:t_string LspAddServer(server.filetype, lspserver) diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 7559fe4cf366e72809f1302db4e6258adfa2a2d5..2c4e25724e6d1da9fdab861442a23766924bc611 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -77,9 +77,7 @@ enddef # Start a LSP server # -# If 'isSync' is true, then waits for the server to send the initialize -# response message. -def StartServer(lspserver: dict, isSync: bool = false): number +def StartServer(lspserver: dict): number if lspserver.running util.WarnMsg("LSP server for is already running") return 0 @@ -117,7 +115,7 @@ lspserver.job = job lspserver.running = true - lspserver.initServer(isSync) + lspserver.initServer() return 0 enddef @@ -125,9 +123,7 @@ # Request: 'initialize' # Param: InitializeParams # -# If 'isSync' is true, then waits for the server to send the initialize -# response message. -def InitServer(lspserver: dict, isSync: bool = false) +def InitServer(lspserver: dict) var req = lspserver.createRequest('initialize') # client capabilities (ClientCapabilities) @@ -176,7 +172,7 @@ initparams.capabilities = clientCaps req.params->extend(initparams) lspserver.sendMessage(req) - if isSync + if lspserver.sync lspserver.waitForResponse(req) endif enddef @@ -1020,10 +1016,11 @@ echo k .. ": " .. lspserver.caps[k]->string() endfor enddef -export def NewLspServer(path: string, args: list): dict +export def NewLspServer(path: string, args: list, isSync: bool): dict var lspserver: dict = { path: path, args: args, + sync: isSync, running: false, ready: false, job: v:none, diff --git a/doc/lsp.txt b/doc/lsp.txt index 96158f0f7d85de8fa4bde28ddfafc00022be88e7..3dee5e256655cb6e656a538f59f5d9f68f7d307f 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -154,10 +154,10 @@ call LspAddServer(lspServers) < Depending on the location of the typescript and python pyls language servers installed in your system, update the 'path' in the above snippet -appripriately. +appropriately. -Another example, for adding the LSP servers for the C, C++, Shell script and -Vim file types: > +Another example, for adding the LSP servers for the C, C++, Golang, Rust, +Shell script and Vim file types: > let lspServers = [ \ #{ @@ -165,6 +165,20 @@ \ filetype: ['c', 'cpp'], \ path: '/usr/local/bin/clangd', \ args: ['--background-index'] \ }, + \ #{ + \ filetype: ['go', 'gomod', 'gohtmltmpl', 'gotexttmpl'], + \ path: '/home/dza/.go/bin/gopls', + \ args: [], + \ sync: v:true, + \ omnicompl: v:true, + \ }, + \ #{ + \ filetype: ['rust'], + \ path: '/home/dza/.cargo/bin/rust-analyzer', + \ args: [], + \ sync: v:true, + \ omnicompl: v:true, + \ }, \ #{ \ filetype: 'sh', \ path: '/usr/local/bin/bash-language-server', @@ -189,6 +203,10 @@ args a list of command-line arguments passed to the LSP server. Each argument is a separate List item. omnicompl a boolean value that enables (true) or disables (false) omni-completion for this file type. + sync (Optional) for lsp servers that responds to a + 'initialize'-request with a 'initialzed' response this + should be set to 'v:true'. By default this is set to + 'v:false'. The LSP servers are added using the LspAddServer() function. This function accepts a list of LSP servers with the above information.