autoload/lsp.vim | 28 ++++++++++++++-------------- doc/lsp.txt | 17 +++++++---------- diff --git a/autoload/lsp.vim b/autoload/lsp.vim index 283c41aa741e88448fdc0eaf794c9a6a098100d9..62124ca332d124f52bb3a53e76c8b03103171e42 100644 --- a/autoload/lsp.vim +++ b/autoload/lsp.vim @@ -21,8 +21,8 @@ # filetype to LSP server map var ftypeServerMap: dict> = {} -# filetype to omnicompl map -var omnicomplFtypeMap: dict = {} +# per-filetype omni-completion enabled/disabled table +var ftypeOmniCtrlMap: dict = {} # Buffer number to LSP server map var bufnrToServer: dict> = {} @@ -58,15 +58,15 @@ def s:lspAddServer(ftype: string, lspserver: dict) ftypeServerMap->extend({[ftype]: lspserver}) enddef -# Return bool of omnicompl for a specific filetype. -# Return false if not found. -def s:lspBoolOmnicompl(ftype: string): bool - return omnicomplFtypeMap->get(ftype, v:false) +# Returns true if omni-completion is enabled for filetype 'ftype'. +# Otherwise, returns false. +def s:lspOmniComplEnabled(ftype: string): bool + return ftypeOmniCtrlMap->get(ftype, v:false) enddef -# Reg bool of omnicompl for a filetype. -def s:lspRegOmnicompl(ftype: string, omnicompl: bool) - omnicomplFtypeMap->extend({[ftype]: omnicompl}) +# Enables or disables omni-completion for filetype 'fype' +def s:lspOmniComplSet(ftype: string, enabled: bool) + ftypeOmniCtrlMap->extend({[ftype]: enabled}) enddef def lsp#enableServerTrace() @@ -297,7 +297,7 @@ autocmd TextChangedI call lsp#complete() # in insert mode stops completion and inserts a inoremap pumvisible() ? "\\" : "\" else - if s:lspBoolOmnicompl(ftype) + if s:lspOmniComplEnabled(ftype) setbufvar(bnr, '&omnifunc', 'lsp#omniFunc') endif endif @@ -357,7 +357,7 @@ ErrMsg('Error: LSP server information is missing filetype or path or args') continue endif if !server->has_key('omnicompl') - # Default true if didnot reg + # Enable omni-completion by default server['omnicompl'] = v:true endif @@ -370,7 +370,7 @@ ErrMsg('Error: Arguments for LSP server ' .. server.args .. ' is not a List') return endif if server.omnicompl->type() != v:t_bool - ErrMsg('Error: Setting of omnicompl ' .. server.omnicompl .. ' is not a Bool') + ErrMsg('Error: Setting of omnicompl ' .. server.omnicompl .. ' is not a Boolean') return endif @@ -378,11 +378,11 @@ var lspserver: dict = NewLspServer(server.path, server.args) if server.filetype->type() == v:t_string s:lspAddServer(server.filetype, lspserver) - s:lspRegOmnicompl(server.filetype, server.omnicompl) + s:lspOmniComplSet(server.filetype, server.omnicompl) elseif server.filetype->type() == v:t_list for ftype in server.filetype s:lspAddServer(ftype, lspserver) - s:lspRegOmnicompl(server.filetype, server.omnicompl) + s:lspOmniComplSet(ftype, server.omnicompl) endfor else ErrMsg('Error: Unsupported file type information "' .. diff --git a/doc/lsp.txt b/doc/lsp.txt index 0acef02147de7864feb9a706fa3aa732fcb988f2..121ee9588dfd9987df03b8c538261415281c3d75 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -2,7 +2,7 @@ *lsp.txt* Language Server Protocol (LSP) Plugin for Vim9 Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com) For Vim version 8.2.2342 and above -Last change: Jan 31, 2021 +Last change: Feb 24, 2021 ============================================================================== *lsp-license* @@ -166,6 +166,8 @@ path complete path to the LSP server executable (without any arguments). 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. The LSP servers are added using the lsp#addServer() function. This function accepts a list of LSP servers with the above information. @@ -365,16 +367,13 @@ It sets the 'omnifunc' option for the buffers which have a registered LSP server. To complete a symbol in insert mode manually, you can press CTRL-X CTRL-O to invoke completion using the items suggested by the LSP server. -And also indeed e.g: > +You can also enable or disable omni-completion based on a file type by setting +the 'omnicompl' item to 'false' when registering a lsp server for the +filetype. If this item is not specified, then omni-completion is enabled by +default. The following example disables omni-completion for python: > let lspServers = [ \ { - \ 'filetype': ['javascript', 'typescript'], - \ 'omnicompl': v:true, - \ 'path': '/usr/local/bin/typescript-language-server', - \ 'args': ['--stdio'] - \ }, - \ { \ 'filetype': 'python', \ 'omnicompl': v:false, \ 'path': '/usr/local/bin/pyls', @@ -382,8 +381,6 @@ \ 'args': ['--check-parent-process', '-v'] \ } \ ] < -adding "omnicompl" into configuration to set for specific ft, default is true. - ============================================================================== vim:tw=78:ts=8:noet:ft=help:norl: