From 6cce113e6c229f6a04c923feeae8faa739855146 Mon Sep 17 00:00:00 2001 From: "shane.xb.qian" Date: Thu, 25 Feb 2021 00:54:54 +0800 Subject: [PATCH] To allow user can disable omnicompl for specific ft. - adding a 'omnicompl' option in configuration. - default 'omnicompl' is true. --- README.md | 2 +- autoload/lsp.vim | 32 +++++++++++++++++++++++++++++--- doc/lsp.txt | 23 +++++++++++++++++++++-- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 366a906..fdae792 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ To register a LSP server, add the following lines to your .vimrc file: \ 'filetype': ['javascript', 'typescript'], \ 'path': '/usr/local/bin/typescript-language-server', \ 'args': ['--stdio'] - \ } + \ }, \ { \ 'filetype': 'sh', \ 'path': '/usr/local/bin/bash-language-server', diff --git a/autoload/lsp.vim b/autoload/lsp.vim index f36e3a8..283c41a 100644 --- a/autoload/lsp.vim +++ b/autoload/lsp.vim @@ -21,6 +21,9 @@ var lspServers: list> = [] # filetype to LSP server map var ftypeServerMap: dict> = {} +# filetype to omnicompl map +var omnicomplFtypeMap: dict = {} + # Buffer number to LSP server map var bufnrToServer: dict> = {} @@ -55,6 +58,17 @@ 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) +enddef + +# Reg bool of omnicompl for a filetype. +def s:lspRegOmnicompl(ftype: string, omnicompl: bool) + omnicomplFtypeMap->extend({[ftype]: omnicompl}) +enddef + def lsp#enableServerTrace() ClearTraceLogs() lsp_server_trace = true @@ -283,7 +297,9 @@ def lsp#addFile(bnr: number): void # in insert mode stops completion and inserts a inoremap pumvisible() ? "\\" : "\" else - setbufvar(bnr, '&omnifunc', 'lsp#omniFunc') + if s:lspBoolOmnicompl(ftype) + setbufvar(bnr, '&omnifunc', 'lsp#omniFunc') + endif endif setbufvar(bnr, '&balloonexpr', 'LspDiagExpr()') @@ -340,13 +356,21 @@ def lsp#addServer(serverList: list>) ErrMsg('Error: LSP server information is missing filetype or path or args') continue endif + if !server->has_key('omnicompl') + # Default true if didnot reg + server['omnicompl'] = v:true + endif if !server.path->filereadable() ErrMsg('Error: LSP server ' .. server.path .. ' is not found') return endif if server.args->type() != v:t_list - ErrMsg('Error: Arguments for LSP server ' .. server.path .. ' is not a List') + 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') return endif @@ -354,9 +378,11 @@ def lsp#addServer(serverList: list>) if server.filetype->type() == v:t_string s:lspAddServer(server.filetype, lspserver) + s:lspRegOmnicompl(server.filetype, server.omnicompl) elseif server.filetype->type() == v:t_list for ftype in server.filetype - s:lspAddServer(ftype, lspserver) + s:lspAddServer(ftype, lspserver) + s:lspRegOmnicompl(server.filetype, server.omnicompl) endfor else ErrMsg('Error: Unsupported file type information "' .. diff --git a/doc/lsp.txt b/doc/lsp.txt index 483a8ac..0acef02 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -122,7 +122,7 @@ file types, add the following commands to the .vimrc file: > \ 'filetype': ['javascript', 'typescript'], \ 'path': '/usr/local/bin/typescript-language-server', \ 'args': ['--stdio'] - \ } + \ }, \ { \ 'filetype': 'python', \ 'path': '/usr/local/bin/pyls', @@ -357,7 +357,7 @@ use the keys described in |popupmenu-keys| with this menu. To disable the auto-compeltion, you can set the LSP_24x7_Complete variable to v:false in your .vimrc file: > - let g:LSP_24x7_Complete=v:false + let g:LSP_24x7_Complete = v:false < If this variable is set, then the LSP plugin doesn't automatically start completion in insert mode and instead supports omni-completion (|compl-omni|). @@ -365,6 +365,25 @@ 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: > + + 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', + \ '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: -- 2.48.1