From: Yegappan Lakshmanan Date: Tue, 8 Feb 2022 04:42:40 +0000 (-0800) Subject: Change the script-local function names to start with an uppercase letter. Remove... X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=4bbddf9bf9ad42ff9f602483972bc47972061542;p=vim-lsp.git Change the script-local function names to start with an uppercase letter. Remove redundant funcref initialization. --- diff --git a/autoload/buffer.vim b/autoload/buffer.vim index 1b50403..d7fb5ba 100644 --- a/autoload/buffer.vim +++ b/autoload/buffer.vim @@ -28,3 +28,5 @@ enddef export def BufHasLspServer(bnr: number): bool return bufnrToServer->has_key(bnr) enddef + +# vim: shiftwidth=2 softtabstop=2 diff --git a/autoload/callhierarchy.vim b/autoload/callhierarchy.vim index 9d20dd7..9ccc71a 100644 --- a/autoload/callhierarchy.vim +++ b/autoload/callhierarchy.vim @@ -19,7 +19,7 @@ else util.GetLineByteFromPos = GetLineByteFromPos endif -def s:createLoclistWithCalls(calls: list>, incoming: bool) +def s:CreateLoclistWithCalls(calls: list>, incoming: bool) var qflist: list> = [] for item in calls @@ -74,7 +74,7 @@ export def IncomingCalls(calls: list>) return endif - s:createLoclistWithCalls(calls, true) + s:CreateLoclistWithCalls(calls, true) enddef export def OutgoingCalls(calls: list>) @@ -83,7 +83,7 @@ export def OutgoingCalls(calls: list>) return endif - s:createLoclistWithCalls(calls, false) + s:CreateLoclistWithCalls(calls, false) enddef # vim: shiftwidth=2 softtabstop=2 diff --git a/autoload/diag.vim b/autoload/diag.vim index e5a5b00..9780cd9 100644 --- a/autoload/diag.vim +++ b/autoload/diag.vim @@ -32,7 +32,7 @@ export def DiagRemoveFile(lspserver: dict, bnr: number) endif enddef -def s:lspDiagSevToSignName(severity: number): string +def s:DiagSevToSignName(severity: number): string var typeMap: list = ['LspDiagError', 'LspDiagWarning', 'LspDiagInfo', 'LspDiagHint'] if severity > 4 @@ -71,7 +71,7 @@ def ProcessNewDiags(lspserver: dict, bnr: number) for [lnum, diag] in lspserver.diagsMap[bnr]->items() signs->add({id: 0, buffer: bnr, group: 'LSPDiag', lnum: str2nr(lnum), - name: s:lspDiagSevToSignName(diag.severity)}) + name: s:DiagSevToSignName(diag.severity)}) endfor signs->sign_placelist() @@ -140,7 +140,7 @@ export def DiagsGetErrorCount(lspserver: dict): dict enddef # Map the LSP DiagnosticSeverity to a quickfix type character -def s:lspDiagSevToQfType(severity: number): string +def s:DiagSevToQfType(severity: number): string var typeMap: list = ['E', 'W', 'I', 'N'] if severity > 4 @@ -173,7 +173,7 @@ export def ShowAllDiags(lspserver: dict): void 'lnum': diag.range.start.line + 1, 'col': util.GetLineByteFromPos(bnr, diag.range.start) + 1, 'text': text, - 'type': s:lspDiagSevToQfType(diag.severity)}) + 'type': s:DiagSevToQfType(diag.severity)}) endfor setloclist(0, [], ' ', {'title': 'Language Server Diagnostics', 'items': qflist}) @@ -221,7 +221,7 @@ export def GetDiagByLine(lspserver: dict, bnr: number, lnum: number): dict< enddef # sort the diaganostics messages for a buffer by line number -def s:getSortedDiagLines(lspsrv: dict, bnr: number): list +def s:GetSortedDiagLines(lspsrv: dict, bnr: number): list # create a list of line numbers from the diag map keys var lnums: list = lspsrv.diagsMap[bnr]->keys()->mapnew((_, v) => v->str2nr()) @@ -242,7 +242,7 @@ export def LspDiagsJump(lspserver: dict, which: string): void endif # sort the diagnostics by line number - var sortedDiags: list = s:getSortedDiagLines(lspserver, bnr) + var sortedDiags: list = s:GetSortedDiagLines(lspserver, bnr) if which == 'first' cursor(sortedDiags[0], 1) diff --git a/autoload/handlers.vim b/autoload/handlers.vim index 48965fd..f073f31 100644 --- a/autoload/handlers.vim +++ b/autoload/handlers.vim @@ -83,7 +83,7 @@ endif # process the 'initialize' method reply from the LSP server # Result: InitializeResult -def s:processInitializeReply(lspserver: dict, req: dict, reply: dict): void +def s:ProcessInitializeReply(lspserver: dict, req: dict, reply: dict): void if reply.result->len() <= 0 return endif @@ -126,7 +126,7 @@ enddef # 'textDocument/typeDefinition' and 'textDocument/implementation' replies from # the LSP server # Result: Location | Location[] | LocationLink[] | null -def s:processDefDeclReply(lspserver: dict, req: dict, reply: dict): void +def s:ProcessDefDeclReply(lspserver: dict, req: dict, reply: dict): void var location: dict if reply.result->type() == v:t_list if !reply.result->empty() @@ -143,7 +143,7 @@ enddef # process the 'textDocument/signatureHelp' reply from the LSP server # Result: SignatureHelp | null -def s:processSignaturehelpReply(lspserver: dict, req: dict, reply: dict): void +def s:ProcessSignaturehelpReply(lspserver: dict, req: dict, reply: dict): void signature.SignatureDisplay(lspserver, reply.result) enddef @@ -184,7 +184,7 @@ enddef # process the 'textDocument/completion' reply from the LSP server # Result: CompletionItem[] | CompletionList | null -def s:processCompletionReply(lspserver: dict, req: dict, reply: dict): void +def s:ProcessCompletionReply(lspserver: dict, req: dict, reply: dict): void if reply.result->empty() return endif @@ -274,7 +274,7 @@ enddef # process the 'textDocument/hover' reply from the LSP server # Result: Hover | null -def s:processHoverReply(lspserver: dict, req: dict, reply: dict): void +def s:ProcessHoverReply(lspserver: dict, req: dict, reply: dict): void if reply.result->empty() return endif @@ -337,13 +337,13 @@ enddef # process the 'textDocument/references' reply from the LSP server # Result: Location[] | null -def s:processReferencesReply(lspserver: dict, req: dict, reply: dict): void +def s:ProcessReferencesReply(lspserver: dict, req: dict, reply: dict): void symbol.ShowReferences(lspserver, reply.result) enddef # process the 'textDocument/documentHighlight' reply from the LSP server # Result: DocumentHighlight[] | null -def s:processDocHighlightReply(lspserver: dict, req: dict, reply: dict): void +def s:ProcessDocHighlightReply(lspserver: dict, req: dict, reply: dict): void if reply.result->empty() return endif @@ -387,7 +387,7 @@ def LspSymbolKindToName(symkind: number): string enddef # process SymbolInformation[] -def s:processSymbolInfoTable(symbolInfoTable: list>, +def s:ProcessSymbolInfoTable(symbolInfoTable: list>, symbolTypeTable: dict>>, symbolLineTable: list>) var fname: string @@ -417,7 +417,7 @@ def s:processSymbolInfoTable(symbolInfoTable: list>, enddef # process DocumentSymbol[] -def s:processDocSymbolTable(docSymbolTable: list>, +def s:ProcessDocSymbolTable(docSymbolTable: list>, symbolTypeTable: dict>>, symbolLineTable: list>) var symbolType: string @@ -439,7 +439,7 @@ def s:processDocSymbolTable(docSymbolTable: list>, endif childSymbols = {} if symbol->has_key('children') - s:processDocSymbolTable(symbol.children, childSymbols, symbolLineTable) + s:ProcessDocSymbolTable(symbol.children, childSymbols, symbolLineTable) endif symInfo = {name: name, range: r, detail: symbolDetail, children: childSymbols} @@ -451,7 +451,7 @@ enddef # process the 'textDocument/documentSymbol' reply from the LSP server # Open a symbols window and display the symbols as a tree # Result: DocumentSymbol[] | SymbolInformation[] | null -def s:processDocSymbolReply(lspserver: dict, req: dict, reply: dict): void +def s:ProcessDocSymbolReply(lspserver: dict, req: dict, reply: dict): void var fname: string var symbolTypeTable: dict>> = {} var symbolLineTable: list> = [] @@ -468,10 +468,10 @@ def s:processDocSymbolReply(lspserver: dict, req: dict, reply: dicthas_key('location') # SymbolInformation[] - s:processSymbolInfoTable(reply.result, symbolTypeTable, symbolLineTable) + s:ProcessSymbolInfoTable(reply.result, symbolTypeTable, symbolLineTable) else # DocumentSymbol[] - s:processDocSymbolTable(reply.result, symbolTypeTable, symbolLineTable) + s:ProcessDocSymbolTable(reply.result, symbolTypeTable, symbolLineTable) endif # sort the symbols by line number @@ -481,7 +481,7 @@ enddef # process the 'textDocument/formatting' reply from the LSP server # Result: TextEdit[] | null -def s:processFormatReply(lspserver: dict, req: dict, reply: dict) +def s:ProcessFormatReply(lspserver: dict, req: dict, reply: dict) if reply.result->empty() # nothing to format return @@ -506,7 +506,7 @@ enddef # Reply: 'textDocument/rename' # Result: Range | { range: Range, placeholder: string } # | { defaultBehavior: boolean } | null -def s:processRenameReply(lspserver: dict, req: dict, reply: dict) +def s:ProcessRenameReply(lspserver: dict, req: dict, reply: dict) if reply.result->empty() # nothing to rename return @@ -518,19 +518,19 @@ enddef # process the 'textDocument/codeAction' reply from the LSP server # Result: (Command | CodeAction)[] | null -def s:processCodeActionReply(lspserver: dict, req: dict, reply: dict) +def s:ProcessCodeActionReply(lspserver: dict, req: dict, reply: dict) codeaction.ApplyCodeAction(lspserver, reply.result) enddef # Reply: 'textDocument/selectionRange' # Result: SelectionRange[] | null -def s:processSelectionRangeReply(lspserver: dict, req: dict, reply: dict) +def s:ProcessSelectionRangeReply(lspserver: dict, req: dict, reply: dict) selection.SelectionStart(lspserver, reply.result) enddef # Reply: 'textDocument/foldingRange' # Result: FoldingRange[] | null -def s:processFoldingRangeReply(lspserver: dict, req: dict, reply: dict) +def s:ProcessFoldingRangeReply(lspserver: dict, req: dict, reply: dict) if reply.result->empty() return endif @@ -556,7 +556,7 @@ enddef # process the 'workspace/executeCommand' reply from the LSP server # Result: any | null -def s:processWorkspaceExecuteReply(lspserver: dict, req: dict, reply: dict) +def s:ProcessWorkspaceExecuteReply(lspserver: dict, req: dict, reply: dict) if reply.result->empty() return endif @@ -566,7 +566,7 @@ enddef # Convert a file name () format. # Make sure the popup does't occupy the entire screen by reducing the width. -def s:makeMenuName(popupWidth: number, fname: string): string +def s:MakeMenuName(popupWidth: number, fname: string): string var filename: string = fname->fnamemodify(':t') var flen: number = filename->len() var dirname: string = fname->fnamemodify(':h') @@ -587,7 +587,7 @@ enddef # process the 'workspace/symbol' reply from the LSP server # Result: SymbolInformation[] | null -def s:processWorkspaceSymbolReply(lspserver: dict, req: dict, reply: dict) +def s:ProcessWorkspaceSymbolReply(lspserver: dict, req: dict, reply: dict) var symbols: list> = [] var symbolType: string var fileName: string @@ -613,7 +613,7 @@ def s:processWorkspaceSymbolReply(lspserver: dict, req: dict, reply: d symName = symbol.containerName .. '::' .. symName endif symName ..= ' [' .. LspSymbolKindToName(symbol.kind) .. ']' - symName ..= ' ' .. s:makeMenuName( + symName ..= ' ' .. s:MakeMenuName( lspserver.workspaceSymbolPopup->popup_getpos().core_width, fileName) @@ -628,7 +628,7 @@ enddef # process the 'textDocument/prepareCallHierarchy' reply from the LSP server # Result: CallHierarchyItem[] | null -def s:processPrepareCallHierarchy(lspserver: dict, req: dict, reply: dict) +def s:ProcessPrepareCallHierarchy(lspserver: dict, req: dict, reply: dict) if reply.result->empty() if lspserver.callHierarchyType == 'incoming' util.WarnMsg('No incoming calls') @@ -659,13 +659,13 @@ enddef # process the 'callHierarchy/incomingCalls' reply from the LSP server # Result: CallHierarchyIncomingCall[] | null -def s:processIncomingCalls(lspserver: dict, req: dict, reply: dict) +def s:ProcessIncomingCalls(lspserver: dict, req: dict, reply: dict) callhier.IncomingCalls(reply.result) enddef # process the 'callHierarchy/outgoingCalls' reply from the LSP server # Result: CallHierarchyOutgoingCall[] | null -def s:processOutgoingCalls(lspserver: dict, req: dict, reply: dict) +def s:ProcessOutgoingCalls(lspserver: dict, req: dict, reply: dict) callhier.OutgoingCalls(reply.result) enddef @@ -673,28 +673,28 @@ enddef export def ProcessReply(lspserver: dict, req: dict, reply: dict): void var lsp_reply_handlers: dict = { - 'initialize': function('s:processInitializeReply'), - 'textDocument/definition': function('s:processDefDeclReply'), - 'textDocument/declaration': function('s:processDefDeclReply'), - 'textDocument/typeDefinition': function('s:processDefDeclReply'), - 'textDocument/implementation': function('s:processDefDeclReply'), - 'textDocument/signatureHelp': function('s:processSignaturehelpReply'), - 'textDocument/completion': function('s:processCompletionReply'), - 'textDocument/hover': function('s:processHoverReply'), - 'textDocument/references': function('s:processReferencesReply'), - 'textDocument/documentHighlight': function('s:processDocHighlightReply'), - 'textDocument/documentSymbol': function('s:processDocSymbolReply'), - 'textDocument/formatting': function('s:processFormatReply'), - 'textDocument/rangeFormatting': function('s:processFormatReply'), - 'textDocument/rename': function('s:processRenameReply'), - 'textDocument/codeAction': function('s:processCodeActionReply'), - 'textDocument/selectionRange': function('s:processSelectionRangeReply'), - 'textDocument/foldingRange': function('s:processFoldingRangeReply'), - 'workspace/executeCommand': function('s:processWorkspaceExecuteReply'), - 'workspace/symbol': function('s:processWorkspaceSymbolReply'), - 'textDocument/prepareCallHierarchy': function('s:processPrepareCallHierarchy'), - 'callHierarchy/incomingCalls': function('s:processIncomingCalls'), - 'callHierarchy/outgoingCalls': function('s:processOutgoingCalls') + 'initialize': function('s:ProcessInitializeReply'), + 'textDocument/definition': function('s:ProcessDefDeclReply'), + 'textDocument/declaration': function('s:ProcessDefDeclReply'), + 'textDocument/typeDefinition': function('s:ProcessDefDeclReply'), + 'textDocument/implementation': function('s:ProcessDefDeclReply'), + 'textDocument/signatureHelp': function('s:ProcessSignaturehelpReply'), + 'textDocument/completion': function('s:ProcessCompletionReply'), + 'textDocument/hover': function('s:ProcessHoverReply'), + 'textDocument/references': function('s:ProcessReferencesReply'), + 'textDocument/documentHighlight': function('s:ProcessDocHighlightReply'), + 'textDocument/documentSymbol': function('s:ProcessDocSymbolReply'), + 'textDocument/formatting': function('s:ProcessFormatReply'), + 'textDocument/rangeFormatting': function('s:ProcessFormatReply'), + 'textDocument/rename': function('s:ProcessRenameReply'), + 'textDocument/codeAction': function('s:ProcessCodeActionReply'), + 'textDocument/selectionRange': function('s:ProcessSelectionRangeReply'), + 'textDocument/foldingRange': function('s:ProcessFoldingRangeReply'), + 'workspace/executeCommand': function('s:ProcessWorkspaceExecuteReply'), + 'workspace/symbol': function('s:ProcessWorkspaceSymbolReply'), + 'textDocument/prepareCallHierarchy': function('s:ProcessPrepareCallHierarchy'), + 'callHierarchy/incomingCalls': function('s:ProcessIncomingCalls'), + 'callHierarchy/outgoingCalls': function('s:ProcessOutgoingCalls') } if lsp_reply_handlers->has_key(req.method) @@ -707,14 +707,14 @@ enddef # process a diagnostic notification message from the LSP server # Notification: textDocument/publishDiagnostics # Param: PublishDiagnosticsParams -def s:processDiagNotif(lspserver: dict, reply: dict): void +def s:ProcessDiagNotif(lspserver: dict, reply: dict): void diag.DiagNotification(lspserver, reply.params.uri, reply.params.diagnostics) enddef # process a show notification message from the LSP server # Notification: window/showMessage # Param: ShowMessageParams -def s:processShowMsgNotif(lspserver: dict, reply: dict) +def s:ProcessShowMsgNotif(lspserver: dict, reply: dict) var msgType: list = ['', 'Error: ', 'Warning: ', 'Info: ', 'Log: '] if reply.params.type == 4 # ignore log messages from the LSP server (too chatty) @@ -734,7 +734,7 @@ enddef # process a log notification message from the LSP server # Notification: window/logMessage # Param: LogMessageParams -def s:processLogMsgNotif(lspserver: dict, reply: dict) +def s:ProcessLogMsgNotif(lspserver: dict, reply: dict) var msgType: list = ['', 'Error: ', 'Warning: ', 'Info: ', 'Log: '] var mtype: string = 'Log: ' if reply.params.type > 0 && reply.params.type < 5 @@ -745,26 +745,26 @@ def s:processLogMsgNotif(lspserver: dict, reply: dict) enddef # process unsupported notification messages -def s:processUnsupportedNotif(lspserver: dict, reply: dict) +def s:ProcessUnsupportedNotif(lspserver: dict, reply: dict) util.ErrMsg('Error: Unsupported notification message received from the LSP server (' .. lspserver.path .. '), message = ' .. reply->string()) enddef # ignore unsupported notification message -def s:ignoreNotif(lspserver: dict, reply: dict) +def s:IgnoreNotif(lspserver: dict, reply: dict) enddef # process notification messages from the LSP server export def ProcessNotif(lspserver: dict, reply: dict): void var lsp_notif_handlers: dict = { - 'window/showMessage': function('s:processShowMsgNotif'), - 'window/logMessage': function('s:processLogMsgNotif'), - 'textDocument/publishDiagnostics': function('s:processDiagNotif'), - '$/progress': function('s:processUnsupportedNotif'), - 'telemetry/event': function('s:processUnsupportedNotif'), + 'window/showMessage': function('s:ProcessShowMsgNotif'), + 'window/logMessage': function('s:ProcessLogMsgNotif'), + 'textDocument/publishDiagnostics': function('s:ProcessDiagNotif'), + '$/progress': function('s:ProcessUnsupportedNotif'), + 'telemetry/event': function('s:ProcessUnsupportedNotif'), # Java language server sends the 'language/status' notification which is # not in the LSP specification - 'language/status': function('s:ignoreNotif') + 'language/status': function('s:IgnoreNotif') } if lsp_notif_handlers->has_key(reply.method) @@ -777,7 +777,7 @@ enddef # process the workspace/applyEdit LSP server request # Request: "workspace/applyEdit" # Param: ApplyWorkspaceEditParams -def s:processApplyEditReq(lspserver: dict, request: dict) +def s:ProcessApplyEditReq(lspserver: dict, request: dict) # interface ApplyWorkspaceEditParams if !request->has_key('params') return @@ -791,7 +791,7 @@ def s:processApplyEditReq(lspserver: dict, request: dict) lspserver.sendResponse(request, {applied: true}, {}) enddef -def s:processUnsupportedReq(lspserver: dict, request: dict) +def s:ProcessUnsupportedReq(lspserver: dict, request: dict) util.ErrMsg('Error: Unsupported request message received from the LSP server (' .. lspserver.path .. '), message = ' .. request->string()) enddef @@ -799,14 +799,14 @@ enddef export def ProcessRequest(lspserver: dict, request: dict) var lspRequestHandlers: dict = { - 'workspace/applyEdit': function('s:processApplyEditReq'), - 'window/workDoneProgress/create': function('s:processUnsupportedReq'), - 'client/registerCapability': function('s:processUnsupportedReq'), - 'client/unregisterCapability': function('s:processUnsupportedReq'), - 'workspace/workspaceFolders': function('s:processUnsupportedReq'), - 'workspace/configuration': function('s:processUnsupportedReq'), - 'workspace/codeLens/refresh': function('s:processUnsupportedReq'), - 'workspace/semanticTokens/refresh': function('s:processUnsupportedReq') + 'workspace/applyEdit': function('s:ProcessApplyEditReq'), + 'window/workDoneProgress/create': function('s:ProcessUnsupportedReq'), + 'client/registerCapability': function('s:ProcessUnsupportedReq'), + 'client/unregisterCapability': function('s:ProcessUnsupportedReq'), + 'workspace/workspaceFolders': function('s:ProcessUnsupportedReq'), + 'workspace/configuration': function('s:ProcessUnsupportedReq'), + 'workspace/codeLens/refresh': function('s:ProcessUnsupportedReq'), + 'workspace/semanticTokens/refresh': function('s:ProcessUnsupportedReq') } if lspRequestHandlers->has_key(request.method) diff --git a/autoload/lsp.vim b/autoload/lsp.vim index 7a37b6a..324c048 100644 --- a/autoload/lsp.vim +++ b/autoload/lsp.vim @@ -121,7 +121,7 @@ var ftypeOmniCtrlMap: dict = {} var lspInitializedOnce = false -def s:lspInitOnce() +def s:LspInitOnce() # Signs used for LSP diagnostics sign_define([{name: 'LspDiagError', text: 'E ', texthl: 'ErrorMsg', linehl: 'MatchParen'}, @@ -141,13 +141,13 @@ enddef # Returns the LSP server for the a specific filetype. Returns an empty dict if # the server is not found. -def s:lspGetServer(ftype: string): dict +def s:LspGetServer(ftype: string): dict return ftypeServerMap->get(ftype, {}) enddef # Returns the LSP server for the current buffer if it is running and is ready. # Returns an empty dict if the server is not found or is not ready. -def s:curbufGetServerChecked(): dict +def s:CurbufGetServerChecked(): dict var fname: string = @% if fname == '' return {} @@ -171,18 +171,18 @@ def s:curbufGetServerChecked(): dict enddef # Add a LSP server for a filetype -def s:lspAddServer(ftype: string, lspsrv: dict) +def s:LspAddServer(ftype: string, lspsrv: dict) ftypeServerMap->extend({[ftype]: lspsrv}) enddef # Returns true if omni-completion is enabled for filetype 'ftype'. # Otherwise, returns false. -def s:lspOmniComplEnabled(ftype: string): bool +def s:LspOmniComplEnabled(ftype: string): bool return ftypeOmniCtrlMap->get(ftype, v:false) enddef # Enables or disables omni-completion for filetype 'fype' -def s:lspOmniComplSet(ftype: string, enabled: bool) +def s:LspOmniComplSet(ftype: string, enabled: bool) ftypeOmniCtrlMap->extend({[ftype]: enabled}) enddef @@ -207,7 +207,7 @@ enddef # Go to a definition using "textDocument/definition" LSP request export def GotoDefinition(peek: bool) - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -217,7 +217,7 @@ enddef # Go to a declaration using "textDocument/declaration" LSP request export def GotoDeclaration(peek: bool) - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -227,7 +227,7 @@ enddef # Go to a type definition using "textDocument/typeDefinition" LSP request export def GotoTypedef(peek: bool) - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -237,7 +237,7 @@ enddef # Go to a implementation using "textDocument/implementation" LSP request export def GotoImplementation(peek: bool) - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -248,7 +248,7 @@ enddef # Show the signature using "textDocument/signatureHelp" LSP method # Invoked from an insert-mode mapping, so return an empty string. def g:LspShowSignature(): string - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return '' endif @@ -260,7 +260,7 @@ def g:LspShowSignature(): string enddef # buffer change notification listener -def s:bufchange_listener(bnr: number, start: number, end: number, added: number, changes: list>) +def s:Bufchange_listener(bnr: number, start: number, end: number, added: number, changes: list>) var lspserver: dict = buf.CurbufGetServer() if lspserver->empty() || !lspserver.running return @@ -270,7 +270,7 @@ def s:bufchange_listener(bnr: number, start: number, end: number, added: number, enddef # A buffer is saved. Send the "textDocument/didSave" LSP notification -def s:lspSavedFile() +def s:LspSavedFile() var bnr: number = expand('')->str2nr() var lspserver: dict = buf.BufLspServerGet(bnr) if lspserver->empty() || !lspserver.running @@ -339,20 +339,20 @@ export def AddFile(bnr: number): void if ftype == '' return endif - var lspserver: dict = s:lspGetServer(ftype) + var lspserver: dict = s:LspGetServer(ftype) if lspserver->empty() return endif if !lspserver.running if !lspInitializedOnce - s:lspInitOnce() + s:LspInitOnce() endif lspserver.startServer() endif lspserver.textdocDidOpen(bnr, ftype) # add a listener to track changes to this buffer - listener_add(function('s:bufchange_listener'), bnr) + listener_add(function('s:Bufchange_listener'), bnr) # set options for insert mode completion if opt.lspOptions.autoComplete @@ -363,7 +363,7 @@ export def AddFile(bnr: number): void inoremap pumvisible() ? "\\" : "\" endif else - if s:lspOmniComplEnabled(ftype) + if s:LspOmniComplEnabled(ftype) setbufvar(bnr, '&omnifunc', 'LspOmniFunc') endif endif @@ -376,7 +376,7 @@ export def AddFile(bnr: number): void # Set buffer local autocmds augroup LSPBufferAutocmds # file saved notification handler - exe 'autocmd BufWritePost call s:lspSavedFile()' + exe 'autocmd BufWritePost call s:LspSavedFile()' if opt.lspOptions.autoComplete # Trigger 24x7 insert mode completion when text is changed @@ -454,12 +454,12 @@ export def AddServer(serverList: list>) var lspserver: dict = lserver.NewLspServer(server.path, args) if server.filetype->type() == v:t_string - s:lspAddServer(server.filetype, lspserver) - s:lspOmniComplSet(server.filetype, server.omnicompl) + s:LspAddServer(server.filetype, lspserver) + s:LspOmniComplSet(server.filetype, server.omnicompl) elseif server.filetype->type() == v:t_list for ftype in server.filetype - s:lspAddServer(ftype, lspserver) - s:lspOmniComplSet(ftype, server.omnicompl) + s:LspAddServer(ftype, lspserver) + s:LspOmniComplSet(ftype, server.omnicompl) endfor else util.ErrMsg('Error: Unsupported file type information "' .. @@ -492,7 +492,7 @@ export def SetTraceServer(traceVal: string) return endif - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -503,7 +503,7 @@ enddef # Display the diagnostic messages from the LSP server for the current buffer # in a quickfix list export def ShowDiagnostics(): void - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -513,7 +513,7 @@ enddef # Show the diagnostic message for the current line export def LspShowCurrentDiag() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -554,7 +554,7 @@ enddef # jump to the next/previous/first diagnostic message in the current buffer export def JumpToDiag(which: string): void - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -601,7 +601,7 @@ enddef # omni complete handler def g:LspOmniFunc(findstart: number, base: string): any - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return -2 endif @@ -654,7 +654,7 @@ enddef # show symbol references export def ShowReferences(peek: bool) - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -664,7 +664,7 @@ enddef # highlight all the places where a symbol is referenced def g:LspDocHighlight() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -710,7 +710,7 @@ export def TextDocFormat(range_args: number, line1: number, line2: number) return endif - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -729,7 +729,7 @@ enddef # Display all the locations where the current symbol is called from. # Uses LSP "callHierarchy/incomingCalls" request export def IncomingCalls() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -740,7 +740,7 @@ export def IncomingCalls() enddef def g:LspGetIncomingCalls(item: dict) - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -749,7 +749,7 @@ def g:LspGetIncomingCalls(item: dict) enddef def g:LspGetOutgoingCalls(item: dict) - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -761,7 +761,7 @@ enddef # Display all the symbols used by the current symbol. # Uses LSP "callHierarchy/outgoingCalls" request export def OutgoingCalls() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -774,7 +774,7 @@ enddef # Rename a symbol # Uses LSP "textDocument/rename" request export def Rename() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -790,7 +790,7 @@ enddef # Perform a code action # Uses LSP "textDocument/codeAction" request export def CodeAction() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -802,7 +802,7 @@ enddef # Perform a workspace wide symbol lookup # Uses LSP "workspace/symbol" request export def SymbolSearch(queryArg: string) - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -825,7 +825,7 @@ enddef # Display the list of workspace folders export def ListWorkspaceFolders() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -835,7 +835,7 @@ enddef # Add a workspace folder. Default is to use the current folder. export def AddWorkspaceFolder(dirArg: string) - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -858,7 +858,7 @@ enddef # Remove a workspace folder. Default is to use the current folder. export def RemoveWorkspaceFolder(dirArg: string) - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -881,7 +881,7 @@ enddef # expand the previous selection or start a new selection export def SelectionExpand() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -891,7 +891,7 @@ enddef # shrink the previous selection or start a new selection export def SelectionShrink() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -901,7 +901,7 @@ enddef # fold the entire document export def FoldDocument() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif @@ -927,7 +927,7 @@ enddef # Display the LSP server capabilities export def ShowServerCapabilities() - var lspserver: dict = s:curbufGetServerChecked() + var lspserver: dict = s:CurbufGetServerChecked() if lspserver->empty() return endif diff --git a/autoload/lspserver.vim b/autoload/lspserver.vim index 9a71724..74a693f 100644 --- a/autoload/lspserver.vim +++ b/autoload/lspserver.vim @@ -56,19 +56,19 @@ else endif # LSP server standard output handler -def s:output_cb(lspserver: dict, chan: channel, msg: string): void +def s:Output_cb(lspserver: dict, chan: channel, msg: string): void util.TraceLog(false, msg) lspserver.data = lspserver.data .. msg lspserver.processMessages() enddef # LSP server error output handler -def s:error_cb(lspserver: dict, chan: channel, emsg: string,): void +def s:Error_cb(lspserver: dict, chan: channel, emsg: string,): void util.TraceLog(true, emsg) enddef # LSP server exit callback -def s:exit_cb(lspserver: dict, job: job, status: number): void +def s:Exit_cb(lspserver: dict, job: job, status: number): void util.WarnMsg("LSP server exited with status " .. status) lspserver.job = v:null lspserver.running = false @@ -77,7 +77,7 @@ def s:exit_cb(lspserver: dict, job: job, status: number): void enddef # Start a LSP server -def s:startServer(lspserver: dict): number +def s:StartServer(lspserver: dict): number if lspserver.running util.WarnMsg("LSP server for is already running") return 0 @@ -90,9 +90,9 @@ def s:startServer(lspserver: dict): number out_mode: 'raw', err_mode: 'raw', noblock: 1, - out_cb: function('s:output_cb', [lspserver]), - err_cb: function('s:error_cb', [lspserver]), - exit_cb: function('s:exit_cb', [lspserver])} + out_cb: function('s:Output_cb', [lspserver]), + err_cb: function('s:Error_cb', [lspserver]), + exit_cb: function('s:Exit_cb', [lspserver])} lspserver.data = '' lspserver.caps = {} @@ -122,7 +122,7 @@ enddef # Request: 'initialize' # Param: InitializeParams -def s:initServer(lspserver: dict) +def s:InitServer(lspserver: dict) var req = lspserver.createRequest('initialize') # client capabilities (ClientCapabilities) @@ -175,27 +175,27 @@ enddef # Send a "initialized" LSP notification # Params: InitializedParams -def s:sendInitializedNotif(lspserver: dict) +def s:SendInitializedNotif(lspserver: dict) var notif: dict = lspserver.createNotification('initialized') lspserver.sendMessage(notif) enddef # Request: shutdown # Param: void -def s:shutdownServer(lspserver: dict): void +def s:ShutdownServer(lspserver: dict): void var req = lspserver.createRequest('shutdown') lspserver.sendMessage(req) enddef # Send a 'exit' notification to the LSP server # Params: void -def s:exitServer(lspserver: dict): void +def s:ExitServer(lspserver: dict): void var notif: dict = lspserver.createNotification('exit') lspserver.sendMessage(notif) enddef # Stop a LSP server -def s:stopServer(lspserver: dict): number +def s:StopServer(lspserver: dict): number if !lspserver.running util.WarnMsg("LSP server is not running") return 0 @@ -217,21 +217,21 @@ def s:stopServer(lspserver: dict): number enddef # set the LSP server trace level using $/setTrace notification -def s:setTrace(lspserver: dict, traceVal: string) +def s:SetTrace(lspserver: dict, traceVal: string) var notif: dict = lspserver.createNotification('$/setTrace') notif.params->extend({value: traceVal}) lspserver.sendMessage(notif) enddef # Return the next id for a LSP server request message -def s:nextReqID(lspserver: dict): number +def s:NextReqID(lspserver: dict): number var id = lspserver.nextID lspserver.nextID = id + 1 return id enddef # create a LSP server request message -def s:createRequest(lspserver: dict, method: string): dict +def s:CreateRequest(lspserver: dict, method: string): dict var req = {} req.jsonrpc = '2.0' req.id = lspserver.nextReqID() @@ -245,7 +245,7 @@ def s:createRequest(lspserver: dict, method: string): dict enddef # create a LSP server response message -def s:createResponse(lspserver: dict, req_id: number): dict +def s:CreateResponse(lspserver: dict, req_id: number): dict var resp = {} resp.jsonrpc = '2.0' resp.id = req_id @@ -254,7 +254,7 @@ def s:createResponse(lspserver: dict, req_id: number): dict enddef # create a LSP server notification message -def s:createNotification(lspserver: dict, notif: string): dict +def s:CreateNotification(lspserver: dict, notif: string): dict var req = {} req.jsonrpc = '2.0' req.method = notif @@ -264,7 +264,7 @@ def s:createNotification(lspserver: dict, notif: string): dict enddef # send a response message to the server -def s:sendResponse(lspserver: dict, request: dict, result: dict, error: dict) +def s:SendResponse(lspserver: dict, request: dict, result: dict, error: dict) var resp: dict = lspserver.createResponse(request.id) if result->type() != v:t_none resp->extend({result: result}) @@ -275,7 +275,7 @@ def s:sendResponse(lspserver: dict, request: dict, result: dict, enddef # Send a request message to LSP server -def s:sendMessage(lspserver: dict, content: dict): void +def s: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 ch = lspserver.job->job_getchannel() @@ -289,7 +289,7 @@ enddef # Wait for a response message from the LSP server for the request "req" # Waits for a maximum of 5 seconds -def s:waitForReponse(lspserver: dict, req: dict) +def s:WaitForReponse(lspserver: dict, req: dict) var maxCount: number = 2500 var key: string = req.id->string() @@ -301,7 +301,7 @@ enddef # Send a LSP "textDocument/didOpen" notification # Params: DidOpenTextDocumentParams -def s:textdocDidOpen(lspserver: dict, bnr: number, ftype: string): void +def s:TextdocDidOpen(lspserver: dict, bnr: number, ftype: string): void var notif: dict = lspserver.createNotification('textDocument/didOpen') # interface DidOpenTextDocumentParams @@ -317,7 +317,7 @@ def s:textdocDidOpen(lspserver: dict, bnr: number, ftype: string): void enddef # Send a LSP "textDocument/didClose" notification -def s:textdocDidClose(lspserver: dict, bnr: number): void +def s:TextdocDidClose(lspserver: dict, bnr: number): void var notif: dict = lspserver.createNotification('textDocument/didClose') # interface DidCloseTextDocumentParams @@ -331,7 +331,7 @@ enddef # Send a LSP "textDocument/didChange" notification # Params: DidChangeTextDocumentParams -def s:textdocDidChange(lspserver: dict, bnr: number, start: number, +def s:TextdocDidChange(lspserver: dict, bnr: number, start: number, end: number, added: number, changes: list>): void var notif: dict = lspserver.createNotification('textDocument/didChange') @@ -392,7 +392,7 @@ enddef # LSP line and column numbers start from zero, whereas Vim line and column # numbers start from one. The LSP column number is the character index in the # line and not the byte index in the line. -def s:getLspPosition(): dict +def s:GetLspPosition(): dict var lnum: number = line('.') - 1 var col: number = charcol('.') - 1 return {line: lnum, character: col} @@ -400,17 +400,17 @@ enddef # Return the current file name and current cursor position as a LSP # TextDocumentPositionParams structure -def s:getLspTextDocPosition(): dict> +def s:GetLspTextDocPosition(): dict> # interface TextDocumentIdentifier # interface Position return {textDocument: {uri: util.LspFileToUri(@%)}, - position: s:getLspPosition()} + position: s:GetLspPosition()} enddef # Get a list of completion items. # Request: "textDocument/completion" # Param: CompletionParams -def s:getCompletion(lspserver: dict, triggerKind_arg: number): void +def s:GetCompletion(lspserver: dict, triggerKind_arg: number): void # Check whether LSP server supports completion if !lspserver.caps->has_key('completionProvider') util.ErrMsg("Error: LSP server does not support completion") @@ -426,7 +426,7 @@ def s:getCompletion(lspserver: dict, triggerKind_arg: number): void # interface CompletionParams # interface TextDocumentPositionParams - req.params = s:getLspTextDocPosition() + req.params = s:GetLspTextDocPosition() # interface CompletionContext req.params.context = {triggerKind: triggerKind_arg} @@ -439,7 +439,7 @@ enddef # Request: "textDocument/definition" # Param: DefinitionParams -def s:gotoDefinition(lspserver: dict, peek: bool) +def s:GotoDefinition(lspserver: dict, peek: bool) # Check whether LSP server supports jumping to a definition if !lspserver.caps->has_key('definitionProvider') || !lspserver.caps.definitionProvider @@ -454,7 +454,7 @@ def s:gotoDefinition(lspserver: dict, peek: bool) var req = lspserver.createRequest('textDocument/definition') # interface DefinitionParams # interface TextDocumentPositionParams - req.params->extend(s:getLspTextDocPosition()) + req.params->extend(s:GetLspTextDocPosition()) lspserver.sendMessage(req) lspserver.waitForReponse(req) @@ -462,7 +462,7 @@ enddef # Request: "textDocument/declaration" # Param: DeclarationParams -def s:gotoDeclaration(lspserver: dict, peek: bool): void +def s:GotoDeclaration(lspserver: dict, peek: bool): void # Check whether LSP server supports jumping to a declaration if !lspserver.caps->has_key('declarationProvider') || !lspserver.caps.declarationProvider @@ -478,7 +478,7 @@ def s:gotoDeclaration(lspserver: dict, peek: bool): void # interface DeclarationParams # interface TextDocumentPositionParams - req.params->extend(s:getLspTextDocPosition()) + req.params->extend(s:GetLspTextDocPosition()) lspserver.sendMessage(req) @@ -487,7 +487,7 @@ enddef # Request: "textDocument/typeDefinition" # Param: TypeDefinitionParams -def s:gotoTypeDef(lspserver: dict, peek: bool): void +def s:GotoTypeDef(lspserver: dict, peek: bool): void # Check whether LSP server supports jumping to a type definition if !lspserver.caps->has_key('typeDefinitionProvider') || !lspserver.caps.typeDefinitionProvider @@ -503,7 +503,7 @@ def s:gotoTypeDef(lspserver: dict, peek: bool): void # interface TypeDefinitionParams # interface TextDocumentPositionParams - req.params->extend(s:getLspTextDocPosition()) + req.params->extend(s:GetLspTextDocPosition()) lspserver.sendMessage(req) @@ -512,7 +512,7 @@ enddef # Request: "textDocument/implementation" # Param: ImplementationParams -def s:gotoImplementation(lspserver: dict, peek: bool): void +def s:GotoImplementation(lspserver: dict, peek: bool): void # Check whether LSP server supports jumping to a implementation if !lspserver.caps->has_key('implementationProvider') || !lspserver.caps.implementationProvider @@ -528,7 +528,7 @@ def s:gotoImplementation(lspserver: dict, peek: bool): void # interface ImplementationParams # interface TextDocumentPositionParams - req.params->extend(s:getLspTextDocPosition()) + req.params->extend(s:GetLspTextDocPosition()) lspserver.sendMessage(req) @@ -538,7 +538,7 @@ enddef # get symbol signature help. # Request: "textDocument/signatureHelp" # Param: SignatureHelpParams -def s:showSignature(lspserver: dict): void +def s:ShowSignature(lspserver: dict): void # Check whether LSP server supports signature help if !lspserver.caps->has_key('signatureHelpProvider') util.ErrMsg("Error: LSP server does not support signature help") @@ -548,7 +548,7 @@ def s:showSignature(lspserver: dict): void var req = lspserver.createRequest('textDocument/signatureHelp') # interface SignatureHelpParams # interface TextDocumentPositionParams - req.params->extend(s:getLspTextDocPosition()) + req.params->extend(s:GetLspTextDocPosition()) lspserver.sendMessage(req) @@ -558,7 +558,7 @@ def s:showSignature(lspserver: dict): void endif enddef -def s:didSaveFile(lspserver: dict, bnr: number): void +def s:DidSaveFile(lspserver: dict, bnr: number): void # Check whether the LSP server supports the didSave notification if !lspserver.caps->has_key('textDocumentSync') || lspserver.caps.textDocumentSync->type() == v:t_number @@ -577,7 +577,7 @@ enddef # get the hover information # Request: "textDocument/hover" # Param: HoverParams -def s:hover(lspserver: dict): void +def s:Hover(lspserver: dict): void # Check whether LSP server supports getting hover information if !lspserver.caps->has_key('hoverProvider') || !lspserver.caps.hoverProvider @@ -587,7 +587,7 @@ def s:hover(lspserver: dict): void var req = lspserver.createRequest('textDocument/hover') # interface HoverParams # interface TextDocumentPositionParams - req.params->extend(s:getLspTextDocPosition()) + req.params->extend(s:GetLspTextDocPosition()) lspserver.sendMessage(req) if exists('g:LSPTest') && g:LSPTest # When running LSP tests, make this a synchronous call @@ -597,7 +597,7 @@ enddef # Request: "textDocument/references" # Param: ReferenceParams -def s:showReferences(lspserver: dict, peek: bool): void +def s:ShowReferences(lspserver: dict, peek: bool): void # Check whether LSP server supports getting reference information if !lspserver.caps->has_key('referencesProvider') || !lspserver.caps.referencesProvider @@ -608,7 +608,7 @@ def s:showReferences(lspserver: dict, peek: bool): void var req = lspserver.createRequest('textDocument/references') # interface ReferenceParams # interface TextDocumentPositionParams - req.params->extend(s:getLspTextDocPosition()) + req.params->extend(s:GetLspTextDocPosition()) req.params->extend({context: {includeDeclaration: true}}) lspserver.peekSymbol = peek @@ -621,7 +621,7 @@ enddef # Request: "textDocument/documentHighlight" # Param: DocumentHighlightParams -def s:docHighlight(lspserver: dict): void +def s:DocHighlight(lspserver: dict): void # Check whether LSP server supports getting highlight information if !lspserver.caps->has_key('documentHighlightProvider') || !lspserver.caps.documentHighlightProvider @@ -632,7 +632,7 @@ def s:docHighlight(lspserver: dict): void var req = lspserver.createRequest('textDocument/documentHighlight') # interface DocumentHighlightParams # interface TextDocumentPositionParams - req.params->extend(s:getLspTextDocPosition()) + req.params->extend(s:GetLspTextDocPosition()) lspserver.sendMessage(req) if exists('g:LSPTest') && g:LSPTest # When running LSP tests, make this a synchronous call @@ -642,7 +642,7 @@ enddef # Request: "textDocument/documentSymbol" # Param: DocumentSymbolParams -def s:getDocSymbols(lspserver: dict, fname: string): void +def s:GetDocSymbols(lspserver: dict, fname: string): void # Check whether LSP server supports getting document symbol information if !lspserver.caps->has_key('documentSymbolProvider') || !lspserver.caps.documentSymbolProvider @@ -666,7 +666,7 @@ enddef # or # Request: "textDocument/rangeFormatting" # Param: DocumentRangeFormattingParams -def s:textDocFormat(lspserver: dict, fname: string, rangeFormat: bool, +def s:TextDocFormat(lspserver: dict, fname: string, rangeFormat: bool, start_lnum: number, end_lnum: number) # Check whether LSP server supports formatting documents if !lspserver.caps->has_key('documentFormattingProvider') @@ -717,7 +717,7 @@ enddef # Request: "textDocument/prepareCallHierarchy" # Param: CallHierarchyPrepareParams -def s:prepareCallHierarchy(lspserver: dict, fname: string) +def s:PrepareCallHierarchy(lspserver: dict, fname: string) # Check whether LSP server supports call hierarchy if !lspserver.caps->has_key('callHierarchyProvider') || !lspserver.caps.callHierarchyProvider @@ -729,13 +729,13 @@ def s:prepareCallHierarchy(lspserver: dict, fname: string) # interface CallHierarchyPrepareParams # interface TextDocumentPositionParams - req.params->extend(s:getLspTextDocPosition()) + req.params->extend(s:GetLspTextDocPosition()) lspserver.sendMessage(req) enddef # Request: "callHierarchy/incomingCalls" # Param: CallHierarchyItem -def s:incomingCalls(lspserver: dict, hierItem: dict) +def s:IncomingCalls(lspserver: dict, hierItem: dict) # Check whether LSP server supports call hierarchy if !lspserver.caps->has_key('callHierarchyProvider') || !lspserver.caps.callHierarchyProvider @@ -757,7 +757,7 @@ enddef # Request: "callHierarchy/outgoingCalls" # Param: CallHierarchyItem -def s:outgoingCalls(lspserver: dict, hierItem: dict) +def s:OutgoingCalls(lspserver: dict, hierItem: dict) # Check whether LSP server supports call hierarchy if !lspserver.caps->has_key('callHierarchyProvider') || !lspserver.caps.callHierarchyProvider @@ -779,7 +779,7 @@ enddef # Request: "textDocument/rename" # Param: RenameParams -def s:renameSymbol(lspserver: dict, newName: string) +def s:RenameSymbol(lspserver: dict, newName: string) # Check whether LSP server supports rename operation if !lspserver.caps->has_key('renameProvider') || !lspserver.caps.renameProvider @@ -790,7 +790,7 @@ def s:renameSymbol(lspserver: dict, newName: string) var req = lspserver.createRequest('textDocument/rename') # interface RenameParams # interface TextDocumentPositionParams - req.params = s:getLspTextDocPosition() + req.params = s:GetLspTextDocPosition() req.params.newName = newName lspserver.sendMessage(req) if exists('g:LSPTest') && g:LSPTest @@ -801,7 +801,7 @@ enddef # Request: "textDocument/codeAction" # Param: CodeActionParams -def s:codeAction(lspserver: dict, fname_arg: string) +def s:CodeAction(lspserver: dict, fname_arg: string) # Check whether LSP server supports code action operation if !lspserver.caps->has_key('codeActionProvider') || !lspserver.caps.codeActionProvider @@ -836,7 +836,7 @@ enddef # List project-wide symbols matching query string # Request: "workspace/symbol" # Param: WorkspaceSymbolParams -def s:workspaceQuerySymbols(lspserver: dict, query: string): bool +def s:WorkspaceQuerySymbols(lspserver: dict, query: string): bool # Check whether the LSP server supports listing workspace symbols if !lspserver.caps->has_key('workspaceSymbolProvider') || !lspserver.caps.workspaceSymbolProvider @@ -854,7 +854,7 @@ enddef # Add a workspace folder to the LSP server. # Request: "workspace/didChangeWorkspaceFolders" # Param: DidChangeWorkspaceFoldersParams -def s:addWorkspaceFolder(lspserver: dict, dirName: string): void +def s:AddWorkspaceFolder(lspserver: dict, dirName: string): void if !lspserver.caps->has_key('workspace') || !lspserver.caps.workspace->has_key('workspaceFolders') || !lspserver.caps.workspace.workspaceFolders->has_key('supported') @@ -880,7 +880,7 @@ enddef # Remove a workspace folder from the LSP server. # Request: "workspace/didChangeWorkspaceFolders" # Param: DidChangeWorkspaceFoldersParams -def s:removeWorkspaceFolder(lspserver: dict, dirName: string): void +def s:RemoveWorkspaceFolder(lspserver: dict, dirName: string): void if !lspserver.caps->has_key('workspace') || !lspserver.caps.workspace->has_key('workspaceFolders') || !lspserver.caps.workspace.workspaceFolders->has_key('supported') @@ -907,7 +907,7 @@ enddef # select the text around the current cursor location # Request: "textDocument/selectionRange" # Param: SelectionRangeParams -def s:selectionRange(lspserver: dict, fname: string) +def s:SelectionRange(lspserver: dict, fname: string) # Check whether LSP server supports selection ranges if !lspserver.caps->has_key('selectionRangeProvider') || !lspserver.caps.selectionRangeProvider @@ -921,14 +921,14 @@ def s:selectionRange(lspserver: dict, fname: string) var req = lspserver.createRequest('textDocument/selectionRange') # interface SelectionRangeParams # interface TextDocumentIdentifier - req.params->extend({textDocument: {uri: util.LspFileToUri(fname)}, positions: [s:getLspPosition()]}) + req.params->extend({textDocument: {uri: util.LspFileToUri(fname)}, positions: [s:GetLspPosition()]}) lspserver.sendMessage(req) lspserver.waitForReponse(req) enddef # Expand the previous selection or start a new one -def s:selectionExpand(lspserver: dict) +def s:SelectionExpand(lspserver: dict) # Check whether LSP server supports selection ranges if !lspserver.caps->has_key('selectionRangeProvider') || !lspserver.caps.selectionRangeProvider @@ -940,7 +940,7 @@ def s:selectionExpand(lspserver: dict) enddef # Shrink the previous selection or start a new one -def s:selectionShrink(lspserver: dict) +def s:SelectionShrink(lspserver: dict) # Check whether LSP server supports selection ranges if !lspserver.caps->has_key('selectionRangeProvider') || !lspserver.caps.selectionRangeProvider @@ -954,7 +954,7 @@ enddef # fold the entire document # Request: "textDocument/foldingRange" # Param: FoldingRangeParams -def s:foldRange(lspserver: dict, fname: string) +def s:FoldRange(lspserver: dict, fname: string) # Check whether LSP server supports fold ranges if !lspserver.caps->has_key('foldingRangeProvider') || !lspserver.caps.foldingRangeProvider @@ -976,7 +976,7 @@ enddef # Request the LSP server to execute a command # Request: workspace/executeCommand # Params: ExecuteCommandParams -def s:executeCommand(lspserver: dict, cmd: dict) +def s:ExecuteCommand(lspserver: dict, cmd: dict) var req = lspserver.createRequest('workspace/executeCommand') req.params->extend(cmd) lspserver.sendMessage(req) @@ -988,7 +988,7 @@ enddef # Display the LSP server capabilities (received during the initialization # stage). -def s:showCapabilities(lspserver: dict) +def s:ShowCapabilities(lspserver: dict) echo "Capabilities of '" .. lspserver.path .. "' LSP server:" for k in lspserver.caps->keys()->sort() echo k .. ": " .. lspserver.caps[k]->string() @@ -1018,54 +1018,54 @@ export def NewLspServer(path: string, args: list): dict } # Add the LSP server functions lspserver->extend({ - startServer: function('s:startServer', [lspserver]), - initServer: function('s:initServer', [lspserver]), - stopServer: function('s:stopServer', [lspserver]), - shutdownServer: function('s:shutdownServer', [lspserver]), - exitServer: function('s:exitServer', [lspserver]), - setTrace: function('s:setTrace', [lspserver]), - nextReqID: function('s:nextReqID', [lspserver]), - createRequest: function('s:createRequest', [lspserver]), - createResponse: function('s:createResponse', [lspserver]), - createNotification: function('s:createNotification', [lspserver]), - sendResponse: function('s:sendResponse', [lspserver]), - sendMessage: function('s:sendMessage', [lspserver]), - waitForReponse: function('s:waitForReponse', [lspserver]), + startServer: function('s:StartServer', [lspserver]), + initServer: function('s:InitServer', [lspserver]), + stopServer: function('s:StopServer', [lspserver]), + shutdownServer: function('s:ShutdownServer', [lspserver]), + exitServer: function('s:ExitServer', [lspserver]), + setTrace: function('s:SetTrace', [lspserver]), + nextReqID: function('s:NextReqID', [lspserver]), + createRequest: function('s:CreateRequest', [lspserver]), + createResponse: function('s:CreateResponse', [lspserver]), + createNotification: function('s:CreateNotification', [lspserver]), + sendResponse: function('s:SendResponse', [lspserver]), + sendMessage: function('s:SendMessage', [lspserver]), + waitForReponse: function('s:WaitForReponse', [lspserver]), processReply: function(handlers.ProcessReply, [lspserver]), processNotif: function(handlers.ProcessNotif, [lspserver]), processRequest: function(handlers.ProcessRequest, [lspserver]), processMessages: function(handlers.ProcessMessages, [lspserver]), getDiagByLine: function(diag.GetDiagByLine, [lspserver]), - textdocDidOpen: function('s:textdocDidOpen', [lspserver]), - textdocDidClose: function('s:textdocDidClose', [lspserver]), - textdocDidChange: function('s:textdocDidChange', [lspserver]), - sendInitializedNotif: function('s:sendInitializedNotif', [lspserver]), - getCompletion: function('s:getCompletion', [lspserver]), - gotoDefinition: function('s:gotoDefinition', [lspserver]), - gotoDeclaration: function('s:gotoDeclaration', [lspserver]), - gotoTypeDef: function('s:gotoTypeDef', [lspserver]), - gotoImplementation: function('s:gotoImplementation', [lspserver]), - showSignature: function('s:showSignature', [lspserver]), - didSaveFile: function('s:didSaveFile', [lspserver]), - hover: function('s:hover', [lspserver]), - showReferences: function('s:showReferences', [lspserver]), - docHighlight: function('s:docHighlight', [lspserver]), - getDocSymbols: function('s:getDocSymbols', [lspserver]), - textDocFormat: function('s:textDocFormat', [lspserver]), - prepareCallHierarchy: function('s:prepareCallHierarchy', [lspserver]), - incomingCalls: function('s:incomingCalls', [lspserver]), - outgoingCalls: function('s:outgoingCalls', [lspserver]), - renameSymbol: function('s:renameSymbol', [lspserver]), - codeAction: function('s:codeAction', [lspserver]), - workspaceQuery: function('s:workspaceQuerySymbols', [lspserver]), - addWorkspaceFolder: function('s:addWorkspaceFolder', [lspserver]), - removeWorkspaceFolder: function('s:removeWorkspaceFolder', [lspserver]), - selectionRange: function('s:selectionRange', [lspserver]), - selectionExpand: function('s:selectionExpand', [lspserver]), - selectionShrink: function('s:selectionShrink', [lspserver]), - foldRange: function('s:foldRange', [lspserver]), - executeCommand: function('s:executeCommand', [lspserver]), - showCapabilities: function('s:showCapabilities', [lspserver]) + textdocDidOpen: function('s:TextdocDidOpen', [lspserver]), + textdocDidClose: function('s:TextdocDidClose', [lspserver]), + textdocDidChange: function('s:TextdocDidChange', [lspserver]), + sendInitializedNotif: function('s:SendInitializedNotif', [lspserver]), + getCompletion: function('s:GetCompletion', [lspserver]), + gotoDefinition: function('s:GotoDefinition', [lspserver]), + gotoDeclaration: function('s:GotoDeclaration', [lspserver]), + gotoTypeDef: function('s:GotoTypeDef', [lspserver]), + gotoImplementation: function('s:GotoImplementation', [lspserver]), + showSignature: function('s:ShowSignature', [lspserver]), + didSaveFile: function('s:DidSaveFile', [lspserver]), + hover: function('s:Hover', [lspserver]), + showReferences: function('s:ShowReferences', [lspserver]), + docHighlight: function('s:DocHighlight', [lspserver]), + getDocSymbols: function('s:GetDocSymbols', [lspserver]), + textDocFormat: function('s:TextDocFormat', [lspserver]), + prepareCallHierarchy: function('s:PrepareCallHierarchy', [lspserver]), + incomingCalls: function('s:IncomingCalls', [lspserver]), + outgoingCalls: function('s:OutgoingCalls', [lspserver]), + renameSymbol: function('s:RenameSymbol', [lspserver]), + codeAction: function('s:CodeAction', [lspserver]), + workspaceQuery: function('s:WorkspaceQuerySymbols', [lspserver]), + addWorkspaceFolder: function('s:AddWorkspaceFolder', [lspserver]), + removeWorkspaceFolder: function('s:RemoveWorkspaceFolder', [lspserver]), + selectionRange: function('s:SelectionRange', [lspserver]), + selectionExpand: function('s:SelectionExpand', [lspserver]), + selectionShrink: function('s:SelectionShrink', [lspserver]), + foldRange: function('s:FoldRange', [lspserver]), + executeCommand: function('s:ExecuteCommand', [lspserver]), + showCapabilities: function('s:ShowCapabilities', [lspserver]) }) return lspserver diff --git a/autoload/outline.vim b/autoload/outline.vim index 71840f8..25e41ed 100644 --- a/autoload/outline.vim +++ b/autoload/outline.vim @@ -16,7 +16,7 @@ else endif # jump to a symbol selected in the outline window -def s:outlineJumpToSymbol() +def s:OutlineJumpToSymbol() var lnum: number = line('.') - 1 if w:lspSymbols.lnumTable[lnum]->empty() return @@ -70,7 +70,7 @@ export def SkipOutlineRefresh(): bool return skipRefresh enddef -def s:addSymbolText(bnr: number, +def s:AddSymbolText(bnr: number, symbolTypeTable: dict>>, pfx: string, text: list, @@ -99,7 +99,7 @@ def s:addSymbolText(bnr: number, col: start_col}) s.outlineLine = lnumMap->len() if s->has_key('children') && !s.children->empty() - s:addSymbolText(bnr, s.children, prefix, text, lnumMap, true) + s:AddSymbolText(bnr, s.children, prefix, text, lnumMap, true) endif endfor endfor @@ -137,7 +137,7 @@ export def UpdateOutlineWindow(fname: string, # First two lines in the buffer display comment information var lnumMap: list> = [{}, {}] var text: list = [] - s:addSymbolText(fname->bufnr(), symbolTypeTable, '', text, lnumMap, false) + s:AddSymbolText(fname->bufnr(), symbolTypeTable, '', text, lnumMap, false) append('$', text) w:lspSymbols = {filename: fname, lnumTable: lnumMap, symbolsByLine: symbolLineTable} @@ -150,13 +150,13 @@ export def UpdateOutlineWindow(fname: string, prevWinID->win_gotoid() # Highlight the current symbol - s:outlineHighlightCurrentSymbol() + s:OutlineHighlightCurrentSymbol() # re-enable refreshing the outline window skipRefresh = false enddef -def s:outlineHighlightCurrentSymbol() +def s:OutlineHighlightCurrentSymbol() var fname: string = expand('%')->fnamemodify(':p') if fname == '' || &filetype == '' return @@ -224,7 +224,7 @@ def s:outlineHighlightCurrentSymbol() enddef # when the outline window is closed, do the cleanup -def s:outlineCleanup() +def s:OutlineCleanup() # Remove the outline autocommands :silent! autocmd! LSPOutline @@ -279,8 +279,8 @@ export def OpenOutlineWindow() au! autocmd BufEnter * call g:LspRequestDocSymbols() # when the outline window is closed, do the cleanup - autocmd BufUnload LSP-Outline call s:outlineCleanup() - autocmd CursorHold * call s:outlineHighlightCurrentSymbol() + autocmd BufUnload LSP-Outline call s:OutlineCleanup() + autocmd CursorHold * call s:OutlineHighlightCurrentSymbol() augroup END prevWinID->win_gotoid() diff --git a/autoload/selection.vim b/autoload/selection.vim index 3b5e070..49c2dde 100644 --- a/autoload/selection.vim +++ b/autoload/selection.vim @@ -14,7 +14,7 @@ else endif # Visually (character-wise) select the text in a range -def s:selectText(bnr: number, range: dict>) +def s:SelectText(bnr: number, range: dict>) var start_col: number = util.GetLineByteFromPos(bnr, range.start) + 1 var end_col: number = util.GetLineByteFromPos(bnr, range.end) @@ -35,11 +35,11 @@ export def SelectionStart(lspserver: dict, sel: list>) # save the reply for expanding or shrinking the selected text. lspserver.selection = {bnr: bnr, selRange: sel[0], index: 0} - s:selectText(bnr, sel[0].range) + s:SelectText(bnr, sel[0].range) enddef # Locate the range in the LSP reply at a specified level -def s:getSelRangeAtLevel(selRange: dict, level: number): dict +def s:GetSelRangeAtLevel(selRange: dict, level: number): dict var r: dict = selRange var idx: number = 0 @@ -56,7 +56,7 @@ enddef # Returns true if the current visual selection matches a range in the # selection reply from LSP. -def s:selectionFromLSP(range: dict, startpos: list, endpos: list): bool +def s:SelectionFromLSP(range: dict, startpos: list, endpos: list): bool return startpos[1] == range.start.line + 1 && endpos[1] == range.end.line + 1 && startpos[2] == range.start.character + 1 @@ -80,11 +80,11 @@ export def SelectionModify(lspserver: dict, expand: bool) var idx: number = lspserver.selection.index # Locate the range in the LSP reply for the current selection - selRange = s:getSelRangeAtLevel(selRange, lspserver.selection.index) + selRange = s:GetSelRangeAtLevel(selRange, lspserver.selection.index) # If the current selection is present in the LSP reply, then modify the # selection - if s:selectionFromLSP(selRange.range, startpos, endpos) + if s:SelectionFromLSP(selRange.range, startpos, endpos) if expand # expand the selection if selRange->has_key('parent') @@ -95,12 +95,12 @@ export def SelectionModify(lspserver: dict, expand: bool) # shrink the selection if idx > 0 idx -= 1 - selRange = s:getSelRangeAtLevel(lspserver.selection.selRange, idx) + selRange = s:GetSelRangeAtLevel(lspserver.selection.selRange, idx) lspserver.selection.index = idx endif endif - s:selectText(bnr, selRange.range) + s:SelectText(bnr, selRange.range) return endif endif diff --git a/autoload/signature.vim b/autoload/signature.vim index 9459a2c..19ff04d 100644 --- a/autoload/signature.vim +++ b/autoload/signature.vim @@ -25,18 +25,18 @@ else endif # close the signature popup window -def s:closeSignaturePopup(lspserver: dict) +def s:CloseSignaturePopup(lspserver: dict) lspserver.signaturePopup->popup_close() lspserver.signaturePopup = -1 enddef -def s:closeCurBufSignaturePopup() +def s:CloseCurBufSignaturePopup() var lspserver: dict = buf.CurbufGetServer() if lspserver->empty() return endif - s:closeSignaturePopup(lspserver) + s:CloseSignaturePopup(lspserver) enddef # Initialize the signature triggers for the current buffer @@ -53,19 +53,19 @@ export def SignatureInit(lspserver: dict) .. "=LspShowSignature()" endfor # close the signature popup when leaving insert mode - autocmd InsertLeave call s:closeCurBufSignaturePopup() + autocmd InsertLeave call s:CloseCurBufSignaturePopup() enddef # Display the symbol signature help export def SignatureDisplay(lspserver: dict, sighelp: dict): void if sighelp->empty() - s:closeSignaturePopup(lspserver) + s:CloseSignaturePopup(lspserver) return endif if sighelp.signatures->len() <= 0 util.WarnMsg('No signature help available') - s:closeSignaturePopup(lspserver) + s:CloseSignaturePopup(lspserver) return endif diff --git a/autoload/symbol.vim b/autoload/symbol.vim index e46887d..6b09430 100644 --- a/autoload/symbol.vim +++ b/autoload/symbol.vim @@ -33,7 +33,7 @@ else endif # Handle keys pressed when the workspace symbol popup menu is displayed -def s:filterSymbols(lspserver: dict, popupID: number, key: string): bool +def s:FilterSymbols(lspserver: dict, popupID: number, key: string): bool var key_handled: bool = false var update_popup: bool = false var query: string = lspserver.workspaceSymbolQuery @@ -94,7 +94,7 @@ def s:filterSymbols(lspserver: dict, popupID: number, key: string): bool enddef # Jump to the location of a symbol selected in the popup menu -def s:jumpToWorkspaceSymbol(popupID: number, result: number): void +def s:JumpToWorkspaceSymbol(popupID: number, result: number): void # clear the message displayed at the command-line echo '' diff --git a/autoload/textedit.vim b/autoload/textedit.vim index abddb4e..77a09f6 100644 --- a/autoload/textedit.vim +++ b/autoload/textedit.vim @@ -26,7 +26,7 @@ endif # numbers. # 'a': {'A': [lnum, col], 'B': [lnum, col]} # 'b': {'A': [lnum, col], 'B': [lnum, col]} -def s:edit_sort_func(a: dict, b: dict): number +def s:Edit_sort_func(a: dict, b: dict): number # line number if a.A[0] != b.A[0] return b.A[0] - a.A[0] @@ -49,7 +49,7 @@ enddef # 'new_lines' A list of strings to replace the original # # returns the modified 'lines' -def s:set_lines(lines: list, A: list, B: list, +def s:Set_lines(lines: list, A: list, B: list, new_lines: list): list var i_0: number = A[0] @@ -153,7 +153,7 @@ export def ApplyTextEdits(bnr: number, text_edits: list>): void # Reverse sort the edit operations by descending line and column numbers so # that they can be applied without interfering with each other. - updated_edits->sort('s:edit_sort_func') + updated_edits->sort('s:Edit_sort_func') var lines: list = bnr->getbufline(start_line + 1, finish_line + 1) var fix_eol: bool = bnr->getbufvar('&fixeol') @@ -168,7 +168,7 @@ export def ApplyTextEdits(bnr: number, text_edits: list>): void for e in updated_edits var A: list = [e.A[0] - start_line, e.A[1]] var B: list = [e.B[0] - start_line, e.B[1]] - lines = s:set_lines(lines, A, B, e.lines) + lines = s:Set_lines(lines, A, B, e.lines) endfor #echomsg 'lines(2) = ' .. string(lines) @@ -202,7 +202,7 @@ export def ApplyTextEdits(bnr: number, text_edits: list>): void enddef # interface TextDocumentEdit -def s:applyTextDocumentEdit(textDocEdit: dict) +def s: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') @@ -218,7 +218,7 @@ export def ApplyWorkspaceEdit(workspaceEdit: dict) if change->has_key('kind') util.ErrMsg('Error: Unsupported change in workspace edit [' .. change.kind .. ']') else - s:applyTextDocumentEdit(change) + s:ApplyTextDocumentEdit(change) endif endfor return diff --git a/plugin/lsp.vim b/plugin/lsp.vim index 4da8915..fa06c73 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -27,19 +27,12 @@ if has('patch-8.2.4257') lspf.gotoDeclaration = lsp.GotoDeclaration lspf.gotoTypedef = lsp.GotoTypedef lspf.gotoImplementation = lsp.GotoImplementation - 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.jumpToDiag = lsp.JumpToDiag - lspf.jumpToDiag = lsp.JumpToDiag lspf.diagHighlightEnable = lsp.DiagHighlightEnable lspf.diagHighlightDisable = lsp.DiagHighlightDisable lspf.showReferences = lsp.ShowReferences - lspf.showReferences = lsp.ShowReferences lspf.outline = lsp.Outline lspf.textDocFormat = lsp.TextDocFormat lspf.incomingCalls = lsp.IncomingCalls @@ -73,19 +66,12 @@ elseif has('patch-8.2.4019') lspf.gotoDeclaration = lsp_import.GotoDeclaration lspf.gotoTypedef = lsp_import.GotoTypedef lspf.gotoImplementation = lsp_import.GotoImplementation - 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.jumpToDiag = lsp_import.JumpToDiag - lspf.jumpToDiag = lsp_import.JumpToDiag lspf.diagHighlightEnable = lsp_import.DiagHighlightEnable lspf.diagHighlightDisable = lsp_import.DiagHighlightDisable lspf.showReferences = lsp_import.ShowReferences - lspf.showReferences = lsp_import.ShowReferences lspf.outline = lsp_import.Outline lspf.textDocFormat = lsp_import.TextDocFormat lspf.incomingCalls = lsp_import.IncomingCalls