diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 8ce5899c..0400a491 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -146,7 +146,7 @@ enddef # process the 'textDocument/completion' reply from the LSP server # Result: CompletionItem[] | CompletionList | null -export def CompletionReply(lspserver: dict, cItems: any) +export def CompletionReply(lspserver: dict, cItems: any, trigger_type: number) lspserver.completeItemsIsIncomplete = false if cItems->empty() if lspserver.omniCompletePending @@ -182,7 +182,7 @@ export def CompletionReply(lspserver: dict, cItems: any) snippet.CompletionVsnip(items) endif - if lspOpts.useBufferCompletion + if lspOpts.useBufferCompletion && count(lspOpts.bufferCompletionTriggers, trigger_type) > 0 CompletionFromBuffer(items) endif @@ -549,7 +549,7 @@ def LspComplete() endif var [triggerKind, triggerChar] = GetTriggerAttributes(lspserver) - if triggerKind < 0 + if count(opt.lspOptions.autoCompleteTriggers, triggerKind) == 0 return endif diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index bfbdd77d..36c05a4c 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -727,8 +727,11 @@ def GetCompletion(lspserver: dict, triggerKind_arg: number, triggerChar: st # interface CompletionContext params.context = {triggerKind: triggerKind_arg, triggerCharacter: triggerChar} - lspserver.rpc_a('textDocument/completion', params, - completion.CompletionReply) + # Wrap CompletionReply, so it gets the trigger kind + var CompletionReplyWithTriggerKind = (lspserverarg: dict, cItems: any) => + completion.CompletionReply(lspserverarg, cItems, triggerKind_arg) + echom lspserver.completionTriggerChars + lspserver.rpc_a('textDocument/completion', params, CompletionReplyWithTriggerKind) enddef # Get lazy properties for a completion item. diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index 50697a3b..2bc3ac8b 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -16,6 +16,15 @@ export var lspOptions: dict = { # Otherwise, use omni-completion autoComplete: true, + # If autoComplete is set to true, limit auto completion to the specified cases: + # 1: typing keyword characters (see :help iskeyword) + # 2: typing a trigger character (language specific, provided by the lsp server. + # E.g., for C++ this might be any of '.', '<', '>', ':', '"', '/', '*' + # Default is to execute autocompletion in both cases. If you want autocompletion only when typing + # a trigger character, set this option to [ 2 ]. You can still use omni-completion to trigger + # completion manually in other situations. + autoCompleteTriggers: [ 1, 2 ], + # In normal mode, highlight the current symbol automatically autoHighlight: false, @@ -25,6 +34,14 @@ export var lspOptions: dict = { # Automatically populate the location list with new diagnostics autoPopulateDiags: false, + # If useBufferCompletion is set to true, limit completion to the specified cases: + # 1: typing keyword characters (see :help iskeyword) + # 2: typing a trigger character (language specific, provided by the lsp server. + # E.g., for C++ this might be any of '.', '<', '>', ':', '"', '/', '*' + # Default is to execute buffer completion in both cases. If you do not want buffer completions + # to come up with more specific completions (e.g., class members, file names), set it to [ 1 ]. + bufferCompletionTriggers: [ 1, 2 ], + # icase | fuzzy | case match for language servers that replies with a full # list of completion items completionMatcher: 'case',