autoload/lsp/completion.vim | 13 ++++++++++++- autoload/lsp/lsp.vim | 9 ++++++++- autoload/lsp/options.vim | 4 ++++ doc/lsp.txt | 18 +++++++++++++++++- diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 37690a0ff4fc0a3055d76ca28dd710e26ceaba5f..15f59c4ae94c511f59947313ea4c917e465bed79 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -623,7 +623,9 @@ acmds->add({bufnr: bnr, event: 'TextChangedI', group: 'LSPBufferAutocmds', cmd: 'LspComplete()'}) - else + endif + + if LspOmniComplEnabled(ftype) setbufvar(bnr, '&omnifunc', 'g:LspOmniFunc') endif @@ -647,6 +649,15 @@ group: 'LSPBufferAutocmds', cmd: $'LspCompleteDone({bnr})'}) 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 930c115efaeeebfd4967b8cc0898c3d9e3d4c6d2..7cf25ac2b5d2172d21fed769c24a6374afae8ed8 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -516,6 +516,7 @@ # Refresh the displayed diags visuals if opt.lspOptions.autoHighlightDiags diag.DiagsRefresh(bnr) endif + completion.BufferLoadedInWin(bnr) enddef # Stop all the LSP servers @@ -584,7 +585,13 @@ util.ErrMsg('LSP server information is missing filetype or path') 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 ea35c6cf3854dd9a9020e2e33e5c8198c72b8c02..eae209308f387a14fbe5df58cc6d250c2b7fca24 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -73,6 +73,10 @@ # 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 c30220b495d7a2ccc6a12ba73d8dc2141f7616c8..dd5325ef6ceb756ed260da27b46fc7c7906f8508 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`. ==============================================================================