From 67bd20bda3e2c4d2c6814bc3dbea90dcf3a3e867 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Thu, 29 Sep 2022 18:55:10 -0700 Subject: [PATCH] Bump up the minimum required Vim version to 9.0 and cleanup the code --- .github/workflows/unitests.yml | 2 +- README.md | 2 +- autoload/lsp/callhierarchy.vim | 25 +-- autoload/lsp/codeaction.vim | 18 +- autoload/lsp/diag.vim | 32 +--- autoload/lsp/handlers.vim | 135 ++++----------- autoload/lsp/lsp.vim | 154 ++++------------- autoload/lsp/lspserver.vim | 70 ++------ autoload/lsp/outline.vim | 28 +-- autoload/lsp/selection.vim | 11 +- autoload/lsp/signature.vim | 27 +-- autoload/lsp/symbol.vim | 49 ++---- autoload/lsp/textedit.vim | 26 +-- autoload/lsp/util.vim | 12 +- doc/lsp.txt | 6 +- plugin/lsp.vim | 299 ++++++--------------------------- test/unit_tests.vim | 20 +-- 17 files changed, 182 insertions(+), 734 deletions(-) diff --git a/.github/workflows/unitests.yml b/.github/workflows/unitests.yml index 71c04dd..1009b0a 100644 --- a/.github/workflows/unitests.yml +++ b/.github/workflows/unitests.yml @@ -12,7 +12,7 @@ jobs: 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 diff --git a/README.md b/README.md index ce5bf9b..7fa2bc8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![unit-tests](https://github.com/yegappan/mru/workflows/unit-tests/badge.svg?branch=master) -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 diff --git a/autoload/lsp/callhierarchy.vim b/autoload/lsp/callhierarchy.vim index 1cd76b6..75508e2 100644 --- a/autoload/lsp/callhierarchy.vim +++ b/autoload/lsp/callhierarchy.vim @@ -2,22 +2,7 @@ vim9script # 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>, incoming: bool) var qflist: list> = [] @@ -51,15 +36,15 @@ def CreateLoclistWithCalls(calls: list>, incoming: bool) 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 = 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() diff --git a/autoload/lsp/codeaction.vim b/autoload/lsp/codeaction.vim index e7e838f..6306834 100644 --- a/autoload/lsp/codeaction.vim +++ b/autoload/lsp/codeaction.vim @@ -2,22 +2,8 @@ vim9script # 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, actions: list>): void if actions->empty() diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index d4d1284..e7696e4 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -2,28 +2,8 @@ vim9script # 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, bnr: number) @@ -115,7 +95,7 @@ export def DiagNotification(lspserver: dict, uri: string, diags: listextend({['' .. bnr]: diag_by_lnum}) + lspserver.diagsMap->extend({[$'{bnr}']: diag_by_lnum}) ProcessNewDiags(lspserver, bnr) enddef @@ -204,7 +184,7 @@ enddef # in a location list export def ShowAllDiags(lspserver: dict): void if !DiagsUpdateLocList(lspserver, bufnr()) - util.WarnMsg('No diagnostic messages found for ' .. @%) + util.WarnMsg($'No diagnostic messages found for {@%}') return endif @@ -233,7 +213,7 @@ export def ShowCurrentDiagInStatusLine(lspserver: dict) 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] @@ -268,7 +248,7 @@ export def LspDiagsJump(lspserver: dict, which: string): void 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 diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim index ec37783..50dac81 100644 --- a/autoload/lsp/handlers.vim +++ b/autoload/lsp/handlers.vim @@ -4,82 +4,16 @@ vim9script # 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 @@ -156,9 +90,9 @@ def ProcessSwitchHeaderReply(lspserver: dict, req: dict, reply: dict, req: dict, reply: dict): v 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 @@ -341,7 +275,7 @@ def ProcessHoverReply(lspserver: dict, req: dict, reply: dict): v 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 @@ -349,7 +283,7 @@ def ProcessHoverReply(lspserver: dict, req: dict, reply: dict): v 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) @@ -432,7 +366,7 @@ def ProcessSymbolInfoTable(symbolInfoTable: list>, name = symbol.name if symbol->has_key('containerName') if symbol.containerName != '' - name ..= ' [' .. symbol.containerName .. ']' + name ..= $' [{symbol.containerName}]' endif endif r = symbol.location.range @@ -583,7 +517,7 @@ def ProcessFoldingRangeReply(lspserver: dict, req: dict, reply: dict, req: dict, reply: dic 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) @@ -750,7 +684,7 @@ export def ProcessReply(lspserver: dict, req: dict, reply: dict): 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 @@ -778,7 +712,7 @@ def ProcessShowMsgNotif(lspserver: dict, reply: dict) 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 @@ -791,12 +725,12 @@ def ProcessLogMsgNotif(lspserver: dict, reply: dict) 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, reply: dict) - 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 @@ -830,7 +764,7 @@ export def ProcessNotif(lspserver: dict, reply: dict): void 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 @@ -844,7 +778,7 @@ def ProcessApplyEditReq(lspserver: dict, request: dict) endif var workspaceEditParams: dict = 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 @@ -873,7 +807,7 @@ def ProcessClientUnregisterCap(lspserver: dict, request: dict) enddef def ProcessUnsupportedReq(lspserver: dict, request: dict) - 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 @@ -893,7 +827,7 @@ export def ProcessRequest(lspserver: dict, request: dict) 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 @@ -944,7 +878,7 @@ export def ProcessMessages(lspserver: dict): void 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 @@ -961,12 +895,11 @@ export def ProcessMessages(lspserver: dict): void 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') @@ -976,7 +909,7 @@ export def ProcessMessages(lspserver: dict): void # 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 :] diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index e2398cd..662f32d 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -2,113 +2,19 @@ vim9script # 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> = [] @@ -155,15 +61,15 @@ def CurbufGetServerChecked(): dict var lspserver: dict = 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 @@ -200,7 +106,7 @@ export def ShowServers() else msg ..= 'not running' endif - msg ..= ' ' .. lspserver.path + msg ..= $' {lspserver.path}' :echomsg msg endfor enddef @@ -387,22 +293,21 @@ export def AddFile(bnr: number): void # Set buffer local autocmds augroup LSPBufferAutocmds # file saved notification handler - exe 'autocmd BufWritePost call LspSavedFile()' + exe $'autocmd BufWritePost call LspSavedFile()' if opt.lspOptions.autoComplete # Trigger 24x7 insert mode completion when text is changed - exe 'autocmd TextChangedI call LspComplete()' + exe $'autocmd TextChangedI call LspComplete()' endif # Update the diagnostics when insert mode is stopped - exe 'autocmd InsertLeave call LspLeftInsertMode()' + exe $'autocmd InsertLeave 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 ' - .. 'call LspDocHighlightClear() | call LspDocHighlight()' + exe $'autocmd CursorMoved call LspDocHighlightClear() | call LspDocHighlight()' endif augroup END @@ -454,7 +359,7 @@ export def RestartServer() 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}) @@ -478,14 +383,14 @@ export def AddServer(serverList: list>) 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 = [] 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 @@ -496,14 +401,14 @@ export def AddServer(serverList: list>) var initializationOptions: dict = {} 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 @@ -525,8 +430,7 @@ export def AddServer(serverList: list>) 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 @@ -551,7 +455,7 @@ enddef # 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 @@ -843,7 +747,7 @@ export def Rename() endif var sym: string = expand('') - var newName: string = input("Rename symbol '" .. sym .. "' to: ", sym) + var newName: string = input($"Rename symbol '{sym}' to: ", sym) if newName == '' return endif @@ -894,7 +798,7 @@ export def ListWorkspaceFolders() 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. @@ -913,7 +817,7 @@ export def AddWorkspaceFolder(dirArg: string) endif :redraw! if !dirName->isdirectory() - util.ErrMsg('Error: ' .. dirName .. ' is not a directory') + util.ErrMsg($'Error: {dirName} is not a directory') return endif @@ -936,7 +840,7 @@ export def RemoveWorkspaceFolder(dirArg: string) endif :redraw! if !dirName->isdirectory() - util.ErrMsg('Error: ' .. dirName .. ' is not a directory') + util.ErrMsg($'Error: {dirName} is not a directory') return endif diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 13436af..5d32d86 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -4,56 +4,10 @@ vim9script # 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, chan: channel, msg: string): void @@ -69,7 +23,7 @@ enddef # LSP server exit callback def Exit_cb(lspserver: dict, 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 = {} @@ -79,7 +33,7 @@ enddef # def StartServer(lspserver: dict): number if lspserver.running - util.WarnMsg("LSP server for is already running") + util.WarnMsg('LSP server for is already running') return 0 endif @@ -105,7 +59,7 @@ def StartServer(lspserver: dict): number 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 @@ -298,7 +252,7 @@ enddef # Send a request message to LSP server def SendMessage(lspserver: dict, content: dict): 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 @@ -888,7 +842,7 @@ def AddWorkspaceFolder(lspserver: dict, dirName: string): void 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 @@ -915,7 +869,7 @@ def RemoveWorkspaceFolder(lspserver: dict, dirName: string): void 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 @@ -1013,9 +967,9 @@ enddef # Display the LSP server capabilities (received during the initialization # stage). def ShowCapabilities(lspserver: dict) - 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 diff --git a/autoload/lsp/outline.vim b/autoload/lsp/outline.vim index d66c676..5be07bb 100644 --- a/autoload/lsp/outline.vim +++ b/autoload/lsp/outline.vim @@ -1,19 +1,7 @@ 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() @@ -54,7 +42,7 @@ def OutlineJumpToSymbol() win_execute(symWinid, 'vertical resize 20') endif - exe 'edit ' .. fname + exe $'edit {fname}' else wid->win_gotoid() endif @@ -131,8 +119,7 @@ export def UpdateOutlineWindow(fname: string, :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> = [{}, {}] @@ -217,8 +204,7 @@ def OutlineHighlightCurrentSymbol() 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 @@ -241,9 +227,9 @@ export def OpenOutlineWindow() 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 diff --git a/autoload/lsp/selection.vim b/autoload/lsp/selection.vim index 222b385..0996c0e 100644 --- a/autoload/lsp/selection.vim +++ b/autoload/lsp/selection.vim @@ -2,16 +2,7 @@ vim9script # 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>) diff --git a/autoload/lsp/signature.vim b/autoload/lsp/signature.vim index c78b0c3..60887ff 100644 --- a/autoload/lsp/signature.vim +++ b/autoload/lsp/signature.vim @@ -2,27 +2,9 @@ vim9script # 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) @@ -49,8 +31,7 @@ export def SignatureInit(lspserver: dict) # map characters that trigger signature help for ch in lspserver.caps.signatureHelpProvider.triggerCharacters - exe 'inoremap ' .. ch .. ' ' .. ch - .. "=LspShowSignature()" + exe $"inoremap {ch} {ch}=LspShowSignature()" endfor # close the signature popup when leaving insert mode autocmd InsertLeave call CloseCurBufSignaturePopup() diff --git a/autoload/lsp/symbol.vim b/autoload/lsp/symbol.vim index f61d650..765714a 100644 --- a/autoload/lsp/symbol.vim +++ b/autoload/lsp/symbol.vim @@ -6,31 +6,8 @@ vim9script # - 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, popupID: number, key: string): bool @@ -80,7 +57,7 @@ def FilterSymbols(lspserver: dict, popupID: number, key: string): bool else []->setwinvar(popupID, 'LspSymbolTable') endif - echo 'Symbol: ' .. query + echo $'Symbol: {query}' endif # Update the workspace symbol query string @@ -119,9 +96,9 @@ def JumpToWorkspaceSymbol(popupID: number, result: number): void 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() @@ -158,7 +135,7 @@ export def ShowSymbolMenu(lspserver: dict, query: string) 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 @@ -199,9 +176,9 @@ export def ShowReferences(lspserver: dict, refs: 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 @@ -240,7 +217,7 @@ export def GotoSymbol(lspserver: dict, location: dict, type: string) 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() @@ -268,18 +245,18 @@ export def GotoSymbol(lspserver: dict, location: dict, type: string) # 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 diff --git a/autoload/lsp/textedit.vim b/autoload/lsp/textedit.vim index b57addc..7fb2037 100644 --- a/autoload/lsp/textedit.vim +++ b/autoload/lsp/textedit.vim @@ -1,26 +1,6 @@ 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. @@ -205,7 +185,7 @@ enddef def ApplyTextDocumentEdit(textDocEdit: dict) 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) @@ -216,7 +196,7 @@ export def ApplyWorkspaceEdit(workspaceEdit: dict) 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 diff --git a/autoload/lsp/util.vim b/autoload/lsp/util.vim index fe478ed..65d15d4 100644 --- a/autoload/lsp/util.vim +++ b/autoload/lsp/util.vim @@ -35,9 +35,9 @@ export def TraceLog(stderr: bool, msg: string) 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 @@ -46,8 +46,8 @@ export def ClearTraceLogs() 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://) to a Vim file name @@ -93,9 +93,9 @@ def ConvertFilenameToUri(fname: string): string '\=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 diff --git a/doc/lsp.txt b/doc/lsp.txt index 2678fe1..99cb875 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -1,8 +1,8 @@ *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* @@ -35,7 +35,7 @@ Refer to the following pages for more information about LSP: 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. diff --git a/plugin/lsp.vim b/plugin/lsp.vim index dd3f79e..5b54be1 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -1,287 +1,88 @@ 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) - opt.LspOptionsSet(opts) + lspoptions.OptionsSet(opts) enddef def g:LspServerTraceEnable() - lspf.enableServerTrace() + lsp.EnableServerTrace() enddef def g:LspAddServer(serverList: list>) - 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('')->str2nr()) + autocmd BufNewFile,BufReadPost * lsp.AddFile(expand('')->str2nr()) # Note that when BufWipeOut is invoked, the current buffer may be different # from the buffer getting wiped out. - autocmd BufWipeOut * TremoveFile(expand('')->str2nr()) - if opt.lspOptions.showDiagOnStatusLine - autocmd CursorMoved * TshowCurrentDiagInStatusLine() + autocmd BufWipeOut * lsp.RemoveFile(expand('')->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() -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() +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(, , ) -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() -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() -command! -nargs=1 -bar -complete=dir LspWorkspaceRemoveFolder call TremoveWorkspaceFolder() +command! -nargs=0 -bar LspOutline lsp.Outline() +command! -nargs=0 -bar -range=% LspFormat lsp.TextDocFormat(, , ) +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() +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() +command! -nargs=1 -bar -complete=dir LspWorkspaceRemoveFolder lsp.RemoveWorkspaceFolder() # Add the GUI menu entries if has('gui_running') diff --git a/test/unit_tests.vim b/test/unit_tests.vim index 62d9fc5..cf5fb77 100644 --- a/test/unit_tests.vim +++ b/test/unit_tests.vim @@ -585,19 +585,13 @@ def Test_LspHighlight() :LspHighlight var expected: dict 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)) @@ -660,9 +654,7 @@ def Test_LspShowSignature() assert_equal(['MyFunc(int a, int b) -> int'], getbufline(bnr, 1, '$')) var expected: dict 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]) @@ -674,9 +666,7 @@ def Test_LspShowSignature() 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! -- 2.48.1