vim9script
-import lspOptions from './lspoptions.vim'
+var opt = {}
+
+if has('patch-8.2.4019')
+ import './lspoptions.vim' as opt_import
+ opt.lspOptions = opt_import.lspOptions
+else
+ import lspOptions from './lspoptions.vim'
+ opt.lspOptions = lspOptions
+endif
def s:lspDiagSevToSignName(severity: number): string
var typeMap: list<string> = ['LspDiagError', 'LspDiagWarning',
# New LSP diagnostic messages received from the server for a file.
# Update the signs placed in the buffer for this file
export def LspDiagsUpdated(lspserver: dict<any>, bnr: number)
- if !lspOptions.autoHighlightDiags
+ if !opt.lspOptions.autoHighlightDiags
return
endif
# Refer to https://microsoft.github.io/language-server-protocol/specification
# for the Language Server Protocol (LSP) specificaiton.
-import lspOptions from './lspoptions.vim'
-import {WarnMsg,
+var opt = {}
+var util = {}
+var buf = {}
+
+if has('patch-8.2.4019')
+ import './lspoptions.vim' as opt_import
+ import './util.vim' as util_import
+ import './buf.vim' as buf_import
+
+ opt.lspOptions = opt_import.lspOptions
+ util.WarnMsg = util_import.WarnMsg
+ util.ErrMsg = util_import.ErrMsg
+ util.TraceLog = util_import.TraceLog
+ util.LspUriToFile = util_import.LspUriToFile
+ util.GetLineByteFromPos = util_import.GetLineByteFromPos
+ buf.LspDiagsUpdated = buf_import.LspDiagsUpdated
+else
+ import lspOptions from './lspoptions.vim'
+ import {WarnMsg,
ErrMsg,
TraceLog,
LspUriToFile,
GetLineByteFromPos} from './util.vim'
-import {LspDiagsUpdated} from './buf.vim'
+ import {LspDiagsUpdated} from './buf.vim'
+
+ opt.lspOptions = lspOptions
+ util.WarnMsg = WarnMsg
+ util.ErrMsg = ErrMsg
+ util.TraceLog = TraceLog
+ util.LspUriToFile = LspUriToFile
+ util.GetLineByteFromPos = GetLineByteFromPos
+ buf.LspDiagsUpdated = LspDiagsUpdated
+endif
# process the 'initialize' method reply from the LSP server
# Result: InitializeResult
# and then setup the below mapping for those buffers.
# map characters that trigger signature help
- if lspOptions.showSignature && caps->has_key('signatureHelpProvider')
+ if opt.lspOptions.showSignature && caps->has_key('signatureHelpProvider')
var triggers = caps.signatureHelpProvider.triggerCharacters
for ch in triggers
exe 'inoremap <buffer> <silent> ' .. ch .. ' ' .. ch .. "<C-R>=lsp#showSignature()<CR>"
endfor
endif
- if lspOptions.autoComplete && caps->has_key('completionProvider')
+ if opt.lspOptions.autoComplete && caps->has_key('completionProvider')
var triggers = caps.completionProvider.triggerCharacters
lspserver.completionTriggerChars = triggers
endif
- if lspOptions.autoHighlight && caps->has_key('documentHighlightProvider')
+ if opt.lspOptions.autoHighlight && caps->has_key('documentHighlightProvider')
&& caps.documentHighlightProvider
# Highlight all the occurrences of the current keyword
augroup LSPBufferAutocmds
# Result: Location | Location[] | LocationLink[] | null
def s:processDefDeclReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
if reply.result->empty()
- WarnMsg("Error: definition is not found")
+ util.WarnMsg("Error: definition is not found")
# pop the tag stack
var tagstack: dict<any> = gettagstack()
if tagstack.length > 0
else
location = reply.result
endif
- var fname = LspUriToFile(location.uri)
+ var fname = util.LspUriToFile(location.uri)
var wid = fname->bufwinid()
if wid != -1
wid->win_gotoid()
var result: dict<any> = reply.result
if result.signatures->len() <= 0
- WarnMsg('No signature help available')
+ util.WarnMsg('No signature help available')
return
endif
var label = ''
if sig.parameters[result.activeParameter]->has_key('documentation')
if sig.parameters[result.activeParameter].documentation->type()
- == v:t_string
+ == v:t_string
label = sig.parameters[result.activeParameter].documentation
endif
else
startcol = text->stridx(label)
endif
endif
- if lspOptions.echoSignature
+ if opt.lspOptions.echoSignature
echon "\r\r"
echon ''
echon strpart(text, 0, startcol)
completeItems->add(d)
endfor
- if lspOptions.autoComplete
+ if opt.lspOptions.autoComplete
if completeItems->empty()
# no matches
return
hoverText = reply.result.contents.value->split("\n")
hoverKind = 'markdown'
else
- ErrMsg('Error: Unsupported hover contents type (' .. reply.result.contents.kind .. ')')
+ util.ErrMsg('Error: Unsupported hover contents type (' .. reply.result.contents.kind .. ')')
return
endif
elseif reply.result.contents->has_key('value')
# MarkedString
hoverText = reply.result.contents.value->split("\n")
else
- ErrMsg('Error: Unsupported hover contents (' .. reply.result.contents .. ')')
+ util.ErrMsg('Error: Unsupported hover contents (' .. reply.result.contents .. ')')
return
endif
elseif reply.result.contents->type() == v:t_list
endif
hoverText->extend(reply.result.contents->split("\n"))
else
- ErrMsg('Error: Unsupported hover contents (' .. reply.result.contents .. ')')
+ util.ErrMsg('Error: Unsupported hover contents (' .. reply.result.contents .. ')')
return
endif
- if lspOptions.hoverInPreview
+ if opt.lspOptions.hoverInPreview
silent! pedit HoverReply
wincmd P
setlocal buftype=nofile
# Result: Location[] | null
def s:processReferencesReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
if reply.result->empty()
- WarnMsg('Error: No references found')
+ util.WarnMsg('Error: No references found')
return
endif
var locations: list<dict<any>> = reply.result
var qflist: list<dict<any>> = []
for loc in locations
- var fname: string = LspUriToFile(loc.uri)
+ var fname: string = util.LspUriToFile(loc.uri)
var bnr: number = fname->bufnr()
if bnr == -1
bnr = fname->bufadd()
->trim("\t ", 1)
qflist->add({filename: fname,
lnum: loc.range.start.line + 1,
- col: GetLineByteFromPos(bnr, loc.range.start) + 1,
+ col: util.GetLineByteFromPos(bnr, loc.range.start) + 1,
text: text})
endfor
setloclist(0, [], ' ', {title: 'Symbol Reference', items: qflist})
return
endif
- var fname: string = LspUriToFile(req.params.textDocument.uri)
+ var fname: string = util.LspUriToFile(req.params.textDocument.uri)
var bnr = fname->bufnr()
for docHL in reply.result
propName = 'LspTextRef'
endif
prop_add(docHL.range.start.line + 1,
- GetLineByteFromPos(bnr, docHL.range.start) + 1,
+ util.GetLineByteFromPos(bnr, docHL.range.start) + 1,
{end_lnum: docHL.range.end.line + 1,
- end_col: GetLineByteFromPos(bnr, docHL.range.end) + 1,
+ end_col: util.GetLineByteFromPos(bnr, docHL.range.end) + 1,
bufnr: bnr,
type: propName})
endfor
var symInfo: dict<any>
for symbol in symbolInfoTable
- fname = LspUriToFile(symbol.location.uri)
+ fname = util.LspUriToFile(symbol.location.uri)
symbolType = LspSymbolKindToName(symbol.kind)
name = symbol.name
if symbol->has_key('containerName')
var symbolLineTable: list<dict<any>> = []
if req.params.textDocument.uri != ''
- fname = LspUriToFile(req.params.textDocument.uri)
+ fname = util.LspUriToFile(req.params.textDocument.uri)
endif
if reply.result->empty()
var i_n = [B[0], numlines - 1]->min()
if i_0 < 0 || i_0 >= numlines || i_n < 0 || i_n >= numlines
- WarnMsg("set_lines: Invalid range, A = " .. A->string()
+ util.WarnMsg("set_lines: Invalid range, A = " .. A->string()
.. ", B = " .. B->string() .. ", numlines = " .. numlines
.. ", new lines = " .. new_lines->string())
return lines
for e in text_edits
# Adjust the start and end columns for multibyte characters
start_row = e.range.start.line
- start_col = GetLineByteFromPos(bnr, e.range.start)
+ start_col = util.GetLineByteFromPos(bnr, e.range.start)
end_row = e.range.end.line
- end_col = GetLineByteFromPos(bnr, e.range.end)
+ end_col = util.GetLineByteFromPos(bnr, e.range.end)
start_line = [e.range.start.line, start_line]->min()
finish_line = [e.range.end.line, finish_line]->max()
# interface TextDocumentEdit
def s:applyTextDocumentEdit(textDocEdit: dict<any>)
- var bnr: number = bufnr(LspUriToFile(textDocEdit.textDocument.uri))
+ var bnr: number = bufnr(util.LspUriToFile(textDocEdit.textDocument.uri))
if bnr == -1
- ErrMsg('Error: Text Document edit, buffer ' .. textDocEdit.textDocument.uri .. ' is not found')
+ util.ErrMsg('Error: Text Document edit, buffer ' .. textDocEdit.textDocument.uri .. ' is not found')
return
endif
s:applyTextEdits(bnr, textDocEdit.edits)
if workspaceEdit->has_key('documentChanges')
for change in workspaceEdit.documentChanges
if change->has_key('kind')
- ErrMsg('Error: Unsupported change in workspace edit [' .. change.kind .. ']')
+ util.ErrMsg('Error: Unsupported change in workspace edit [' .. change.kind .. ']')
else
s:applyTextDocumentEdit(change)
endif
var save_cursor: list<number> = getcurpos()
for [uri, changes] in workspaceEdit.changes->items()
- var fname: string = LspUriToFile(uri)
+ var fname: string = util.LspUriToFile(uri)
var bnr: number = fname->bufnr()
if bnr == -1
# file is already removed
# result: TextEdit[]
- var fname: string = LspUriToFile(req.params.textDocument.uri)
+ var fname: string = util.LspUriToFile(req.params.textDocument.uri)
var bnr: number = fname->bufnr()
if bnr == -1
# file is already removed
def s:processCodeActionReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
if reply.result->empty()
# no action can be performed
- WarnMsg('No code action is available')
+ util.WarnMsg('No code action is available')
return
endif
var r: dict<dict<number>> = reply.result[0].range
var bnr: number = bufnr()
- var start_col: number = GetLineByteFromPos(bnr, r.start) + 1
- var end_col: number = GetLineByteFromPos(bnr, r.end)
+ var start_col: number = util.GetLineByteFromPos(bnr, r.start) + 1
+ var end_col: number = util.GetLineByteFromPos(bnr, r.end)
setcharpos("'<", [0, r.start.line + 1, start_col, 0])
setcharpos("'>", [0, r.end.line + 1, end_col, 0])
endif
# interface SymbolInformation
- fileName = LspUriToFile(symbol.location.uri)
+ fileName = util.LspUriToFile(symbol.location.uri)
r = symbol.location.range
symName = symbol.name
if lsp_reply_handlers->has_key(req.method)
lsp_reply_handlers[req.method](lspserver, req, reply)
else
- ErrMsg("Error: Unsupported reply received from LSP server: " .. reply->string())
+ util.ErrMsg("Error: Unsupported reply received from LSP server: " .. reply->string())
endif
enddef
# Notification: textDocument/publishDiagnostics
# Param: PublishDiagnosticsParams
def s:processDiagNotif(lspserver: dict<any>, reply: dict<any>): void
- var fname: string = LspUriToFile(reply.params.uri)
+ var fname: string = util.LspUriToFile(reply.params.uri)
var bnr: number = fname->bufnr()
if bnr == -1
# Is this condition possible?
endfor
lspserver.diagsMap->extend({['' .. bnr]: diag_by_lnum})
- LspDiagsUpdated(lspserver, bnr)
+ buf.LspDiagsUpdated(lspserver, bnr)
enddef
# process a show notification message from the LSP server
mtype = msgType[reply.params.type]
endif
- TraceLog(false, '[' .. mtype .. ']: ' .. reply.params.message)
+ util.TraceLog(false, '[' .. mtype .. ']: ' .. reply.params.message)
enddef
# process unsupported notification messages
def s:processUnsupportedNotif(lspserver: dict<any>, reply: dict<any>)
- ErrMsg('Error: Unsupported notification message received from the LSP server (' .. lspserver.path .. '), message = ' .. reply->string())
+ util.ErrMsg('Error: Unsupported notification message received from the LSP server (' .. lspserver.path .. '), message = ' .. reply->string())
enddef
# ignore unsupported notification message
if lsp_notif_handlers->has_key(reply.method)
lsp_notif_handlers[reply.method](lspserver, reply)
else
- ErrMsg('Error: Unsupported notification received from LSP server ' .. reply->string())
+ util.ErrMsg('Error: Unsupported notification received from LSP server ' .. reply->string())
endif
enddef
endif
s:applyWorkspaceEdit(workspaceEditParams.edit)
# TODO: Need to return the proper result of the edit operation
- lspserver.sendResponse(request, {applied: true}, v:null)
+ lspserver.sendResponse(request, {applied: true}, {})
enddef
def s:processUnsupportedReq(lspserver: dict<any>, request: dict<any>)
- ErrMsg('Error: Unsupported request message received from the LSP server (' .. lspserver.path .. '), message = ' .. request->string())
+ util.ErrMsg('Error: Unsupported request message received from the LSP server (' .. lspserver.path .. '), message = ' .. request->string())
enddef
# process a request message from the server
if lspRequestHandlers->has_key(request.method)
lspRequestHandlers[request.method](lspserver, request)
else
- ErrMsg('Error: Unsupported request received from LSP server ' ..
+ util.ErrMsg('Error: Unsupported request received from LSP server ' ..
request->string())
endif
enddef
len = str2nr(lspserver.data[idx + 16 : ])
if len == 0
- ErrMsg("Error(LSP): Invalid content length")
+ util.ErrMsg("Error(LSP): Invalid content length")
# Discard the header
lspserver.data = lspserver.data[idx + 16 :]
return
try
msg = content->json_decode()
catch
- ErrMsg("Error(LSP): Malformed content (" .. content .. ")")
+ util.ErrMsg("Error(LSP): Malformed content (" .. content .. ")")
lspserver.data = lspserver.data[idx + len :]
continue
endtry
if msg.error->has_key('data')
emsg = emsg .. ', data = ' .. msg.error.data->string()
endif
- ErrMsg("Error(LSP): request " .. req.method .. " failed ("
+ util.ErrMsg("Error(LSP): request " .. req.method .. " failed ("
.. emsg .. ")")
endif
endif
# notification message from the server
lspserver.processNotif(msg)
else
- ErrMsg("Error(LSP): Unsupported message (" .. msg->string() .. ")")
+ util.ErrMsg("Error(LSP): Unsupported message (" .. msg->string() .. ")")
endif
lspserver.data = lspserver.data[idx + len :]
# Vim9 LSP client
-import lspOptions from './lspoptions.vim'
-import NewLspServer from './lspserver.vim'
-import {WarnMsg,
- ErrMsg,
- lsp_server_trace,
- ClearTraceLogs,
- GetLineByteFromPos,
- PushCursorToTagStack} from './util.vim'
-import {LspDiagsUpdated} from './buf.vim'
+var opt = {}
+var lserver = {}
+var util = {}
+var buf = {}
+
+if has('patch-8.2.4019')
+ import './lspoptions.vim' as opt_import
+ import './lspserver.vim' as server_import
+ import './util.vim' as util_import
+ import './buf.vim' as buf_import
+
+ opt.LspOptionsSet = opt_import.LspOptionsSet
+ opt.lspOptions = opt_import.lspOptions
+ lserver.NewLspServer = server_import.NewLspServer
+ util.WarnMsg = util_import.WarnMsg
+ util.ErrMsg = util_import.ErrMsg
+ util.ServerTrace = util_import.ServerTrace
+ util.ClearTraceLogs = util_import.ClearTraceLogs
+ util.GetLineByteFromPos = util_import.GetLineByteFromPos
+ util.PushCursorToTagStack = util_import.PushCursorToTagStack
+ buf.LspDiagsUpdated = buf_import.LspDiagsUpdated
+else
+ import {lspOptions, LspOptionsSet} from './lspoptions.vim'
+ import NewLspServer from './lspserver.vim'
+ import {WarnMsg,
+ ErrMsg,
+ ServerTrace,
+ ClearTraceLogs,
+ GetLineByteFromPos,
+ PushCursorToTagStack} from './util.vim'
+ import {LspDiagsUpdated} from './buf.vim'
+
+ opt.LspOptionsSet = LspOptionsSet
+ opt.lspOptions = lspOptions
+ lserver.NewLspServer = NewLspServer
+ util.WarnMsg = WarnMsg
+ util.ErrMsg = ErrMsg
+ util.ServerTrace = ServerTrace
+ util.ClearTraceLogs = ClearTraceLogs
+ util.GetLineByteFromPos = GetLineByteFromPos
+ util.PushCursorToTagStack = PushCursorToTagStack
+ buf.LspDiagsUpdated = LspDiagsUpdated
+endif
# Needs Vim 8.2.2342 and higher
if v:version < 802 || !has('patch-8.2.2342')
# Set user configurable LSP options
def lsp#setOptions(lspOpts: dict<any>)
- for key in lspOpts->keys()
- lspOptions[key] = lspOpts[key]
- endfor
+ opt.LspOptionsSet(lspOpts)
enddef
def s:lspInitOnce()
enddef
# Add a LSP server for a filetype
-def s:lspAddServer(ftype: string, lspserver: dict<any>)
- ftypeServerMap->extend({[ftype]: lspserver})
+def s:lspAddServer(ftype: string, lspsrv: dict<any>)
+ ftypeServerMap->extend({[ftype]: lspsrv})
enddef
# Returns true if omni-completion is enabled for filetype 'ftype'.
enddef
def lsp#enableServerTrace()
- ClearTraceLogs()
- lsp_server_trace = true
+ util.ClearTraceLogs()
+ util.ServerTrace(true)
enddef
# Show information about all the LSP servers
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return ''
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return ''
endif
if lspserver->empty() || !lspserver.running
return
endif
- LspDiagsUpdated(lspserver, bufnr())
+ buf.LspDiagsUpdated(lspserver, bufnr())
enddef
# A new buffer is opened. If LSP is supported for this buffer, then add it
listener_add(function('lsp#bufchange_listener'), bnr)
# set options for insert mode completion
- if lspOptions.autoComplete
+ if opt.lspOptions.autoComplete
setbufvar(bnr, '&completeopt', 'menuone,popup,noinsert,noselect')
setbufvar(bnr, '&completepopup', 'border:off')
# <Enter> in insert mode stops completion and inserts a <Enter>
setbufvar(bnr, '&balloonexpr', 'LspDiagExpr()')
# map characters that trigger signature help
- if lspOptions.showSignature &&
+ if opt.lspOptions.showSignature &&
lspserver.caps->has_key('signatureHelpProvider')
var triggers = lspserver.caps.signatureHelpProvider.triggerCharacters
for ch in triggers
# file saved notification handler
exe 'autocmd BufWritePost <buffer=' .. bnr .. '> call s:lspSavedFile()'
- if lspOptions.autoComplete
+ if opt.lspOptions.autoComplete
# Trigger 24x7 insert mode completion when text is changed
exe 'autocmd TextChangedI <buffer=' .. bnr .. '> call lsp#complete()'
endif
# Update the diagnostics when insert mode is stopped
exe 'autocmd InsertLeave <buffer=' .. bnr .. '> call lsp#leftInsertMode()'
- if lspOptions.autoHighlight &&
+ if opt.lspOptions.autoHighlight &&
lspserver.caps->has_key('documentHighlightProvider')
&& lspserver.caps.documentHighlightProvider
# Highlight all the occurrences of the current keyword
def lsp#addServer(serverList: list<dict<any>>)
for server in serverList
if !server->has_key('filetype') || !server->has_key('path') || !server->has_key('args')
- ErrMsg('Error: LSP server information is missing filetype or path or args')
+ util.ErrMsg('Error: LSP server information is missing filetype or path or args')
continue
endif
if !server->has_key('omnicompl')
endif
if !server.path->filereadable()
- ErrMsg('Error: LSP server ' .. server.path .. ' is not found')
+ util.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.args .. ' is not a List')
+ util.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 Boolean')
+ util.ErrMsg('Error: Setting of omnicompl ' .. server.omnicompl .. ' is not a Boolean')
return
endif
- var lspserver: dict<any> = NewLspServer(server.path, server.args)
+ var lspserver: dict<any> = lserver.NewLspServer(server.path, server.args)
if server.filetype->type() == v:t_string
s:lspAddServer(server.filetype, lspserver)
s:lspOmniComplSet(ftype, server.omnicompl)
endfor
else
- ErrMsg('Error: Unsupported file type information "' ..
+ util.ErrMsg('Error: Unsupported file type information "' ..
server.filetype->string() .. '" in LSP server registration')
continue
endif
# Params: SetTraceParams
def lsp#setTraceServer(traceVal: string)
if ['off', 'message', 'verbose']->index(traceVal) == -1
- ErrMsg("Error: Unsupported LSP server trace value " .. traceVal)
+ util.ErrMsg("Error: Unsupported LSP server trace value " .. traceVal)
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var bnr: number = bufnr()
if !lspserver.diagsMap->has_key(bnr) || lspserver.diagsMap[bnr]->empty()
- WarnMsg('No diagnostic messages found for ' .. fname)
+ util.WarnMsg('No diagnostic messages found for ' .. fname)
return
endif
text = diag.message->substitute("\n\\+", "\n", 'g')
qflist->add({'filename': fname,
'lnum': diag.range.start.line + 1,
- 'col': GetLineByteFromPos(bnr, diag.range.start) + 1,
+ 'col': util.GetLineByteFromPos(bnr, diag.range.start) + 1,
'text': text,
'type': s:lspDiagSevToQfType(diag.severity)})
endfor
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lnum: number = line('.')
var diag: dict<any> = lspserver.getDiagByLine(bnr, lnum)
if diag->empty()
- WarnMsg('No diagnostic messages found for current line')
+ util.WarnMsg('No diagnostic messages found for current line')
else
echo diag.message
endif
enddef
# sort the diaganostics messages for a buffer by line number
-def s:getSortedDiagLines(lspserver: dict<any>, bnr: number): list<number>
+def s:getSortedDiagLines(lspsrv: dict<any>, bnr: number): list<number>
# create a list of line numbers from the diag map keys
var lnums: list<number> =
- lspserver.diagsMap[bnr]->keys()->mapnew((_, v) => v->str2nr())
+ lspsrv.diagsMap[bnr]->keys()->mapnew((_, v) => v->str2nr())
return lnums->sort((a, b) => a - b)
enddef
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var bnr: number = bufnr()
if !lspserver.diagsMap->has_key(bnr) || lspserver.diagsMap[bnr]->empty()
- WarnMsg('No diagnostic messages found for ' .. fname)
+ util.WarnMsg('No diagnostic messages found for ' .. fname)
return
endif
endif
endfor
- WarnMsg('Error: No more diagnostics found')
+ util.WarnMsg('Error: No more diagnostics found')
enddef
# Insert mode completion handler. Used when 24x7 completion is enabled
if findstart
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return -2
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return -2
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
for s in symbols
text->add(prefix .. s.name)
# remember the line number for the symbol
- var start_col: number = GetLineByteFromPos(bnr, s.range.start) + 1
+ var start_col: number = util.GetLineByteFromPos(bnr, s.range.start) + 1
lnumMap->add({name: s.name, lnum: s.range.start.line + 1,
col: start_col})
s.outlineLine = lnumMap->len()
# Format the entire file
def lsp#textDocFormat(range_args: number, line1: number, line2: number)
if !&modifiable
- ErrMsg('Error: Current file is not a modifiable file')
+ util.ErrMsg('Error: Current file is not a modifiable file')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
enddef
# Handle keys pressed when the workspace symbol popup menu is displayed
-def s:filterSymbols(lspserver: dict<any>, popupID: number, key: string): bool
+def s:filterSymbols(lspsrv: dict<any>, popupID: number, key: string): bool
var key_handled: bool = false
var update_popup: bool = false
- var query: string = lspserver.workspaceSymbolQuery
+ var query: string = lspsrv.workspaceSymbolQuery
if key == "\<BS>" || key == "\<C-H>"
# Erase one character from the filter text
# Update the popup with the new list of symbol names
popupID->popup_settext('')
if query != ''
- lspserver.workspaceQuery(query)
+ lspsrv.workspaceQuery(query)
else
[]->setwinvar(popupID, 'LspSymbolTable')
endif
endif
# Update the workspace symbol query string
- lspserver.workspaceSymbolQuery = query
+ lspsrv.workspaceSymbolQuery = query
if key_handled
return true
endif
try
# Save the current location in the tag stack
- PushCursorToTagStack()
+ util.PushCursorToTagStack()
# if the selected file is already present in a window, then jump to it
var fname: string = symTbl[result - 1].file
enddef
# display a list of symbols from the workspace
-def s:showSymbolMenu(lspserver: dict<any>, query: string)
+def s:showSymbolMenu(lspsrv: dict<any>, query: string)
# Create the popup menu
var lnum = &lines - &cmdheight - 2 - 10
var popupAttr = {
mapping: false,
fixed: 1,
close: "button",
- filter: function('s:filterSymbols', [lspserver]),
+ filter: function('s:filterSymbols', [lspsrv]),
callback: function('s:jumpToWorkspaceSymbol')
}
- lspserver.workspaceSymbolPopup = popup_menu([], popupAttr)
- lspserver.workspaceSymbolQuery = query
+ lspsrv.workspaceSymbolPopup = popup_menu([], popupAttr)
+ lspsrv.workspaceSymbolQuery = query
prop_type_add('lspworkspacesymbol',
- {bufnr: lspserver.workspaceSymbolPopup->winbufnr(),
+ {bufnr: lspsrv.workspaceSymbolPopup->winbufnr(),
highlight: 'Title'})
echo 'Symbol: ' .. query
enddef
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
endif
:redraw!
if !dirName->isdirectory()
- ErrMsg('Error: ' .. dirName .. ' is not a directory')
+ util.ErrMsg('Error: ' .. dirName .. ' is not a directory')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
endif
:redraw!
if !dirName->isdirectory()
- ErrMsg('Error: ' .. dirName .. ' is not a directory')
+ util.ErrMsg('Error: ' .. dirName .. ' is not a directory')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
var lspserver: dict<any> = s:lspGetServer(ftype)
if lspserver->empty()
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not found')
return
endif
if !lspserver.running
- ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
+ util.ErrMsg('Error: LSP server for "' .. ftype .. '" filetype is not running')
return
endif
endif
if &foldmethod != 'manual'
- ErrMsg("Error: Only works when 'foldmethod' is 'manual'")
+ util.ErrMsg("Error: Only works when 'foldmethod' is 'manual'")
return
endif
# Show the symbol documentation in the preview window instead of in a popup
hoverInPreview: false,
}
+
+# set LSP options from user provided options
+export def LspOptionsSet(opts: dict<any>)
+ for key in opts->keys()
+ lspOptions[key] = opts[key]
+ endfor
+enddef
# Refer to https://microsoft.github.io/language-server-protocol/specification
# for the Language Server Protocol (LSP) specificaiton.
-import {ProcessReply,
+var handlers = {}
+var util = {}
+
+if has('patch-8.2.4019')
+ import './handlers.vim' as handlers_import
+ import './util.vim' as util_import
+ handlers.ProcessReply = handlers_import.ProcessReply
+ handlers.ProcessNotif = handlers_import.ProcessNotif
+ handlers.ProcessRequest = handlers_import.ProcessRequest
+ handlers.ProcessMessages = handlers_import.ProcessMessages
+ util.WarnMsg = util_import.WarnMsg
+ util.ErrMsg = util_import.ErrMsg
+ util.TraceLog = util_import.TraceLog
+ util.LspUriToFile = util_import.LspUriToFile
+ util.LspBufnrToUri = util_import.LspBufnrToUri
+ util.LspFileToUri = util_import.LspFileToUri
+ util.PushCursorToTagStack = util_import.PushCursorToTagStack
+else
+ import {ProcessReply,
ProcessNotif,
ProcessRequest,
ProcessMessages} from './handlers.vim'
-import {WarnMsg,
+ import {WarnMsg,
ErrMsg,
TraceLog,
LspUriToFile,
LspBufnrToUri,
LspFileToUri,
PushCursorToTagStack} from './util.vim'
+ handlers.ProcessReply = ProcessReply
+ handlers.ProcessNotif = ProcessNotif
+ handlers.ProcessRequest = ProcessRequest
+ handlers.ProcessMessages = ProcessMessages
+ util.WarnMsg = WarnMsg
+ util.ErrMsg = ErrMsg
+ util.TraceLog = TraceLog
+ util.LspUriToFile = LspUriToFile
+ util.LspBufnrToUri = LspBufnrToUri
+ util.LspFileToUri = LspFileToUri
+ util.PushCursorToTagStack = PushCursorToTagStack
+endif
# LSP server standard output handler
def s:output_cb(lspserver: dict<any>, chan: channel, msg: string): void
- TraceLog(false, msg)
+ util.TraceLog(false, msg)
lspserver.data = lspserver.data .. msg
lspserver.processMessages()
enddef
# LSP server error output handler
def s:error_cb(lspserver: dict<any>, chan: channel, emsg: string,): void
- TraceLog(true, emsg)
+ util.TraceLog(true, emsg)
enddef
# LSP server exit callback
def s:exit_cb(lspserver: dict<any>, job: job, status: number): void
- WarnMsg("LSP server exited with status " .. status)
+ util.WarnMsg("LSP server exited with status " .. status)
lspserver.job = v:none
lspserver.running = false
lspserver.requests = {}
# Start a LSP server
def s:startServer(lspserver: dict<any>): number
if lspserver.running
- WarnMsg("LSP server for is already running")
+ util.WarnMsg("LSP server for is already running")
return 0
endif
var job = job_start(cmd, opts)
if job->job_status() == 'fail'
- ErrMsg("Error: Failed to start LSP server " .. lspserver.path)
+ util.ErrMsg("Error: Failed to start LSP server " .. lspserver.path)
return 1
endif
}
var curdir: string = getcwd()
initparams.rootPath = curdir
- initparams.rootUri = LspFileToUri(curdir)
+ initparams.rootUri = util.LspFileToUri(curdir)
initparams.workspaceFolders = [{
name: fnamemodify(curdir, ':t'),
- uri: LspFileToUri(curdir)
+ uri: util.LspFileToUri(curdir)
}]
initparams.trace = 'off'
initparams.capabilities = clientCaps
# Stop a LSP server
def s:stopServer(lspserver: dict<any>): number
if !lspserver.running
- WarnMsg("LSP server is not running")
+ util.WarnMsg("LSP server is not running")
return 0
endif
# interface DidOpenTextDocumentParams
# interface TextDocumentItem
var tdi = {}
- tdi.uri = LspBufnrToUri(bnr)
+ tdi.uri = util.LspBufnrToUri(bnr)
tdi.languageId = ftype
tdi.version = 1
tdi.text = getbufline(bnr, 1, '$')->join("\n") .. "\n"
# interface DidCloseTextDocumentParams
# interface TextDocumentIdentifier
var tdid = {}
- tdid.uri = LspBufnrToUri(bnr)
+ tdid.uri = util.LspBufnrToUri(bnr)
notif.params->extend({textDocument: tdid})
lspserver.sendMessage(notif)
# interface DidChangeTextDocumentParams
# interface VersionedTextDocumentIdentifier
var vtdid: dict<any> = {}
- vtdid.uri = LspBufnrToUri(bnr)
+ vtdid.uri = util.LspBufnrToUri(bnr)
# Use Vim 'changedtick' as the LSP document version number
vtdid.version = bnr->getbufvar('changedtick')
def s:getLspTextDocPosition(): dict<dict<any>>
# interface TextDocumentIdentifier
# interface Position
- return {textDocument: {uri: LspFileToUri(@%)},
+ return {textDocument: {uri: util.LspFileToUri(@%)},
position: s:getLspPosition()}
enddef
def s:getCompletion(lspserver: dict<any>, triggerKind_arg: number): void
# Check whether LSP server supports completion
if !lspserver.caps->has_key('completionProvider')
- ErrMsg("Error: LSP server does not support completion")
+ util.ErrMsg("Error: LSP server does not support completion")
return
endif
# Check whether LSP server supports jumping to a definition
if !lspserver.caps->has_key('definitionProvider')
|| !lspserver.caps.definitionProvider
- ErrMsg("Error: LSP server does not support jumping to a definition")
+ util.ErrMsg("Error: LSP server does not support jumping to a definition")
return
endif
- PushCursorToTagStack()
+ util.PushCursorToTagStack()
var req = lspserver.createRequest('textDocument/definition')
# interface DefinitionParams
# interface TextDocumentPositionParams
# Check whether LSP server supports jumping to a declaration
if !lspserver.caps->has_key('declarationProvider')
|| !lspserver.caps.declarationProvider
- ErrMsg("Error: LSP server does not support jumping to a declaration")
+ util.ErrMsg("Error: LSP server does not support jumping to a declaration")
return
endif
- PushCursorToTagStack()
+ util.PushCursorToTagStack()
var req = lspserver.createRequest('textDocument/declaration')
# interface DeclarationParams
# Check whether LSP server supports jumping to a type definition
if !lspserver.caps->has_key('typeDefinitionProvider')
|| !lspserver.caps.typeDefinitionProvider
- ErrMsg("Error: LSP server does not support jumping to a type definition")
+ util.ErrMsg("Error: LSP server does not support jumping to a type definition")
return
endif
- PushCursorToTagStack()
+ util.PushCursorToTagStack()
var req = lspserver.createRequest('textDocument/typeDefinition')
# interface TypeDefinitionParams
# Check whether LSP server supports jumping to a implementation
if !lspserver.caps->has_key('implementationProvider')
|| !lspserver.caps.implementationProvider
- ErrMsg("Error: LSP server does not support jumping to an implementation")
+ util.ErrMsg("Error: LSP server does not support jumping to an implementation")
return
endif
- PushCursorToTagStack()
+ util.PushCursorToTagStack()
var req = lspserver.createRequest('textDocument/implementation')
# interface ImplementationParams
def s:showSignature(lspserver: dict<any>): void
# Check whether LSP server supports signature help
if !lspserver.caps->has_key('signatureHelpProvider')
- ErrMsg("Error: LSP server does not support signature help")
+ util.ErrMsg("Error: LSP server does not support signature help")
return
endif
var notif: dict<any> = lspserver.createNotification('textDocument/didSave')
# interface: DidSaveTextDocumentParams
- notif.params->extend({textDocument: {uri: LspBufnrToUri(bnr)}})
+ notif.params->extend({textDocument: {uri: util.LspBufnrToUri(bnr)}})
lspserver.sendMessage(notif)
enddef
# Check whether LSP server supports getting reference information
if !lspserver.caps->has_key('referencesProvider')
|| !lspserver.caps.referencesProvider
- ErrMsg("Error: LSP server does not support showing references")
+ util.ErrMsg("Error: LSP server does not support showing references")
return
endif
# Check whether LSP server supports getting highlight information
if !lspserver.caps->has_key('documentHighlightProvider')
|| !lspserver.caps.documentHighlightProvider
- ErrMsg("Error: LSP server does not support document highlight")
+ util.ErrMsg("Error: LSP server does not support document highlight")
return
endif
# Check whether LSP server supports getting document symbol information
if !lspserver.caps->has_key('documentSymbolProvider')
|| !lspserver.caps.documentSymbolProvider
- ErrMsg("Error: LSP server does not support getting list of symbols")
+ util.ErrMsg("Error: LSP server does not support getting list of symbols")
return
endif
var req = lspserver.createRequest('textDocument/documentSymbol')
# interface DocumentSymbolParams
# interface TextDocumentIdentifier
- req.params->extend({textDocument: {uri: LspFileToUri(fname)}})
+ req.params->extend({textDocument: {uri: util.LspFileToUri(fname)}})
lspserver.sendMessage(req)
enddef
# Check whether LSP server supports formatting documents
if !lspserver.caps->has_key('documentFormattingProvider')
|| !lspserver.caps.documentFormattingProvider
- ErrMsg("Error: LSP server does not support formatting documents")
+ util.ErrMsg("Error: LSP server does not support formatting documents")
return
endif
tabSize: tabsz,
insertSpaces: &expandtab ? true : false,
}
- req.params->extend({textDocument: {uri: LspFileToUri(fname)},
+ req.params->extend({textDocument: {uri: util.LspFileToUri(fname)},
options: fmtopts})
if rangeFormat
var r: dict<dict<number>> = {
# Check whether LSP server supports incoming calls
if !lspserver.caps->has_key('callHierarchyProvider')
|| !lspserver.caps.callHierarchyProvider
- ErrMsg("Error: LSP server does not support call hierarchy")
+ util.ErrMsg("Error: LSP server does not support call hierarchy")
return
endif
# Check whether LSP server supports rename operation
if !lspserver.caps->has_key('renameProvider')
|| !lspserver.caps.renameProvider
- ErrMsg("Error: LSP server does not support rename operation")
+ util.ErrMsg("Error: LSP server does not support rename operation")
return
endif
# Check whether LSP server supports code action operation
if !lspserver.caps->has_key('codeActionProvider')
|| !lspserver.caps.codeActionProvider
- ErrMsg("Error: LSP server does not support code action operation")
+ util.ErrMsg("Error: LSP server does not support code action operation")
return
endif
var r: dict<dict<number>> = {
start: {line: line('.') - 1, character: charcol('.') - 1},
end: {line: line('.') - 1, character: charcol('.') - 1}}
- req.params->extend({textDocument: {uri: LspFileToUri(fname)}, range: r})
+ req.params->extend({textDocument: {uri: util.LspFileToUri(fname)}, range: r})
var diag: list<dict<any>> = []
var lnum = line('.')
var diagInfo: dict<any> = lspserver.getDiagByLine(bnr, lnum)
# Check whether the LSP server supports listing workspace symbols
if !lspserver.caps->has_key('workspaceSymbolProvider')
|| !lspserver.caps.workspaceSymbolProvider
- ErrMsg("Error: LSP server does not support listing workspace symbols")
+ util.ErrMsg("Error: LSP server does not support listing workspace symbols")
return false
endif
|| !lspserver.caps.workspace->has_key('workspaceFolders')
|| !lspserver.caps.workspace.workspaceFolders->has_key('supported')
|| !lspserver.caps.workspace.workspaceFolders.supported
- ErrMsg('Error: LSP server does not support workspace folders')
+ util.ErrMsg('Error: LSP server does not support workspace folders')
return
endif
if lspserver.workspaceFolders->index(dirName) != -1
- ErrMsg('Error: ' .. dirName .. ' is already part of this workspace')
+ util.ErrMsg('Error: ' .. dirName .. ' is already part of this workspace')
return
endif
|| !lspserver.caps.workspace->has_key('workspaceFolders')
|| !lspserver.caps.workspace.workspaceFolders->has_key('supported')
|| !lspserver.caps.workspace.workspaceFolders.supported
- ErrMsg('Error: LSP server does not support workspace folders')
+ util.ErrMsg('Error: LSP server does not support workspace folders')
return
endif
var idx: number = lspserver.workspaceFolders->index(dirName)
if idx == -1
- ErrMsg('Error: ' .. dirName .. ' is not currently part of this workspace')
+ util.ErrMsg('Error: ' .. dirName .. ' is not currently part of this workspace')
return
endif
# Check whether LSP server supports selection ranges
if !lspserver.caps->has_key('selectionRangeProvider')
|| !lspserver.caps.selectionRangeProvider
- ErrMsg("Error: LSP server does not support selection ranges")
+ util.ErrMsg("Error: LSP server does not support selection ranges")
return
endif
var req = lspserver.createRequest('textDocument/selectionRange')
# interface SelectionRangeParams
# interface TextDocumentIdentifier
- req.params->extend({textDocument: {uri: LspFileToUri(fname)},
+ req.params->extend({textDocument: {uri: util.LspFileToUri(fname)},
positions: [s:getLspPosition()]})
lspserver.sendMessage(req)
enddef
# Check whether LSP server supports fold ranges
if !lspserver.caps->has_key('foldingRangeProvider')
|| !lspserver.caps.foldingRangeProvider
- ErrMsg("Error: LSP server does not support folding")
+ util.ErrMsg("Error: LSP server does not support folding")
return
endif
var req = lspserver.createRequest('textDocument/foldingRange')
# interface FoldingRangeParams
# interface TextDocumentIdentifier
- req.params->extend({textDocument: {uri: LspFileToUri(fname)}})
+ req.params->extend({textDocument: {uri: util.LspFileToUri(fname)}})
lspserver.sendMessage(req)
enddef
createNotification: function('s:createNotification', [lspserver]),
sendResponse: function('s:sendResponse', [lspserver]),
sendMessage: function('s:sendMessage', [lspserver]),
- processReply: function('ProcessReply', [lspserver]),
- processNotif: function('ProcessNotif', [lspserver]),
- processRequest: function('ProcessRequest', [lspserver]),
- processMessages: function('ProcessMessages', [lspserver]),
+ processReply: function(handlers.ProcessReply, [lspserver]),
+ processNotif: function(handlers.ProcessNotif, [lspserver]),
+ processRequest: function(handlers.ProcessRequest, [lspserver]),
+ processMessages: function(handlers.ProcessMessages, [lspserver]),
getDiagByLine: function('s:getDiagByLine', [lspserver]),
textdocDidOpen: function('s:textdocDidOpen', [lspserver]),
textdocDidClose: function('s:textdocDidClose', [lspserver]),
else
lsp_log_dir = $TEMP .. '\\'
endif
-export var lsp_server_trace: bool = false
+var lsp_server_trace: bool = false
+
+# Enable or disable LSP server trace messages
+export def ServerTrace(trace_enable: bool)
+ lsp_server_trace = trace_enable
+enddef
# Log a message from the LSP server. stderr is true for logging messages
# from the standard error and false for stdout.
cursor(1, 5)
:LspShowReferences
:sleep 1
- qfl = getloclist()
+ qfl = getloclist(0)
assert_equal(1, qfl->len())
assert_equal([1, 5], [qfl[0].lnum, qfl[0].col])