README.md | 9 +++++++++ autoload/lsp/lsp.vim | 16 ++++++++++++++-- autoload/lsp/lspserver.vim | 6 +++++- doc/lsp.txt | 19 +++++++++++++++++-- diff --git a/README.md b/README.md index e3bfcdf1d6508d91b0b57744f9cc36727af9dad2..ce5bf9bae562aec98a0cc050be57253e49457a5b 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,15 @@ \ #{ \ filetype: ['fortran'], \ path: '/usr/local/bin/fortls', \ args: ['--nthreads=1', '--use_signature_help', '--hover_signature'] + \ }, + \ #{ + \ filetype: ['php'], + \ path: '/usr/local/bin/intelephense', + \ args: ['--stdio'], + \ syncInit: v:true, + \ initializationOptions: { + \ licenceKey: 'xxxxxxxxxxxxxxx' + \ } \ } \ ] call LspAddServer(lspServers) diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 8fbc9cf7386b4a5d13f33bdbbb038fcc7b1785a2..e2398cd80ea9fbdb74a4b668d3dbe4379dc339b9 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -492,6 +492,16 @@ args = server.args else endif + + var initializationOptions: dict = {} + if server->has_key('initializationOptions') + if server.initializationOptions->type() != v:t_dict + util.ErrMsg('Error: initializationOptions for LSP server ' .. server.initializationOptions .. ' is not a Dictionary') + return + endif + initializationOptions = server.initializationOptions + endif + if server.omnicompl->type() != v:t_bool util.ErrMsg('Error: Setting of omnicompl ' .. server.omnicompl .. ' is not a Boolean') return @@ -501,8 +511,10 @@ if !server->has_key('syncInit') server.syncInit = v:false endif - var lspserver: dict = lserver.NewLspServer(server.path, args, - server.syncInit) + var lspserver: dict = lserver.NewLspServer(server.path, + args, + server.syncInit, + initializationOptions) if server.filetype->type() == v:t_string LspAddServer(server.filetype, lspserver) diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index ad8e9f8fa3bb5fa2edafaa2b8efcf4fb0fe1881a..13436af1405fd3c0057155d7638aaa59bb4ad933 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -169,6 +169,9 @@ uri: util.LspFileToUri(curdir) }] initparams.trace = 'off' initparams.capabilities = clientCaps + if !empty(lspserver.initializationOptions) + initparams.initializationOptions = lspserver.initializationOptions + endif req.params->extend(initparams) lspserver.sendMessage(req) @@ -1016,11 +1019,12 @@ echo k .. ": " .. lspserver.caps[k]->string() endfor enddef -export def NewLspServer(path: string, args: list, isSync: bool): dict +export def NewLspServer(path: string, args: list, isSync: bool, initializationOptions: dict): dict var lspserver: dict = { path: path, args: args, syncInit: isSync, + initializationOptions: initializationOptions, running: false, ready: false, job: v:none, diff --git a/doc/lsp.txt b/doc/lsp.txt index ccf282adbb5dad2942d5eb9cc129a15650ed8a2c..2678fe1a057b7fedd0da4ac4f2075985a95be404 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -157,7 +157,7 @@ installed in your system, update the 'path' in the above snippet appropriately. Another example, for adding the LSP servers for the C, C++, Golang, Rust, -Shell script and Vim file types: > +Shell script, Vim script and PHP file types: > let lspServers = [ \ #{ @@ -186,7 +186,16 @@ \ #{ \ filetype: ['vim'], \ path: '/usr/local/bin/vim-language-server', \ args: ['--stdio'] - \ } + \ }, + \ #{ + \ filetype: ['php'], + \ path: '/usr/local/bin/intelephense', + \ args: ['--stdio'], + \ syncInit: v:true, + \ initializationOptions: { + \ licenceKey: 'xxxxxxxxxxxxxxx' + \ } + \ } \ ] call LspAddServer(lspServers) < @@ -208,6 +217,12 @@ message this should be set to 'v:true'. If this is set to true, then a synchronous call is used to initialize the LSP server, otherwise the server is initialized asynchronously. By default this is set to 'v:false'. + initializationOptions + (Optional) for lsp servers (e.g. intelephense) some + additional initialization options may be required + or useful for initialization. Those can be provided in + this dictionary and if present will be transmitted to + the lsp server. The LSP servers are added using the LspAddServer() function. This function accepts a list of LSP servers with the above information.