completeItems->add(d)
endfor
- if opt.lspOptions.autoComplete
+ if opt.lspOptions.autoComplete && !lspserver.omniCompletePending
if completeItems->empty()
# no matches
return
complete(start_col, completeItems)
else
lspserver.completeItems = completeItems
- lspserver.completePending = false
+ lspserver.omniCompletePending = false
endif
enddef
util.ErrMsg($'Error: Unsupported notification message received from the LSP server ({lspserver.path}), message = {reply->string()}')
enddef
+# process log trace notification messages
+def ProcessLogTraceNotif(lspserver: dict<any>, reply: dict<any>)
+ :echomsg $'Log trace notification: {reply->string()}'
+enddef
+
# per-filetype private map inside to record if ntf once or not
var ftypeNtfOnceMap: dict<bool> = {}
# process unsupported notification messages but only notify once
'window/logMessage': ProcessLogMsgNotif,
'textDocument/publishDiagnostics': ProcessDiagNotif,
'$/progress': ProcessUnsupportedNotif,
+ '$/logTrace': ProcessLogTraceNotif,
'telemetry/event': ProcessUnsupportedNotifOnce,
# Java language server sends the 'language/status' notification which is
# not in the LSP specification
# set the LSP server trace level for the current buffer
# Params: SetTraceParams
export def SetTraceServer(traceVal: string)
- if ['off', 'message', 'verbose']->index(traceVal) == -1
+ if ['off', 'messages', 'verbose']->index(traceVal) == -1
util.ErrMsg($'Error: Unsupported LSP server trace value {traceVal}')
return
endif
# Trigger kind is 1 for 24x7 code complete or manual invocation
var triggerKind: number = 1
+ var triggerChar: string = ''
# If the character before the cursor is not a keyword character or is not
# one of the LSP completion trigger characters, then do nothing.
if line[cur_col - 2] !~ '\k'
- if lspserver.completionTriggerChars->index(line[cur_col - 2]) == -1
+ var trigidx = lspserver.completionTriggerChars->index(line[cur_col - 2])
+ if trigidx == -1
return
endif
# completion triggered by one of the trigger characters
triggerKind = 2
+ triggerChar = lspserver.completionTriggerChars[trigidx]
endif
# first send all the changes in the current buffer to the LSP server
listener_flush()
# initiate a request to LSP server to get list of completions
- lspserver.getCompletion(triggerKind)
+ lspserver.getCompletion(triggerKind, triggerChar)
return
enddef
# first send all the changes in the current buffer to the LSP server
listener_flush()
- lspserver.completePending = v:true
+ lspserver.omniCompletePending = v:true
lspserver.completeItems = []
# initiate a request to LSP server to get list of completions
- lspserver.getCompletion(1)
+ lspserver.getCompletion(1, '')
# locate the start of the word
var line = getline('.')
else
# Wait for the list of matches from the LSP server
var count: number = 0
- while lspserver.completePending && count < 1000
+ while lspserver.omniCompletePending && count < 1000
if complete_check()
return v:none
endif
lspserver.caps = {}
lspserver.nextID = 1
lspserver.requests = {}
- lspserver.completePending = false
+ lspserver.omniCompletePending = false
lspserver.completionTriggerChars = []
lspserver.signaturePopup = -1
lspserver.workspaceFolders = [getcwd()]
return 0
enddef
-# set the LSP server trace level using $/setTrace notification
+# Set the LSP server trace level using the $/setTrace notification
+# Support values for "traceVal" are "off", "messages" and "verbose".
def SetTrace(lspserver: dict<any>, traceVal: string)
var notif: dict<any> = lspserver.createNotification('$/setTrace')
notif.params->extend({value: traceVal})
# Get a list of completion items.
# Request: "textDocument/completion"
# Param: CompletionParams
-def GetCompletion(lspserver: dict<any>, triggerKind_arg: number): void
+def GetCompletion(lspserver: dict<any>, triggerKind_arg: number, triggerChar: string): void
# Check whether LSP server supports completion
if !lspserver.caps->has_key('completionProvider')
util.ErrMsg("Error: LSP server does not support completion")
# interface TextDocumentPositionParams
req.params = GetLspTextDocPosition()
# interface CompletionContext
- req.params.context = {triggerKind: triggerKind_arg}
+ req.params.context = {triggerKind: triggerKind_arg, triggerCharacter: triggerChar}
lspserver.sendMessage(req)
if exists('g:LSPTest') && g:LSPTest
nextID: 1,
caps: {},
requests: {},
- completePending: false,
+ omniCompletePending: false,
completionTriggerChars: [],
signaturePopup: -1,
diagsMap: {},
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
For Vim version 9.0 and above
-Last change: Oct 7, 2022
+Last change: Oct 21, 2022
==============================================================================
*lsp-license*
\ }
\ ]
<
+If you want to use omni completion, in addition to the automatic completion,
+then you can set the 'omnifunc' option to the "LspOmniFunc" function: >
+
+ set omnifunc=LspOmniFunc
+<
+To use omni completion, press CTRL-X CTRL-O in insert mode. Refer to
+|compl-omni| for more information.
+
==============================================================================
7. Autocommands *lsp-autocmds*
return lsp.ServerReady()
enddef
+# Command line completion function for the LspSetTrace command.
+def LspServerTraceComplete(arglead: string, cmdline: string, cursorpos: number): list<string>
+ var l = ['off', 'messages', 'verbose']
+ if arglead->empty()
+ return l
+ else
+ return filter(l, (_, val) => val =~ arglead)
+ endif
+enddef
+
augroup LSPAutoCmds
au!
autocmd BufNewFile,BufReadPost * lsp.AddFile(expand('<abuf>')->str2nr())
command! -nargs=0 -bar LspShowServers lsp.ShowServers()
command! -nargs=0 -bar LspShowServerCapabilities lsp.ShowServerCapabilities()
command! -nargs=0 -bar LspServerRestart lsp.RestartServer()
-command! -nargs=1 -bar LspSetTrace lsp.SetTraceServer(<q-args>)
+command! -nargs=1 -complete=customlist,LspServerTraceComplete -bar LspSetTrace lsp.SetTraceServer(<q-args>)
command! -nargs=0 -bar LspGotoDefinition lsp.GotoDefinition(v:false)
command! -nargs=0 -bar LspGotoDeclaration lsp.GotoDeclaration(v:false)
command! -nargs=0 -bar LspGotoTypeDef lsp.GotoTypedef(v:false)