From: Yegappan Lakshmanan Date: Fri, 28 Jul 2023 04:32:00 +0000 (-0700) Subject: Add option to enalbe/disable omni-completion X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=6b68a0375775c36c973925b577caf0065a16a8b3;p=vim-lsp.git Add option to enalbe/disable omni-completion --- diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 37690a0..15f59c4 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -623,7 +623,9 @@ export def BufferInit(lspserver: dict, bnr: number, ftype: string) event: 'TextChangedI', group: 'LSPBufferAutocmds', cmd: 'LspComplete()'}) - else + endif + + if LspOmniComplEnabled(ftype) setbufvar(bnr, '&omnifunc', 'g:LspOmniFunc') endif @@ -649,4 +651,13 @@ export def BufferInit(lspserver: dict, bnr: number, ftype: string) autocmd_add(acmds) enddef +# Buffer "bnr" is loaded in a window. If omni-completion is enabled for this +# buffer, then set the 'omnifunc' option. +export def BufferLoadedInWin(bnr: number) + if !opt.lspOptions.autoComplete + && LspOmniComplEnabled(bnr->getbufvar('&filetype')) + setbufvar(bnr, '&omnifunc', 'g:LspOmniFunc') + endif +enddef + # vim: tabstop=8 shiftwidth=2 softtabstop=2 diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 930c115..7cf25ac 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -516,6 +516,7 @@ export def BufferLoadedInWin(bnr: number) if opt.lspOptions.autoHighlightDiags diag.DiagsRefresh(bnr) endif + completion.BufferLoadedInWin(bnr) enddef # Stop all the LSP servers @@ -584,7 +585,13 @@ export def AddServer(serverList: list>) continue endif # Enable omni-completion by default - server.omnicompl = server->get('omnicompl', true) + var omnicompl_def: bool = false + if opt.lspOptions.omniComplete == true + || (opt.lspOptions.omniComplete == null + && !opt.lspOptions.autoComplete) + omnicompl_def = true + endif + server.omnicompl = server->get('omnicompl', omnicompl_def) if !server.path->executable() if !opt.lspOptions.ignoreMissingServer diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index ea35c6c..eae2093 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -73,6 +73,10 @@ export var lspOptions: dict = { # Suppress adding a new line on completion selection with noNewlineInCompletion: false, + # Omni-completion support. To keep backward compatibility, this option is + # set to null by default instead of false. + omniComplete: null, + # Open outline window on right side outlineOnRight: false, diff --git a/doc/lsp.txt b/doc/lsp.txt index c30220b..dd5325e 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -552,6 +552,13 @@ noNewlineInCompletion |Boolean| option. Suppress adding a new line on completion selection with . By default this is set to false. + *lsp-opt-omniComplete* +omniComplete |Boolean| option. Enables or disables omni-completion. + By default this is set to v:false. If "autoComplete" + is set to v:false, then omni-completion is enabled by + default. By setting "omniComplete" option to v:false, + omni-completion can also be disabled. + *lsp-opt-outlineOnRight* outlineOnRight |Boolean| option. Open the outline window on the right side, by default this is false. @@ -1257,6 +1264,15 @@ do the filtering. By default, case sensitive comparison is used to filter the returned items. You can modify the 'completionMatcher' option to use either case insensitive or fuzzy comparison. +To enable auto completion for all the buffers, set the "autoComplete" option +to v:true (default). To disable auto completion for all the buffers, set the +"autoComplete" option to v:false. If auto completion is disabled for all the +buffers, then omni-completion is enabled. To disable omni-completion for all +the buffers, set the "omniComplete" option to v:false (default). To enable +omni-completion for all the buffers, set the "omniComplete" option to v:true. +You can also enable or disable omni-completion for a specific language server, +by setting the "omnicompl" item when registering the language server. + In addition to the automatic completion and omni completion, it is possible to use external completion engines. LSP client can be used as a completion source by repurposing `g:LspOmniFunc` function. The adapter which interfaces with @@ -1267,7 +1283,7 @@ returns the matches from LSP server. If the LSP server is not ready to reply `g:LspOmniFunc` waits for up to 2 seconds. This wait blocks the caller from doing other work, which may be a concern for asynchronous completion engines. To avoid blocking wait call `g:LspOmniCompletePending` function which returns -`true` immediately if LSP server is not ready. `g:LspOmniFunc` can be +`true` immediately if the language server is not ready. `g:LspOmniFunc` can be called (the second time) only after this function returns `false`. ==============================================================================