uses: rhysd/action-setup-vim@v1
id: vim
with:
- version: nightly
+ version: v9.0.0000
- name: Checkout LSP Code
uses: actions/checkout@v2
- name: Run Tests

-Language Server Protocol (LSP) plugin for Vim9. You need Vim version 8.2.2342 or above to use this plugin.
+Language Server Protocol (LSP) plugin for Vim9. You need Vim version 9.0 or above to use this plugin.
## Installation
# Functions for dealing with call hierarchy (incoming/outgoing calls)
-var util = {}
-if has('patch-8.2.4019')
- import './util.vim' as util_import
-
- util.WarnMsg = util_import.WarnMsg
- util.LspUriToFile = util_import.LspUriToFile
- util.GetLineByteFromPos = util_import.GetLineByteFromPos
-else
- import {WarnMsg,
- LspUriToFile,
- GetLineByteFromPos} from './util.vim'
-
- util.WarnMsg = WarnMsg
- util.LspUriToFile = LspUriToFile
- util.GetLineByteFromPos = GetLineByteFromPos
-endif
+import './util.vim'
def CreateLoclistWithCalls(calls: list<dict<any>>, incoming: bool)
var qflist: list<dict<any>> = []
qflist->add({filename: fname,
lnum: r.start.line + 1,
col: util.GetLineByteFromPos(bnr, r.start) + 1,
- text: name .. ': ' .. text})
+ text: $'{name}: {text}'})
endfor
else
var pos: dict<any> = item.to.range.start
var text: string = bnr->getbufline(pos.line + 1)[0]->trim("\t ", 1)
qflist->add({filename: fname,
- lnum: item.to.range.start.line + 1,
- col: util.GetLineByteFromPos(bnr, pos) + 1,
- text: name .. ': ' .. text})
+ lnum: item.to.range.start.line + 1,
+ col: util.GetLineByteFromPos(bnr, pos) + 1,
+ text: $'{name}: {text}'})
endif
endfor
var save_winid = win_getid()
# Functions related to handling LSP code actions to fix diagnostics.
-var util = {}
-var textedit = {}
-
-if has('patch-8.2.4019')
- import './util.vim' as util_import
- import './textedit.vim' as textedit_import
-
- util.WarnMsg = util_import.WarnMsg
- textedit.ApplyWorkspaceEdit = textedit_import.ApplyWorkspaceEdit
-else
- import WarnMsg from './util.vim'
- import ApplyWorkspaceEdit from './textedit.vim'
-
- util.WarnMsg = WarnMsg
- textedit.ApplyWorkspaceEdit = ApplyWorkspaceEdit
-endif
+import './util.vim'
+import './textedit.vim'
export def ApplyCodeAction(lspserver: dict<any>, actions: list<dict<any>>): void
if actions->empty()
# Functions related to handling LSP diagnostics.
-var opt = {}
-var util = {}
-
-if has('patch-8.2.4019')
- import './lspoptions.vim' as opt_import
- import './util.vim' as util_import
-
- opt.lspOptions = opt_import.lspOptions
- util.WarnMsg = util_import.WarnMsg
- util.GetLineByteFromPos = util_import.GetLineByteFromPos
- util.LspUriToFile = util_import.LspUriToFile
-else
- import lspOptions from './lspoptions.vim'
- import {WarnMsg,
- LspUriToFile,
- GetLineByteFromPos} from './util.vim'
-
- opt.lspOptions = lspOptions
- util.WarnMsg = WarnMsg
- util.LspUriToFile = LspUriToFile
- util.GetLineByteFromPos = GetLineByteFromPos
-endif
+import './lspoptions.vim' as opt
+import './util.vim'
# Remove the diagnostics stored for buffer 'bnr'
export def DiagRemoveFile(lspserver: dict<any>, bnr: number)
diag_by_lnum[lnum] = d
endfor
- lspserver.diagsMap->extend({['' .. bnr]: diag_by_lnum})
+ lspserver.diagsMap->extend({[$'{bnr}']: diag_by_lnum})
ProcessNewDiags(lspserver, bnr)
enddef
# in a location list
export def ShowAllDiags(lspserver: dict<any>): void
if !DiagsUpdateLocList(lspserver, bufnr())
- util.WarnMsg('No diagnostic messages found for ' .. @%)
+ util.WarnMsg($'No diagnostic messages found for {@%}')
return
endif
var max_width = &columns - 15
var code = ""
if has_key(diag, 'code')
- code = "[" .. diag.code .. "] "
+ code = $'[{diag.code}] '
endif
var msgNoLineBreak = code .. substitute(substitute(diag.message, "\n", " ", ""), "\\n", " ", "")
echo msgNoLineBreak[ : max_width]
var bnr: number = bufnr()
if !lspserver.diagsMap->has_key(bnr) || lspserver.diagsMap[bnr]->empty()
- util.WarnMsg('No diagnostic messages found for ' .. fname)
+ util.WarnMsg($'No diagnostic messages found for {fname}')
return
endif
# Refer to https://microsoft.github.io/language-server-protocol/specification
# for the Language Server Protocol (LSP) specificaiton.
-var opt = {}
-var util = {}
-var diag = {}
-var outline = {}
-var textedit = {}
-var symbol = {}
-var codeaction = {}
-var callhier = {}
-var selection = {}
-var signature = {}
-
-if has('patch-8.2.4019')
- import './lspoptions.vim' as opt_import
- import './util.vim' as util_import
- import './diag.vim' as diag_import
- import './outline.vim' as outline_import
- import './textedit.vim' as textedit_import
- import './symbol.vim' as symbol_import
- import './codeaction.vim' as codeaction_import
- import './callhierarchy.vim' as callhierarchy_import
- import './selection.vim' as selection_import
- import './signature.vim' as signature_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
- diag.DiagNotification = diag_import.DiagNotification
- outline.UpdateOutlineWindow = outline_import.UpdateOutlineWindow
- textedit.ApplyTextEdits = textedit_import.ApplyTextEdits
- textedit.ApplyWorkspaceEdit = textedit_import.ApplyWorkspaceEdit
- symbol.ShowReferences = symbol_import.ShowReferences
- symbol.GotoSymbol = symbol_import.GotoSymbol
- codeaction.ApplyCodeAction = codeaction_import.ApplyCodeAction
- callhier.IncomingCalls = callhierarchy_import.IncomingCalls
- callhier.OutgoingCalls = callhierarchy_import.OutgoingCalls
- selection.SelectionStart = selection_import.SelectionStart
- signature.SignatureInit = signature_import.SignatureInit
- signature.SignatureDisplay = signature_import.SignatureDisplay
-else
- import lspOptions from './lspoptions.vim'
- import {WarnMsg,
- ErrMsg,
- TraceLog,
- LspUriToFile,
- GetLineByteFromPos} from './util.vim'
- import DiagNotification from './diag.vim'
- import UpdateOutlineWindow from './outline.vim'
- import {ApplyTextEdits, ApplyWorkspaceEdit} from './textedit.vim'
- import {ShowReferences, GotoSymbol} from './symbol.vim'
- import ApplyCodeAction from './codeaction.vim'
- import {IncomingCalls, OutgoingCalls} from './callhierarchy.vim'
- import {SelectionStart} from './selection.vim'
- import {SignatureInit, SignatureDisplay} from './signature.vim'
-
- opt.lspOptions = lspOptions
- util.WarnMsg = WarnMsg
- util.ErrMsg = ErrMsg
- util.TraceLog = TraceLog
- util.LspUriToFile = LspUriToFile
- util.GetLineByteFromPos = GetLineByteFromPos
- diag.DiagNotification = DiagNotification
- outline.UpdateOutlineWindow = UpdateOutlineWindow
- textedit.ApplyTextEdits = ApplyTextEdits
- textedit.ApplyWorkspaceEdit = ApplyWorkspaceEdit
- symbol.ShowReferences = ShowReferences
- symbol.GotoSymbol = GotoSymbol
- codeaction.ApplyCodeAction = ApplyCodeAction
- callhier.IncomingCalls = IncomingCalls
- callhier.OutgoingCalls = OutgoingCalls
- selection.SelectionStart = SelectionStart
- signature.SignatureInit = SignatureInit
- signature.SignatureDisplay = SignatureDisplay
-endif
+import './lspoptions.vim' as opt
+import './util.vim'
+import './diag.vim'
+import './outline.vim'
+import './textedit.vim'
+import './symbol.vim'
+import './codeaction.vim'
+import './callhierarchy.vim' as callhier
+import './selection.vim'
+import './signature.vim'
# process the 'initialize' method reply from the LSP server
# Result: InitializeResult
if (&modified && !&hidden) || &buftype != ''
# if the current buffer has unsaved changes and 'hidden' is not set,
# or if the current buffer is a special buffer, then ask to save changes
- exe 'confirm edit ' .. fname
+ exe $'confirm edit {fname}'
else
- exe 'edit ' .. fname
+ exe $'edit {fname}'
endif
enddef
hoverText = reply.result.contents.value->split("\n")
hoverKind = 'markdown'
else
- util.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
- util.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
- util.ErrMsg('Error: Unsupported hover contents (' .. reply.result.contents .. ')')
+ util.ErrMsg($'Error: Unsupported hover contents ({reply.result.contents})')
return
endif
if opt.lspOptions.hoverInPreview
wincmd P
setlocal buftype=nofile
setlocal bufhidden=delete
- exe 'setlocal ft=' .. hoverKind
+ exe $'setlocal ft={hoverKind}'
deletebufline(bufnr(), 1, '$')
append(0, hoverText)
cursor(1, 1)
name = symbol.name
if symbol->has_key('containerName')
if symbol.containerName != ''
- name ..= ' [' .. symbol.containerName .. ']'
+ name ..= $' [{symbol.containerName}]'
endif
endif
r = symbol.location.range
if end_lnum < foldRange.startLine + 2
end_lnum = foldRange.startLine + 2
endif
- exe ':' .. (foldRange.startLine + 2) .. ',' .. end_lnum .. 'fold'
+ exe $':{foldRange.startLine + 2}, {end_lnum}fold'
# Open all the folds, otherwise the subsequently created folds are not
# correct.
:silent! foldopen!
endif
var str: string = filename
if dirname != '.'
- str ..= ' (' .. dirname .. '/)'
+ str ..= $' ({dirname}/)'
endif
return str
enddef
symName = symbol.name
if symbol->has_key('containerName') && symbol.containerName != ''
- symName = symbol.containerName .. '::' .. symName
+ symName = $'{symbol.containerName}::{symName}'
endif
- symName ..= ' [' .. LspSymbolKindToName(symbol.kind) .. ']'
+ symName ..= $' [{LspSymbolKindToName(symbol.kind)}]'
symName ..= ' ' .. MakeMenuName(
lspserver.workspaceSymbolPopup->popup_getpos().core_width,
fileName)
if lsp_reply_handlers->has_key(req.method)
lsp_reply_handlers[req.method](lspserver, req, reply)
else
- util.ErrMsg("Error: Unsupported reply received from LSP server: " .. reply->string() .. " for request: " .. req->string())
+ util.ErrMsg($'Error: Unsupported reply received from LSP server: {reply->string()} for request: {req->string()}')
endif
enddef
mtype = msgType[reply.params.type]
endif
- :echomsg 'Lsp ' .. mtype .. reply.params.message
+ :echomsg $'Lsp {mtype} {reply.params.message}'
enddef
# process a log notification message from the LSP server
mtype = msgType[reply.params.type]
endif
- util.TraceLog(false, '[' .. mtype .. ']: ' .. reply.params.message)
+ util.TraceLog(false, $'[{mtype}]: {reply.params.message}')
enddef
# process unsupported notification messages
def ProcessUnsupportedNotif(lspserver: dict<any>, reply: dict<any>)
- util.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
# per-filetype private map inside to record if ntf once or not
if lsp_notif_handlers->has_key(reply.method)
lsp_notif_handlers[reply.method](lspserver, reply)
else
- util.ErrMsg('Error: Unsupported notification received from LSP server ' .. reply->string())
+ util.ErrMsg($'Error: Unsupported notification received from LSP server {reply->string()}')
endif
enddef
endif
var workspaceEditParams: dict<any> = request.params
if workspaceEditParams->has_key('label')
- :echomsg "Workspace edit" .. workspaceEditParams.label
+ :echomsg $'Workspace edit {workspaceEditParams.label}'
endif
textedit.ApplyWorkspaceEdit(workspaceEditParams.edit)
# TODO: Need to return the proper result of the edit operation
enddef
def ProcessUnsupportedReq(lspserver: dict<any>, request: dict<any>)
- util.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
- util.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()}')
endif
enddef
try
msg = content->json_decode()
catch
- util.ErrMsg("Error(LSP): Malformed content (" .. content .. ")")
+ util.ErrMsg($'Error(LSP): Malformed content ({content})')
lspserver.data = lspserver.data[idx + len :]
continue
endtry
else
# request failed
var emsg: string = msg.error.message
- emsg ..= ', code = ' .. msg.error.code
+ emsg ..= $', code = {msg.error.code}'
if msg.error->has_key('data')
- emsg = emsg .. ', data = ' .. msg.error.data->string()
+ emsg = $'{emsg}, data = {msg.error.data->string()}'
endif
- util.ErrMsg("Error(LSP): request " .. req.method .. " failed ("
- .. emsg .. ")")
+ util.ErrMsg($'Error(LSP): request {req.method} failed ({emsg})')
endif
endif
elseif msg->has_key('id') && msg->has_key('method')
# notification message from the server
lspserver.processNotif(msg)
else
- util.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
-# Needs Vim 8.2.2342 and higher
-if v:version < 802 || !has('patch-8.2.2342')
+# Needs Vim 9.0 and higher
+if v:version < 900
finish
endif
-var opt = {}
-var lserver = {}
-var util = {}
-var diag = {}
-var symbol = {}
-var outline = {}
-var signature = {}
-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 './buffer.vim' as buf_import
- import './diag.vim' as diag_import
- import './symbol.vim' as symbol_import
- import './outline.vim' as outline_import
- import './signature.vim' as signature_import
-
- 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
- util.LspUriRemote = util_import.LspUriRemote
- buf.BufLspServerSet = buf_import.BufLspServerSet
- buf.BufLspServerRemove = buf_import.BufLspServerRemove
- buf.BufHasLspServer = buf_import.BufHasLspServer
- buf.BufLspServerGet = buf_import.BufLspServerGet
- buf.CurbufGetServer = buf_import.CurbufGetServer
- diag.UpdateDiags = diag_import.UpdateDiags
- diag.DiagsGetErrorCount = diag_import.DiagsGetErrorCount
- diag.ShowAllDiags = diag_import.ShowAllDiags
- diag.ShowCurrentDiag = diag_import.ShowCurrentDiag
- diag.ShowCurrentDiagInStatusLine = diag_import.ShowCurrentDiagInStatusLine
- diag.LspDiagsJump = diag_import.LspDiagsJump
- diag.DiagRemoveFile = diag_import.DiagRemoveFile
- diag.DiagsHighlightEnable = diag_import.DiagsHighlightEnable
- diag.DiagsHighlightDisable = diag_import.DiagsHighlightDisable
- symbol.ShowSymbolMenu = symbol_import.ShowSymbolMenu
- outline.OpenOutlineWindow = outline_import.OpenOutlineWindow
- outline.SkipOutlineRefresh = outline_import.SkipOutlineRefresh
- signature.SignatureInit = signature_import.SignatureInit
-else
- import {lspOptions} from './lspoptions.vim'
- import NewLspServer from './lspserver.vim'
- import {WarnMsg,
- ErrMsg,
- ServerTrace,
- ClearTraceLogs,
- GetLineByteFromPos,
- PushCursorToTagStack,
- LspUriRemote} from './util.vim'
- import {BufLspServerSet,
- BufLspServerRemove,
- BufHasLspServer,
- BufLspServerGet,
- CurbufGetServer} from './buffer.vim'
- import {DiagRemoveFile,
- UpdateDiags,
- DiagsGetErrorCount,
- ShowAllDiags,
- ShowCurrentDiag,
- ShowCurrentDiagInStatusLine,
- LspDiagsJump,
- DiagsHighlightEnable,
- DiagsHighlightDisable} from './diag.vim'
- import ShowSymbolMenu from './symbol.vim'
- import {OpenOutlineWindow, SkipOutlineRefresh} from './outline.vim'
- import {SignatureInit} from './signature.vim'
-
- opt.lspOptions = lspOptions
- lserver.NewLspServer = NewLspServer
- util.WarnMsg = WarnMsg
- util.ErrMsg = ErrMsg
- util.ServerTrace = ServerTrace
- util.ClearTraceLogs = ClearTraceLogs
- util.GetLineByteFromPos = GetLineByteFromPos
- util.PushCursorToTagStack = PushCursorToTagStack
- util.LspUriRemote = LspUriRemote
- buf.BufLspServerSet = BufLspServerSet
- buf.BufLspServerRemove = BufLspServerRemove
- buf.BufHasLspServer = BufHasLspServer
- buf.BufLspServerGet = BufLspServerGet
- buf.CurbufGetServer = CurbufGetServer
- diag.DiagRemoveFile = DiagRemoveFile
- diag.UpdateDiags = UpdateDiags
- diag.DiagsGetErrorCount = DiagsGetErrorCount
- diag.ShowAllDiags = ShowAllDiags
- diag.ShowCurrentDiag = ShowCurrentDiag
- diag.ShowCurrentDiagInStatusLine = ShowCurrentDiagInStatusLine
- diag.LspDiagsJump = LspDiagsJump
- diag.DiagsHighlightEnable = DiagsHighlightEnable
- diag.DiagsHighlightDisable = DiagsHighlightDisable
- symbol.ShowSymbolMenu = ShowSymbolMenu
- outline.OpenOutlineWindow = OpenOutlineWindow
- outline.SkipOutlineRefresh = SkipOutlineRefresh
- signature.SignatureInit = SignatureInit
-endif
+import './lspoptions.vim' as opt
+import './lspserver.vim' as lserver
+import './util.vim'
+import './buffer.vim' as buf
+import './diag.vim'
+import './symbol.vim'
+import './outline.vim'
+import './signature.vim'
# LSP server information
var lspServers: list<dict<any>> = []
var lspserver: dict<any> = buf.CurbufGetServer()
if lspserver->empty()
- util.ErrMsg('Error: LSP server for "' .. fname .. '" is not found')
+ util.ErrMsg($'Error: LSP server for "{fname}" is not found')
return {}
endif
if !lspserver.running
- util.ErrMsg('Error: LSP server for "' .. fname .. '" is not running')
+ util.ErrMsg($'Error: LSP server for "{fname}" is not running')
return {}
endif
if !lspserver.ready
- util.ErrMsg('Error: LSP server for "' .. fname .. '" is not ready')
+ util.ErrMsg($'Error: LSP server for "{fname}" is not ready')
return {}
endif
else
msg ..= 'not running'
endif
- msg ..= ' ' .. lspserver.path
+ msg ..= $' {lspserver.path}'
:echomsg msg
endfor
enddef
# Set buffer local autocmds
augroup LSPBufferAutocmds
# file saved notification handler
- exe 'autocmd BufWritePost <buffer=' .. bnr .. '> call LspSavedFile()'
+ exe $'autocmd BufWritePost <buffer={bnr}> call LspSavedFile()'
if opt.lspOptions.autoComplete
# Trigger 24x7 insert mode completion when text is changed
- exe 'autocmd TextChangedI <buffer=' .. bnr .. '> call LspComplete()'
+ exe $'autocmd TextChangedI <buffer={bnr}> call LspComplete()'
endif
# Update the diagnostics when insert mode is stopped
- exe 'autocmd InsertLeave <buffer=' .. bnr .. '> call LspLeftInsertMode()'
+ exe $'autocmd InsertLeave <buffer={bnr}> call LspLeftInsertMode()'
if opt.lspOptions.autoHighlight &&
lspserver.caps->has_key('documentHighlightProvider')
&& lspserver.caps.documentHighlightProvider
# Highlight all the occurrences of the current keyword
- exe 'autocmd CursorMoved <buffer=' .. bnr .. '> '
- .. 'call LspDocHighlightClear() | call LspDocHighlight()'
+ exe $'autocmd CursorMoved <buffer={bnr}> call LspDocHighlightClear() | call LspDocHighlight()'
endif
augroup END
endfor
# Start the server again
- lspserver.startServer(true)
+ lspserver.startServer()
# Add all the buffers with the same file type as the current buffer
for binfo in getbufinfo({bufloaded: 1})
if !executable(server.path)
if !opt.lspOptions.ignoreMissingServer
- util.ErrMsg('Error: LSP server ' .. server.path .. ' is not found')
+ util.ErrMsg($'Error: LSP server {server.path} is not found')
endif
return
endif
var args: list<string> = []
if server->has_key('args')
if server.args->type() != v:t_list
- util.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
args = server.args
var initializationOptions: dict<any> = {}
if server->has_key('initializationOptions')
if server.initializationOptions->type() != v:t_dict
- util.ErrMsg('Error: initializationOptions for LSP server ' .. server.initializationOptions .. ' is not a Dictionary')
+ util.ErrMsg($'Error: initializationOptions for LSP server {server.initializationOptions} is not a Dictionary')
return
endif
initializationOptions = server.initializationOptions
endif
if server.omnicompl->type() != v:t_bool
- util.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
LspOmniComplSet(ftype, server.omnicompl)
endfor
else
- util.ErrMsg('Error: Unsupported file type information "' ..
- server.filetype->string() .. '" in LSP server registration')
+ util.ErrMsg($'Error: Unsupported file type information "{server.filetype->string()}" in LSP server registration')
continue
endif
endfor
# Params: SetTraceParams
export def SetTraceServer(traceVal: string)
if ['off', 'message', 'verbose']->index(traceVal) == -1
- util.ErrMsg("Error: Unsupported LSP server trace value " .. traceVal)
+ util.ErrMsg($'Error: Unsupported LSP server trace value {traceVal}')
return
endif
endif
var sym: string = expand('<cword>')
- var newName: string = input("Rename symbol '" .. sym .. "' to: ", sym)
+ var newName: string = input($"Rename symbol '{sym}' to: ", sym)
if newName == ''
return
endif
return
endif
- echomsg 'Workspace Folders: ' .. lspserver.workspaceFolders->string()
+ echomsg $'Workspace Folders: {lspserver.workspaceFolders->string()}'
enddef
# Add a workspace folder. Default is to use the current folder.
endif
:redraw!
if !dirName->isdirectory()
- util.ErrMsg('Error: ' .. dirName .. ' is not a directory')
+ util.ErrMsg($'Error: {dirName} is not a directory')
return
endif
endif
:redraw!
if !dirName->isdirectory()
- util.ErrMsg('Error: ' .. dirName .. ' is not a directory')
+ util.ErrMsg($'Error: {dirName} is not a directory')
return
endif
# Refer to https://microsoft.github.io/language-server-protocol/specification
# for the Language Server Protocol (LSP) specificaiton.
-var handlers = {}
-var diag = {}
-var util = {}
-var selection = {}
-
-if has('patch-8.2.4019')
- import './handlers.vim' as handlers_import
- import './util.vim' as util_import
- import './diag.vim' as diag_import
- import './selection.vim' as selection_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.LspBufnrToUri = util_import.LspBufnrToUri
- util.LspFileToUri = util_import.LspFileToUri
- util.PushCursorToTagStack = util_import.PushCursorToTagStack
- diag.GetDiagByLine = diag_import.GetDiagByLine
- selection.SelectionModify = selection_import.SelectionModify
-else
- import {ProcessReply,
- ProcessNotif,
- ProcessRequest,
- ProcessMessages} from './handlers.vim'
- import {GetDiagByLine} from './diag.vim'
- import {WarnMsg,
- ErrMsg,
- TraceLog,
- LspBufnrToUri,
- LspFileToUri,
- PushCursorToTagStack} from './util.vim'
- import {SelectionModify} from './selection.vim'
-
- handlers.ProcessReply = ProcessReply
- handlers.ProcessNotif = ProcessNotif
- handlers.ProcessRequest = ProcessRequest
- handlers.ProcessMessages = ProcessMessages
- util.WarnMsg = WarnMsg
- util.ErrMsg = ErrMsg
- util.TraceLog = TraceLog
- util.LspBufnrToUri = LspBufnrToUri
- util.LspFileToUri = LspFileToUri
- util.PushCursorToTagStack = PushCursorToTagStack
- diag.GetDiagByLine = GetDiagByLine
- selection.SelectionModify = SelectionModify
-endif
+import './handlers.vim'
+import './util.vim'
+import './diag.vim'
+import './selection.vim'
# LSP server standard output handler
def Output_cb(lspserver: dict<any>, chan: channel, msg: string): void
# LSP server exit callback
def Exit_cb(lspserver: dict<any>, job: job, status: number): void
- util.WarnMsg("LSP server exited with status " .. status)
+ util.WarnMsg($'LSP server exited with status {status}')
lspserver.running = false
lspserver.ready = false
lspserver.requests = {}
#
def StartServer(lspserver: dict<any>): number
if lspserver.running
- util.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'
- util.ErrMsg("Error: Failed to start LSP server " .. lspserver.path)
+ util.ErrMsg($'Error: Failed to start LSP server {lspserver.path}')
return 1
endif
# Send a request message to LSP server
def SendMessage(lspserver: dict<any>, content: dict<any>): void
var payload_js: string = content->json_encode()
- var msg = "Content-Length: " .. payload_js->len() .. "\r\n\r\n"
+ var msg = $"Content-Length: {payload_js->len()}\r\n\r\n"
var ch = lspserver.job->job_getchannel()
if ch_status(ch) != 'open'
# LSP server has exited
endif
if lspserver.workspaceFolders->index(dirName) != -1
- util.ErrMsg('Error: ' .. dirName .. ' is already part of this workspace')
+ util.ErrMsg($'Error: {dirName} is already part of this workspace')
return
endif
var idx: number = lspserver.workspaceFolders->index(dirName)
if idx == -1
- util.ErrMsg('Error: ' .. dirName .. ' is not currently part of this workspace')
+ util.ErrMsg($'Error: {dirName} is not currently part of this workspace')
return
endif
# Display the LSP server capabilities (received during the initialization
# stage).
def ShowCapabilities(lspserver: dict<any>)
- echo "Capabilities of '" .. lspserver.path .. "' LSP server:"
+ echo $"Capabilities of '{lspserver.path}' LSP server:"
for k in lspserver.caps->keys()->sort()
- echo k .. ": " .. lspserver.caps[k]->string()
+ echo $'{k}: {lspserver.caps[k]->string()}'
endfor
enddef
vim9script
-var util = {}
-var opt = {}
-if has('patch-8.2.4019')
- import './util.vim' as util_import
- import './lspoptions.vim' as opt_import
- util.GetLineByteFromPos = util_import.GetLineByteFromPos
- opt.lspOptions = opt_import.lspOptions
-else
- import GetLineByteFromPos from './util.vim'
- import lspOptions from './lspoptions.vim'
-
- util.GetLineByteFromPos = GetLineByteFromPos
- opt.lspOptions = lspOptions
-endif
+import './util.vim'
+import './lspoptions.vim' as opt
# jump to a symbol selected in the outline window
def OutlineJumpToSymbol()
win_execute(symWinid, 'vertical resize 20')
endif
- exe 'edit ' .. fname
+ exe $'edit {fname}'
else
wid->win_gotoid()
endif
:setlocal modifiable
:silent! :%d _
setline(1, ['# LSP Outline View',
- '# ' .. fname->fnamemodify(':t') .. ' ('
- .. fname->fnamemodify(':h') .. ')'])
+ $'# {fname->fnamemodify(":t")} ({fname->fnamemodify(":h")})'])
# First two lines in the buffer display comment information
var lnumMap: list<dict<any>> = [{}, {}]
var wininfo = wid->getwininfo()
if symbolTable[mid].outlineLine < wininfo[0].topline
|| symbolTable[mid].outlineLine > wininfo[0].botline
- var cmd: string = 'call cursor(' ..
- symbolTable[mid].outlineLine .. ', 1) | normal z.'
+ var cmd: string = $'call cursor({symbolTable[mid].outlineLine}, 1) | normal z.'
win_execute(wid, cmd)
endif
enddef
var prevWinID: number = win_getid()
if opt.lspOptions.outlineOnRight
- execute ':botright :' .. opt.lspOptions.outlineWinSize .. 'vnew LSP-Outline'
+ execute $':botright :{opt.lspOptions.outlineWinSize}vnew LSP-Outline'
else
- execute ':topleft :' .. opt.lspOptions.outlineWinSize .. 'vnew LSP-Outline'
+ execute $':topleft :{opt.lspOptions.outlineWinSize}vnew LSP-Outline'
endif
:setlocal modifiable
:setlocal noreadonly
# Functions related to handling LSP range selection.
-var util = {}
-if has('patch-8.2.4019')
- import './util.vim' as util_import
-
- util.GetLineByteFromPos = util_import.GetLineByteFromPos
-else
- import {GetLineByteFromPos} from './util.vim'
-
- util.GetLineByteFromPos = GetLineByteFromPos
-endif
+import './util.vim'
# Visually (character-wise) select the text in a range
def SelectText(bnr: number, range: dict<dict<number>>)
# Functions related to handling LSP symbol signature help.
-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 './buffer.vim' as buf_import
-
- opt.lspOptions = opt_import.lspOptions
- util.WarnMsg = util_import.WarnMsg
- buf.CurbufGetServer = buf_import.CurbufGetServer
-else
- import lspOptions from './lspoptions.vim'
- import {WarnMsg} from './util.vim'
- import {CurbufGetServer} from './buffer.vim'
-
- opt.lspOptions = lspOptions
- util.WarnMsg = WarnMsg
- buf.CurbufGetServer = CurbufGetServer
-endif
+import './lspoptions.vim' as opt
+import './util.vim'
+import './buffer.vim' as buf
# close the signature popup window
def CloseSignaturePopup(lspserver: dict<any>)
# map characters that trigger signature help
for ch in lspserver.caps.signatureHelpProvider.triggerCharacters
- exe 'inoremap <buffer> <silent> ' .. ch .. ' ' .. ch
- .. "<C-R>=LspShowSignature()<CR>"
+ exe $"inoremap <buffer> <silent> {ch} {ch}<C-R>=LspShowSignature()<CR>"
endfor
# close the signature popup when leaving insert mode
autocmd InsertLeave <buffer> call CloseCurBufSignaturePopup()
# - jump to a symbol definition, declaration, type definition or
# implementation
-var opt = {}
-var util = {}
-
-if has('patch-8.2.4019')
- import './lspoptions.vim' as opt_import
- import './util.vim' as util_import
-
- opt.lspOptions = opt_import.lspOptions
- util.PushCursorToTagStack = util_import.PushCursorToTagStack
- util.WarnMsg = util_import.WarnMsg
- util.LspUriToFile = util_import.LspUriToFile
- util.GetLineByteFromPos = util_import.GetLineByteFromPos
-else
- import lspOptions from './lspoptions.vim'
- import {WarnMsg,
- LspUriToFile,
- GetLineByteFromPos,
- PushCursorToTagStack} from './util.vim'
-
- opt.lspOptions = lspOptions
- util.WarnMsg = WarnMsg
- util.LspUriToFile = LspUriToFile
- util.GetLineByteFromPos = GetLineByteFromPos
- util.PushCursorToTagStack = PushCursorToTagStack
-endif
+import './lspoptions.vim' as opt
+import './util.vim'
# Handle keys pressed when the workspace symbol popup menu is displayed
def FilterSymbols(lspserver: dict<any>, popupID: number, key: string): bool
else
[]->setwinvar(popupID, 'LspSymbolTable')
endif
- echo 'Symbol: ' .. query
+ echo $'Symbol: {query}'
endif
# Update the workspace symbol query string
if &modified || &buftype != ''
# the current buffer is modified or is not a normal buffer, then open
# the file in a new window
- exe "split " .. symTbl[result - 1].file
+ exe $'split {symTbl[result - 1].file}'
else
- exe "confirm edit " .. symTbl[result - 1].file
+ exe $'confirm edit {symTbl[result - 1].file}'
endif
else
winList[0]->win_gotoid()
prop_type_add('lspworkspacesymbol',
{bufnr: lspserver.workspaceSymbolPopup->winbufnr(),
highlight: 'Title'})
- echo 'Symbol: ' .. query
+ echo $'Symbol: {query}'
enddef
# Display or peek symbol references in a location list
# When peeking the references, open the location list in a vertically
# split window to the right and make the location list window 30% of the
# source window width
- mods = 'belowright vert :' .. (winwidth(0) * 30) / 100
+ mods = $'belowright vert :{(winwidth(0) * 30) / 100}'
endif
- exe mods .. 'lopen'
+ exe $'{mods} lopen'
if !opt.lspOptions.keepFocusInReferences
save_winid->win_gotoid()
endif
if lspserver.peekSymbol
# open the definition/declaration in the preview window and highlight the
# matching symbol
- exe 'pedit ' .. fname
+ exe $'pedit {fname}'
var cur_wid = win_getid()
wincmd P
var pvwbuf = bufnr()
# and 'hidden' is not set or if the current buffer is a special
# buffer, then open the buffer in a new window.
if (&modified && !&hidden) || &buftype != ''
- exe 'sbuffer ' .. bnr
+ exe $'sbuffer {bnr}'
else
- exe 'buf ' .. bnr
+ exe $'buf {bnr}'
endif
else
if (&modified && !&hidden) || &buftype != ''
# if the current buffer has unsaved changes and 'hidden' is not set,
# or if the current buffer is a special buffer, then open the file
# in a new window
- exe 'split ' .. fname
+ exe $'split {fname}'
else
- exe 'edit ' .. fname
+ exe $'edit {fname}'
endif
endif
endif
vim9script
-var util = {}
-
-if has('patch-8.2.4019')
- import './util.vim' as util_import
-
- util.WarnMsg = util_import.WarnMsg
- util.ErrMsg = util_import.ErrMsg
- util.LspUriToFile = util_import.LspUriToFile
- util.GetLineByteFromPos = util_import.GetLineByteFromPos
-else
- import {WarnMsg,
- ErrMsg,
- TraceLog,
- LspUriToFile,
- GetLineByteFromPos} from './util.vim'
-
- util.WarnMsg = WarnMsg
- util.ErrMsg = ErrMsg
- util.LspUriToFile = LspUriToFile
- util.GetLineByteFromPos = GetLineByteFromPos
-endif
+import './util.vim'
# sort the list of edit operations in the descending order of line and column
# numbers.
def ApplyTextDocumentEdit(textDocEdit: dict<any>)
var bnr: number = bufnr(util.LspUriToFile(textDocEdit.textDocument.uri))
if bnr == -1
- util.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
ApplyTextEdits(bnr, textDocEdit.edits)
if workspaceEdit->has_key('documentChanges')
for change in workspaceEdit.documentChanges
if change->has_key('kind')
- util.ErrMsg('Error: Unsupported change in workspace edit [' .. change.kind .. ']')
+ util.ErrMsg($'Error: Unsupported change in workspace edit [{change.kind}]')
else
ApplyTextDocumentEdit(change)
endif
return
endif
if stderr
- writefile(split(msg, "\n"), lsp_log_dir .. 'lsp_server.err', 'a')
+ writefile(split(msg, "\n"), $'{lsp_log_dir}lsp_server.err', 'a')
else
- writefile(split(msg, "\n"), lsp_log_dir .. 'lsp_server.out', 'a')
+ writefile(split(msg, "\n"), $'{lsp_log_dir}lsp_server.out', 'a')
endif
enddef
if !lsp_server_trace
return
endif
- writefile([], lsp_log_dir .. 'lsp_server.out')
- writefile([], lsp_log_dir .. 'lsp_server.err')
+ writefile([], $'{lsp_log_dir}lsp_server.out')
+ writefile([], $'{lsp_log_dir}lsp_server.err')
enddef
# Convert a LSP file URI (file://<absolute_path>) to a Vim file name
'\=printf("%%%02x", char2nr(submatch(1)))', 'g')
if on_windows
- uri = 'file:///' .. uri
+ uri = $'file:///{uri}'
else
- uri = 'file://' .. uri
+ uri = $'file://{uri}'
endif
return uri
*lsp.txt* Language Server Protocol (LSP) Plugin for Vim9
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
-For Vim version 8.2.2342 and above
-Last change: Sep 27, 2022
+For Vim version 9.0 and above
+Last change: Sep 29, 2022
==============================================================================
*lsp-license*
https://microsoft.github.io/language-server-protocol/
https://langserver.org/
-This plugin needs Vim version 8.2.2342 and after. You will need a language
+This plugin needs Vim version 9.0 and after. You will need a language
specific server in your system to use this plugin. Refer to the above pages
for a list of available language servers for the various programming
languages.
vim9script
-# LSP plugin for vim9
+# Language Server Protocol (LSP) plugin for vim
-if !has('patch-8.2.2342')
+# Needs Vim version 9.0 and above
+if v:version < 900
finish
endif
-# The following is needed to support both Vim 8.2.3741 (shipped with Ubuntu
-# 21.10) and the latest Vim. The Vim9 script syntax for import changed between
-# these two versions. Once offical Vim9 is out, the following can be
-# simplified.
-var opt = {}
-var lspf = {}
-if has('patch-8.2.4257')
- import '../autoload/lsp/lspoptions.vim' as lspoptions
- import '../autoload/lsp/lsp.vim'
-
- opt.LspOptionsSet = lspoptions.OptionsSet
- opt.lspOptions = lspoptions.lspOptions
- lspf.enableServerTrace = lsp.EnableServerTrace
- lspf.addServer = lsp.AddServer
- lspf.restartServer = lsp.RestartServer
- lspf.LspServerReady = lsp.ServerReady
- lspf.addFile = lsp.AddFile
- lspf.removeFile = lsp.RemoveFile
- lspf.showCurrentDiagInStatusLine = lsp.LspShowCurrentDiagInStatusLine
- lspf.showServers = lsp.ShowServers
- lspf.showServerCapabilities = lsp.ShowServerCapabilities
- lspf.setTraceServer = lsp.SetTraceServer
- lspf.gotoDefinition = lsp.GotoDefinition
- lspf.gotoDeclaration = lsp.GotoDeclaration
- lspf.gotoTypedef = lsp.GotoTypedef
- lspf.gotoImplementation = lsp.GotoImplementation
- lspf.showDiagnostics = lsp.ShowDiagnostics
- lspf.showCurrentDiag = lsp.LspShowCurrentDiag
- lspf.jumpToDiag = lsp.JumpToDiag
- lspf.diagHighlightEnable = lsp.DiagHighlightEnable
- lspf.diagHighlightDisable = lsp.DiagHighlightDisable
- lspf.showReferences = lsp.ShowReferences
- lspf.outline = lsp.Outline
- lspf.textDocFormat = lsp.TextDocFormat
- lspf.incomingCalls = lsp.IncomingCalls
- lspf.outgoingCalls = lsp.OutgoingCalls
- lspf.rename = lsp.Rename
- lspf.codeAction = lsp.CodeAction
- lspf.symbolSearch = lsp.SymbolSearch
- lspf.hover = lsp.Hover
- lspf.selectionExpand = lsp.SelectionExpand
- lspf.selectionShrink = lsp.SelectionShrink
- lspf.switchSourceHeader = lsp.SwitchSourceHeader
- lspf.foldDocument = lsp.FoldDocument
- lspf.listWorkspaceFolders = lsp.ListWorkspaceFolders
- lspf.addWorkspaceFolder = lsp.AddWorkspaceFolder
- lspf.removeWorkspaceFolder = lsp.RemoveWorkspaceFolder
-elseif has('patch-8.2.4019')
- import '../autoload/lsp/lspoptions.vim' as opt_import
- import '../autoload/lsp/lsp.vim' as lsp_import
-
- opt.LspOptionsSet = opt_import.OptionsSet
- opt.lspOptions = opt_import.lspOptions
- lspf.enableServerTrace = lsp_import.EnableServerTrace
- lspf.addServer = lsp_import.AddServer
- lspf.restartServer = lsp_import.RestartServer
- lspf.LspServerReady = lsp_import.ServerReady
- lspf.addFile = lsp_import.AddFile
- lspf.removeFile = lsp_import.RemoveFile
- lspf.showCurrentDiagInStatusLine = lsp_import.LspShowCurrentDiagInStatusLine
- lspf.showServers = lsp_import.ShowServers
- lspf.showServerCapabilities = lsp_import.ShowServerCapabilities
- lspf.setTraceServer = lsp_import.SetTraceServer
- lspf.gotoDefinition = lsp_import.GotoDefinition
- lspf.gotoDeclaration = lsp_import.GotoDeclaration
- lspf.gotoTypedef = lsp_import.GotoTypedef
- lspf.gotoImplementation = lsp_import.GotoImplementation
- lspf.showDiagnostics = lsp_import.ShowDiagnostics
- lspf.showCurrentDiag = lsp_import.LspShowCurrentDiag
- lspf.jumpToDiag = lsp_import.JumpToDiag
- lspf.diagHighlightEnable = lsp_import.DiagHighlightEnable
- lspf.diagHighlightDisable = lsp_import.DiagHighlightDisable
- lspf.showReferences = lsp_import.ShowReferences
- lspf.outline = lsp_import.Outline
- lspf.textDocFormat = lsp_import.TextDocFormat
- lspf.incomingCalls = lsp_import.IncomingCalls
- lspf.outgoingCalls = lsp_import.OutgoingCalls
- lspf.rename = lsp_import.Rename
- lspf.codeAction = lsp_import.CodeAction
- lspf.symbolSearch = lsp_import.SymbolSearch
- lspf.hover = lsp_import.Hover
- lspf.selectionExpand = lsp_import.SelectionExpand
- lspf.selectionShrink = lsp_import.SelectionShrink
- lspf.switchSourceHeader = lsp_import.SwitchSourceHeader
- lspf.foldDocument = lsp_import.FoldDocument
- lspf.listWorkspaceFolders = lsp_import.ListWorkspaceFolders
- lspf.addWorkspaceFolder = lsp_import.AddWorkspaceFolder
- lspf.removeWorkspaceFolder = lsp_import.RemoveWorkspaceFolder
-else
- import {lspOptions, OptionsSet} from '../autoload/lsp/lspoptions.vim'
- import {EnableServerTrace,
- AddServer,
- RestartServer,
- ServerReady,
- AddFile,
- RemoveFile,
- LspShowCurrentDiagInStatusLine,
- ShowServers,
- ShowServerCapabilities,
- SetTraceServer,
- GotoDefinition,
- GotoDeclaration,
- GotoTypedef,
- GotoImplementation,
- ShowDiagnostics,
- LspShowCurrentDiag,
- JumpToDiag,
- DiagHighlightEnable,
- DiagHighlightDisable,
- ShowReferences,
- Outline,
- TextDocFormat,
- IncomingCalls,
- OutgoingCalls,
- Rename,
- CodeAction,
- SymbolSearch,
- Hover,
- SelectionExpand,
- SelectionShrink,
- SwitchSourceHeader,
- FoldDocument,
- ListWorkspaceFolders,
- AddWorkspaceFolder,
- RemoveWorkspaceFolder} from '../autoload/lsp/lsp.vim'
-
- opt.LspOptionsSet = OptionsSet
- opt.lspOptions = lspOptions
- lspf.enableServerTrace = EnableServerTrace
- lspf.addServer = AddServer
- lspf.restartServer = RestartServer
- lspf.LspServerReady = ServerReady
- lspf.addFile = AddFile
- lspf.removeFile = RemoveFile
- lspf.showCurrentDiagInStatusLine = LspShowCurrentDiagInStatusLine
- lspf.showServers = ShowServers
- lspf.showServerCapabilities = ShowServerCapabilities
- lspf.setTraceServer = SetTraceServer
- lspf.gotoDefinition = GotoDefinition
- lspf.gotoDeclaration = GotoDeclaration
- lspf.gotoTypedef = GotoTypedef
- lspf.gotoImplementation = GotoImplementation
- lspf.gotoDefinition = GotoDefinition
- lspf.gotoDeclaration = GotoDeclaration
- lspf.gotoTypedef = GotoTypedef
- lspf.gotoImplementation = GotoImplementation
- lspf.showDiagnostics = ShowDiagnostics
- lspf.showCurrentDiag = LspShowCurrentDiag
- lspf.jumpToDiag = JumpToDiag
- lspf.diagHighlightEnable = DiagHighlightEnable
- lspf.diagHighlightDisable = DiagHighlightDisable
- lspf.showReferences = ShowReferences
- lspf.showReferences = ShowReferences
- lspf.outline = Outline
- lspf.textDocFormat = TextDocFormat
- lspf.incomingCalls = IncomingCalls
- lspf.outgoingCalls = OutgoingCalls
- lspf.rename = Rename
- lspf.codeAction = CodeAction
- lspf.symbolSearch = SymbolSearch
- lspf.hover = Hover
- lspf.selectionExpand = SelectionExpand
- lspf.selectionShrink = SelectionShrink
- lspf.switchSourceHeader = SwitchSourceHeader
- lspf.foldDocument = FoldDocument
- lspf.listWorkspaceFolders = ListWorkspaceFolders
- lspf.addWorkspaceFolder = AddWorkspaceFolder
- lspf.removeWorkspaceFolder = RemoveWorkspaceFolder
-endif
+import autoload '../autoload/lsp/lspoptions.vim'
+import autoload '../autoload/lsp/lsp.vim'
def g:LspOptionsSet(opts: dict<any>)
- opt.LspOptionsSet(opts)
+ lspoptions.OptionsSet(opts)
enddef
def g:LspServerTraceEnable()
- lspf.enableServerTrace()
+ lsp.EnableServerTrace()
enddef
def g:LspAddServer(serverList: list<dict<any>>)
- lspf.addServer(serverList)
+ lsp.AddServer(serverList)
enddef
def g:LspServerReady(): bool
- return lspf.LspServerReady()
+ return lsp.ServerReady()
enddef
-var TshowServers = lspf.showServers
-var TshowServerCapabilities = lspf.showServerCapabilities
-var TrestartServer = lspf.restartServer
-var TsetTraceServer = lspf.setTraceServer
-var TaddFile = lspf.addFile
-var TremoveFile = lspf.removeFile
-var TshowCurrentDiagInStatusLine = lspf.showCurrentDiagInStatusLine
-var TgotoDefinition = lspf.gotoDefinition
-var TgotoDeclaration = lspf.gotoDeclaration
-var TgotoTypedef = lspf.gotoTypedef
-var TgotoImplementation = lspf.gotoImplementation
-var TshowDiagnostics = lspf.showDiagnostics
-var TshowCurrentDiag = lspf.showCurrentDiag
-var TjumpToDiag = lspf.jumpToDiag
-var TdiagHighlightEnable = lspf.diagHighlightEnable
-var TdiagHighlightDisable = lspf.diagHighlightDisable
-var TshowReferences = lspf.showReferences
-var Toutline = lspf.outline
-var TtextDocFormat = lspf.textDocFormat
-var TincomingCalls = lspf.incomingCalls
-var ToutgoingCalls = lspf.outgoingCalls
-var Trename = lspf.rename
-var TcodeAction = lspf.codeAction
-var TsymbolSearch = lspf.symbolSearch
-var Thover = lspf.hover
-var TselectionExpand = lspf.selectionExpand
-var TselectionShrink = lspf.selectionShrink
-var TswitchSourceHeader = lspf.switchSourceHeader
-var TfoldDocument = lspf.foldDocument
-var TlistWorkspaceFolders = lspf.listWorkspaceFolders
-var TaddWorkspaceFolder = lspf.addWorkspaceFolder
-var TremoveWorkspaceFolder = lspf.removeWorkspaceFolder
-
augroup LSPAutoCmds
au!
- autocmd BufNewFile,BufReadPost * TaddFile(expand('<abuf>')->str2nr())
+ autocmd BufNewFile,BufReadPost * lsp.AddFile(expand('<abuf>')->str2nr())
# Note that when BufWipeOut is invoked, the current buffer may be different
# from the buffer getting wiped out.
- autocmd BufWipeOut * TremoveFile(expand('<abuf>')->str2nr())
- if opt.lspOptions.showDiagOnStatusLine
- autocmd CursorMoved * TshowCurrentDiagInStatusLine()
+ autocmd BufWipeOut * lsp.RemoveFile(expand('<abuf>')->str2nr())
+ if lspoptions.lspOptions.showDiagOnStatusLine
+ autocmd CursorMoved * lsp.LspShowCurrentDiagInStatusLine()
endif
augroup END
# TODO: Is it needed to shutdown all the LSP servers when exiting Vim?
# This takes some time.
-# autocmd VimLeavePre * call TstopAllServers()
+# autocmd VimLeavePre * call lsp.StopAllServers()
# LSP commands
-command! -nargs=0 -bar LspShowServers call TshowServers()
-command! -nargs=0 -bar LspShowServerCapabilities call TshowServerCapabilities()
-command! -nargs=0 -bar LspServerRestart call TrestartServer()
-command! -nargs=1 -bar LspSetTrace call TsetTraceServer(<q-args>)
-command! -nargs=0 -bar LspGotoDefinition call TgotoDefinition(v:false)
-command! -nargs=0 -bar LspGotoDeclaration call TgotoDeclaration(v:false)
-command! -nargs=0 -bar LspGotoTypeDef call TgotoTypedef(v:false)
-command! -nargs=0 -bar LspGotoImpl call TgotoImplementation(v:false)
-command! -nargs=0 -bar LspPeekDefinition call TgotoDefinition(v:true)
-command! -nargs=0 -bar LspPeekDeclaration call TgotoDeclaration(v:true)
-command! -nargs=0 -bar LspPeekTypeDef call TgotoTypedef(v:true)
-command! -nargs=0 -bar LspPeekImpl call TgotoImplementation(v:true)
+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=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)
+command! -nargs=0 -bar LspGotoImpl lsp.GotoImplementation(v:false)
+command! -nargs=0 -bar LspPeekDefinition lsp.GotoDefinition(v:true)
+command! -nargs=0 -bar LspPeekDeclaration lsp.GotoDeclaration(v:true)
+command! -nargs=0 -bar LspPeekTypeDef lsp.GotoTypedef(v:true)
+command! -nargs=0 -bar LspPeekImpl lsp.GotoImplementation(v:true)
command! -nargs=0 -bar LspShowSignature call LspShowSignature()
-command! -nargs=0 -bar LspDiagShow call TshowDiagnostics()
-command! -nargs=0 -bar LspDiagCurrent call TshowCurrentDiag()
-command! -nargs=0 -bar LspDiagFirst call TjumpToDiag('first')
-command! -nargs=0 -bar LspDiagNext call TjumpToDiag('next')
-command! -nargs=0 -bar LspDiagPrev call TjumpToDiag('prev')
-command! -nargs=0 -bar LspDiagHighlightEnable call TdiagHighlightEnable()
-command! -nargs=0 -bar LspDiagHighlightDisable call TdiagHighlightDisable()
-command! -nargs=0 -bar LspShowReferences call TshowReferences(v:false)
-command! -nargs=0 -bar LspPeekReferences call TshowReferences(v:true)
+command! -nargs=0 -bar LspDiagShow lsp.ShowDiagnostics()
+command! -nargs=0 -bar LspDiagCurrent lsp.LspShowCurrentDiag()
+command! -nargs=0 -bar LspDiagFirst lsp.JumpToDiag('first')
+command! -nargs=0 -bar LspDiagNext lsp.JumpToDiag('next')
+command! -nargs=0 -bar LspDiagPrev lsp.JumpToDiag('prev')
+command! -nargs=0 -bar LspDiagHighlightEnable lsp.DiagHighlightEnable()
+command! -nargs=0 -bar LspDiagHighlightDisable lsp.DiagHighlightDisable()
+command! -nargs=0 -bar LspShowReferences lsp.ShowReferences(v:false)
+command! -nargs=0 -bar LspPeekReferences lsp.ShowReferences(v:true)
# Clangd specifc extension to switch from one C/C++ source file to a
# corresponding header file
-command! -nargs=0 -bar LspSwitchSourceHeader call TswitchSourceHeader()
+command! -nargs=0 -bar LspSwitchSourceHeader lsp.SwitchSourceHeader()
command! -nargs=0 -bar LspHighlight call LspDocHighlight()
command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear()
-command! -nargs=0 -bar LspOutline call Toutline()
-command! -nargs=0 -bar -range=% LspFormat call TtextDocFormat(<range>, <line1>, <line2>)
-command! -nargs=0 -bar LspOutgoingCalls call ToutgoingCalls()
-command! -nargs=0 -bar LspIncomingCalls call TincomingCalls()
-command! -nargs=0 -bar LspRename call Trename()
-command! -nargs=0 -bar LspCodeAction call TcodeAction()
-command! -nargs=? -bar LspSymbolSearch call TsymbolSearch(<q-args>)
-command! -nargs=0 -bar LspHover call Thover()
-command! -nargs=0 -bar LspSelectionExpand call TselectionExpand()
-command! -nargs=0 -bar LspSelectionShrink call TselectionShrink()
-command! -nargs=0 -bar LspFold call TfoldDocument()
-command! -nargs=0 -bar LspWorkspaceListFolders call TlistWorkspaceFolders()
-command! -nargs=1 -bar -complete=dir LspWorkspaceAddFolder call TaddWorkspaceFolder(<q-args>)
-command! -nargs=1 -bar -complete=dir LspWorkspaceRemoveFolder call TremoveWorkspaceFolder(<q-args>)
+command! -nargs=0 -bar LspOutline lsp.Outline()
+command! -nargs=0 -bar -range=% LspFormat lsp.TextDocFormat(<range>, <line1>, <line2>)
+command! -nargs=0 -bar LspOutgoingCalls lsp.OutgoingCalls()
+command! -nargs=0 -bar LspIncomingCalls lsp.IncomingCalls()
+command! -nargs=0 -bar LspRename lsp.Rename()
+command! -nargs=0 -bar LspCodeAction lsp.CodeAction()
+command! -nargs=? -bar LspSymbolSearch lsp.SymbolSearch(<q-args>)
+command! -nargs=0 -bar LspHover lsp.Hover()
+command! -nargs=0 -bar LspSelectionExpand lsp.SelectionExpand()
+command! -nargs=0 -bar LspSelectionShrink lsp.SelectionShrink()
+command! -nargs=0 -bar LspFold lsp.FoldDocument()
+command! -nargs=0 -bar LspWorkspaceListFolders lsp.ListWorkspaceFolders()
+command! -nargs=1 -bar -complete=dir LspWorkspaceAddFolder lsp.AddWorkspaceFolder(<q-args>)
+command! -nargs=1 -bar -complete=dir LspWorkspaceRemoveFolder lsp.RemoveWorkspaceFolder(<q-args>)
# Add the GUI menu entries
if has('gui_running')
:LspHighlight
var expected: dict<any>
expected = {id: 0, col: 13, end: 1, type: 'LspTextRef', length: 3, start: 1}
- if has('patch-8.2.3233')
- expected.type_bufnr = 0
- endif
+ expected.type_bufnr = 0
assert_equal([expected], prop_list(1))
expected = {id: 0, col: 11, end: 1, type: 'LspReadRef', length: 3, start: 1}
- if has('patch-8.2.3233')
- expected.type_bufnr = 0
- endif
+ expected.type_bufnr = 0
assert_equal([expected], prop_list(3))
expected = {id: 0, col: 3, end: 1, type: 'LspWriteRef', length: 3, start: 1}
- if has('patch-8.2.3233')
- expected.type_bufnr = 0
- endif
+ expected.type_bufnr = 0
assert_equal([expected], prop_list(4))
:LspHighlightClear
assert_equal([], prop_list(1))
assert_equal(['MyFunc(int a, int b) -> int'], getbufline(bnr, 1, '$'))
var expected: dict<any>
expected = {id: 0, col: 8, end: 1, type: 'signature', length: 5, start: 1}
- if has('patch-8.2.3233')
- expected.type_bufnr = bnr
- endif
+ expected.type_bufnr = bnr
assert_equal([expected], prop_list(1, {bufnr: bnr}))
popup_close(p[0])
assert_equal(1, p->len())
assert_equal(['MyFunc(int a, int b) -> int'], getbufline(bnr, 1, '$'))
expected = {id: 0, col: 15, end: 1, type: 'signature', length: 5, start: 1}
- if has('patch-8.2.3233')
- expected.type_bufnr = bnr
- endif
+ expected.type_bufnr = bnr
assert_equal([expected], prop_list(1, {bufnr: bnr}))
popup_close(p[0])
:%bw!