export def BufHasLspServer(bnr: number): bool
return bufnrToServer->has_key(bnr)
enddef
+
+# vim: shiftwidth=2 softtabstop=2
util.GetLineByteFromPos = GetLineByteFromPos
endif
-def s:createLoclistWithCalls(calls: list<dict<any>>, incoming: bool)
+def s:CreateLoclistWithCalls(calls: list<dict<any>>, incoming: bool)
var qflist: list<dict<any>> = []
for item in calls
return
endif
- s:createLoclistWithCalls(calls, true)
+ s:CreateLoclistWithCalls(calls, true)
enddef
export def OutgoingCalls(calls: list<dict<any>>)
return
endif
- s:createLoclistWithCalls(calls, false)
+ s:CreateLoclistWithCalls(calls, false)
enddef
# vim: shiftwidth=2 softtabstop=2
endif
enddef
-def s:lspDiagSevToSignName(severity: number): string
+def s:DiagSevToSignName(severity: number): string
var typeMap: list<string> = ['LspDiagError', 'LspDiagWarning',
'LspDiagInfo', 'LspDiagHint']
if severity > 4
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()
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<string> = ['E', 'W', 'I', 'N']
if severity > 4
'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})
enddef
# sort the diaganostics messages for a buffer by line number
-def s:getSortedDiagLines(lspsrv: dict<any>, bnr: number): list<number>
+def s:GetSortedDiagLines(lspsrv: dict<any>, bnr: number): list<number>
# create a list of line numbers from the diag map keys
var lnums: list<number> =
lspsrv.diagsMap[bnr]->keys()->mapnew((_, v) => v->str2nr())
endif
# sort the diagnostics by line number
- var sortedDiags: list<number> = s:getSortedDiagLines(lspserver, bnr)
+ var sortedDiags: list<number> = s:GetSortedDiagLines(lspserver, bnr)
if which == 'first'
cursor(sortedDiags[0], 1)
# process the 'initialize' method reply from the LSP server
# Result: InitializeResult
-def s:processInitializeReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
+def s:ProcessInitializeReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
if reply.result->len() <= 0
return
endif
# 'textDocument/typeDefinition' and 'textDocument/implementation' replies from
# the LSP server
# Result: Location | Location[] | LocationLink[] | null
-def s:processDefDeclReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
+def s:ProcessDefDeclReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
var location: dict<any>
if reply.result->type() == v:t_list
if !reply.result->empty()
# process the 'textDocument/signatureHelp' reply from the LSP server
# Result: SignatureHelp | null
-def s:processSignaturehelpReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
+def s:ProcessSignaturehelpReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
signature.SignatureDisplay(lspserver, reply.result)
enddef
# process the 'textDocument/completion' reply from the LSP server
# Result: CompletionItem[] | CompletionList | null
-def s:processCompletionReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
+def s:ProcessCompletionReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
if reply.result->empty()
return
endif
# process the 'textDocument/hover' reply from the LSP server
# Result: Hover | null
-def s:processHoverReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
+def s:ProcessHoverReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
if reply.result->empty()
return
endif
# process the 'textDocument/references' reply from the LSP server
# Result: Location[] | null
-def s:processReferencesReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
+def s:ProcessReferencesReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
symbol.ShowReferences(lspserver, reply.result)
enddef
# process the 'textDocument/documentHighlight' reply from the LSP server
# Result: DocumentHighlight[] | null
-def s:processDocHighlightReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
+def s:ProcessDocHighlightReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
if reply.result->empty()
return
endif
enddef
# process SymbolInformation[]
-def s:processSymbolInfoTable(symbolInfoTable: list<dict<any>>,
+def s:ProcessSymbolInfoTable(symbolInfoTable: list<dict<any>>,
symbolTypeTable: dict<list<dict<any>>>,
symbolLineTable: list<dict<any>>)
var fname: string
enddef
# process DocumentSymbol[]
-def s:processDocSymbolTable(docSymbolTable: list<dict<any>>,
+def s:ProcessDocSymbolTable(docSymbolTable: list<dict<any>>,
symbolTypeTable: dict<list<dict<any>>>,
symbolLineTable: list<dict<any>>)
var symbolType: string
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}
# 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<any>, req: dict<any>, reply: dict<any>): void
+def s:ProcessDocSymbolReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
var fname: string
var symbolTypeTable: dict<list<dict<any>>> = {}
var symbolLineTable: list<dict<any>> = []
if reply.result[0]->has_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
# process the 'textDocument/formatting' reply from the LSP server
# Result: TextEdit[] | null
-def s:processFormatReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
+def s:ProcessFormatReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
if reply.result->empty()
# nothing to format
return
# Reply: 'textDocument/rename'
# Result: Range | { range: Range, placeholder: string }
# | { defaultBehavior: boolean } | null
-def s:processRenameReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
+def s:ProcessRenameReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
if reply.result->empty()
# nothing to rename
return
# process the 'textDocument/codeAction' reply from the LSP server
# Result: (Command | CodeAction)[] | null
-def s:processCodeActionReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
+def s:ProcessCodeActionReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
codeaction.ApplyCodeAction(lspserver, reply.result)
enddef
# Reply: 'textDocument/selectionRange'
# Result: SelectionRange[] | null
-def s:processSelectionRangeReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
+def s:ProcessSelectionRangeReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
selection.SelectionStart(lspserver, reply.result)
enddef
# Reply: 'textDocument/foldingRange'
# Result: FoldingRange[] | null
-def s:processFoldingRangeReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
+def s:ProcessFoldingRangeReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
if reply.result->empty()
return
endif
# process the 'workspace/executeCommand' reply from the LSP server
# Result: any | null
-def s:processWorkspaceExecuteReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
+def s:ProcessWorkspaceExecuteReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
if reply.result->empty()
return
endif
# Convert a file name <filename> (<dirname>) 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')
# process the 'workspace/symbol' reply from the LSP server
# Result: SymbolInformation[] | null
-def s:processWorkspaceSymbolReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
+def s:ProcessWorkspaceSymbolReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
var symbols: list<dict<any>> = []
var symbolType: string
var fileName: string
symName = symbol.containerName .. '::' .. symName
endif
symName ..= ' [' .. LspSymbolKindToName(symbol.kind) .. ']'
- symName ..= ' ' .. s:makeMenuName(
+ symName ..= ' ' .. s:MakeMenuName(
lspserver.workspaceSymbolPopup->popup_getpos().core_width,
fileName)
# process the 'textDocument/prepareCallHierarchy' reply from the LSP server
# Result: CallHierarchyItem[] | null
-def s:processPrepareCallHierarchy(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
+def s:ProcessPrepareCallHierarchy(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
if reply.result->empty()
if lspserver.callHierarchyType == 'incoming'
util.WarnMsg('No incoming calls')
# process the 'callHierarchy/incomingCalls' reply from the LSP server
# Result: CallHierarchyIncomingCall[] | null
-def s:processIncomingCalls(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
+def s:ProcessIncomingCalls(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
callhier.IncomingCalls(reply.result)
enddef
# process the 'callHierarchy/outgoingCalls' reply from the LSP server
# Result: CallHierarchyOutgoingCall[] | null
-def s:processOutgoingCalls(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
+def s:ProcessOutgoingCalls(lspserver: dict<any>, req: dict<any>, reply: dict<any>)
callhier.OutgoingCalls(reply.result)
enddef
export def ProcessReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
var lsp_reply_handlers: dict<func> =
{
- '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)
# process a diagnostic notification message from the LSP server
# Notification: textDocument/publishDiagnostics
# Param: PublishDiagnosticsParams
-def s:processDiagNotif(lspserver: dict<any>, reply: dict<any>): void
+def s:ProcessDiagNotif(lspserver: dict<any>, reply: dict<any>): 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<any>, reply: dict<any>)
+def s:ProcessShowMsgNotif(lspserver: dict<any>, reply: dict<any>)
var msgType: list<string> = ['', 'Error: ', 'Warning: ', 'Info: ', 'Log: ']
if reply.params.type == 4
# ignore log messages from the LSP server (too chatty)
# process a log notification message from the LSP server
# Notification: window/logMessage
# Param: LogMessageParams
-def s:processLogMsgNotif(lspserver: dict<any>, reply: dict<any>)
+def s:ProcessLogMsgNotif(lspserver: dict<any>, reply: dict<any>)
var msgType: list<string> = ['', 'Error: ', 'Warning: ', 'Info: ', 'Log: ']
var mtype: string = 'Log: '
if reply.params.type > 0 && reply.params.type < 5
enddef
# process unsupported notification messages
-def s:processUnsupportedNotif(lspserver: dict<any>, reply: dict<any>)
+def s:ProcessUnsupportedNotif(lspserver: dict<any>, reply: dict<any>)
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<any>, reply: dict<any>)
+def s:IgnoreNotif(lspserver: dict<any>, reply: dict<any>)
enddef
# process notification messages from the LSP server
export def ProcessNotif(lspserver: dict<any>, reply: dict<any>): void
var lsp_notif_handlers: dict<func> =
{
- '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)
# process the workspace/applyEdit LSP server request
# Request: "workspace/applyEdit"
# Param: ApplyWorkspaceEditParams
-def s:processApplyEditReq(lspserver: dict<any>, request: dict<any>)
+def s:ProcessApplyEditReq(lspserver: dict<any>, request: dict<any>)
# interface ApplyWorkspaceEditParams
if !request->has_key('params')
return
lspserver.sendResponse(request, {applied: true}, {})
enddef
-def s:processUnsupportedReq(lspserver: dict<any>, request: dict<any>)
+def s:ProcessUnsupportedReq(lspserver: dict<any>, request: dict<any>)
util.ErrMsg('Error: Unsupported request message received from the LSP server (' .. lspserver.path .. '), message = ' .. request->string())
enddef
export def ProcessRequest(lspserver: dict<any>, request: dict<any>)
var lspRequestHandlers: dict<func> =
{
- '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)
var lspInitializedOnce = false
-def s:lspInitOnce()
+def s:LspInitOnce()
# Signs used for LSP diagnostics
sign_define([{name: 'LspDiagError', text: 'E ', texthl: 'ErrorMsg',
linehl: 'MatchParen'},
# 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<any>
+def s:LspGetServer(ftype: string): dict<any>
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<any>
+def s:CurbufGetServerChecked(): dict<any>
var fname: string = @%
if fname == ''
return {}
enddef
# Add a LSP server for a filetype
-def s:lspAddServer(ftype: string, lspsrv: dict<any>)
+def s:LspAddServer(ftype: string, lspsrv: dict<any>)
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
# Go to a definition using "textDocument/definition" LSP request
export def GotoDefinition(peek: bool)
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Go to a declaration using "textDocument/declaration" LSP request
export def GotoDeclaration(peek: bool)
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Go to a type definition using "textDocument/typeDefinition" LSP request
export def GotoTypedef(peek: bool)
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Go to a implementation using "textDocument/implementation" LSP request
export def GotoImplementation(peek: bool)
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# 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<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return ''
endif
enddef
# buffer change notification listener
-def s:bufchange_listener(bnr: number, start: number, end: number, added: number, changes: list<dict<number>>)
+def s:Bufchange_listener(bnr: number, start: number, end: number, added: number, changes: list<dict<number>>)
var lspserver: dict<any> = buf.CurbufGetServer()
if lspserver->empty() || !lspserver.running
return
enddef
# A buffer is saved. Send the "textDocument/didSave" LSP notification
-def s:lspSavedFile()
+def s:LspSavedFile()
var bnr: number = expand('<abuf>')->str2nr()
var lspserver: dict<any> = buf.BufLspServerGet(bnr)
if lspserver->empty() || !lspserver.running
if ftype == ''
return
endif
- var lspserver: dict<any> = s:lspGetServer(ftype)
+ var lspserver: dict<any> = 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
inoremap <expr> <buffer> <CR> pumvisible() ? "\<C-Y>\<CR>" : "\<CR>"
endif
else
- if s:lspOmniComplEnabled(ftype)
+ if s:LspOmniComplEnabled(ftype)
setbufvar(bnr, '&omnifunc', 'LspOmniFunc')
endif
endif
# Set buffer local autocmds
augroup LSPBufferAutocmds
# file saved notification handler
- exe 'autocmd BufWritePost <buffer=' .. bnr .. '> call s:lspSavedFile()'
+ exe 'autocmd BufWritePost <buffer=' .. bnr .. '> call s:LspSavedFile()'
if opt.lspOptions.autoComplete
# Trigger 24x7 insert mode completion when text is changed
var lspserver: dict<any> = 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 "' ..
return
endif
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Display the diagnostic messages from the LSP server for the current buffer
# in a quickfix list
export def ShowDiagnostics(): void
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Show the diagnostic message for the current line
export def LspShowCurrentDiag()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# jump to the next/previous/first diagnostic message in the current buffer
export def JumpToDiag(which: string): void
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# omni complete handler
def g:LspOmniFunc(findstart: number, base: string): any
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return -2
endif
# show symbol references
export def ShowReferences(peek: bool)
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# highlight all the places where a symbol is referenced
def g:LspDocHighlight()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
return
endif
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Display all the locations where the current symbol is called from.
# Uses LSP "callHierarchy/incomingCalls" request
export def IncomingCalls()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
enddef
def g:LspGetIncomingCalls(item: dict<any>)
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
enddef
def g:LspGetOutgoingCalls(item: dict<any>)
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Display all the symbols used by the current symbol.
# Uses LSP "callHierarchy/outgoingCalls" request
export def OutgoingCalls()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Rename a symbol
# Uses LSP "textDocument/rename" request
export def Rename()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Perform a code action
# Uses LSP "textDocument/codeAction" request
export def CodeAction()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Perform a workspace wide symbol lookup
# Uses LSP "workspace/symbol" request
export def SymbolSearch(queryArg: string)
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Display the list of workspace folders
export def ListWorkspaceFolders()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Add a workspace folder. Default is to use the current folder.
export def AddWorkspaceFolder(dirArg: string)
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Remove a workspace folder. Default is to use the current folder.
export def RemoveWorkspaceFolder(dirArg: string)
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# expand the previous selection or start a new selection
export def SelectionExpand()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# shrink the previous selection or start a new selection
export def SelectionShrink()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# fold the entire document
export def FoldDocument()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
# Display the LSP server capabilities
export def ShowServerCapabilities()
- var lspserver: dict<any> = s:curbufGetServerChecked()
+ var lspserver: dict<any> = s:CurbufGetServerChecked()
if lspserver->empty()
return
endif
endif
# LSP server standard output handler
-def s:output_cb(lspserver: dict<any>, chan: channel, msg: string): void
+def s:Output_cb(lspserver: dict<any>, 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<any>, chan: channel, emsg: string,): void
+def s:Error_cb(lspserver: dict<any>, chan: channel, emsg: string,): void
util.TraceLog(true, emsg)
enddef
# LSP server exit callback
-def s:exit_cb(lspserver: dict<any>, job: job, status: number): void
+def s:Exit_cb(lspserver: dict<any>, job: job, status: number): void
util.WarnMsg("LSP server exited with status " .. status)
lspserver.job = v:null
lspserver.running = false
enddef
# Start a LSP server
-def s:startServer(lspserver: dict<any>): number
+def s:StartServer(lspserver: dict<any>): number
if lspserver.running
util.WarnMsg("LSP server for is already running")
return 0
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 = {}
# Request: 'initialize'
# Param: InitializeParams
-def s:initServer(lspserver: dict<any>)
+def s:InitServer(lspserver: dict<any>)
var req = lspserver.createRequest('initialize')
# client capabilities (ClientCapabilities)
# Send a "initialized" LSP notification
# Params: InitializedParams
-def s:sendInitializedNotif(lspserver: dict<any>)
+def s:SendInitializedNotif(lspserver: dict<any>)
var notif: dict<any> = lspserver.createNotification('initialized')
lspserver.sendMessage(notif)
enddef
# Request: shutdown
# Param: void
-def s:shutdownServer(lspserver: dict<any>): void
+def s:ShutdownServer(lspserver: dict<any>): 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<any>): void
+def s:ExitServer(lspserver: dict<any>): void
var notif: dict<any> = lspserver.createNotification('exit')
lspserver.sendMessage(notif)
enddef
# Stop a LSP server
-def s:stopServer(lspserver: dict<any>): number
+def s:StopServer(lspserver: dict<any>): number
if !lspserver.running
util.WarnMsg("LSP server is not running")
return 0
enddef
# set the LSP server trace level using $/setTrace notification
-def s:setTrace(lspserver: dict<any>, traceVal: string)
+def s:SetTrace(lspserver: dict<any>, traceVal: string)
var notif: dict<any> = 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<any>): number
+def s:NextReqID(lspserver: dict<any>): number
var id = lspserver.nextID
lspserver.nextID = id + 1
return id
enddef
# create a LSP server request message
-def s:createRequest(lspserver: dict<any>, method: string): dict<any>
+def s:CreateRequest(lspserver: dict<any>, method: string): dict<any>
var req = {}
req.jsonrpc = '2.0'
req.id = lspserver.nextReqID()
enddef
# create a LSP server response message
-def s:createResponse(lspserver: dict<any>, req_id: number): dict<any>
+def s:CreateResponse(lspserver: dict<any>, req_id: number): dict<any>
var resp = {}
resp.jsonrpc = '2.0'
resp.id = req_id
enddef
# create a LSP server notification message
-def s:createNotification(lspserver: dict<any>, notif: string): dict<any>
+def s:CreateNotification(lspserver: dict<any>, notif: string): dict<any>
var req = {}
req.jsonrpc = '2.0'
req.method = notif
enddef
# send a response message to the server
-def s:sendResponse(lspserver: dict<any>, request: dict<any>, result: dict<any>, error: dict<any>)
+def s:SendResponse(lspserver: dict<any>, request: dict<any>, result: dict<any>, error: dict<any>)
var resp: dict<any> = lspserver.createResponse(request.id)
if result->type() != v:t_none
resp->extend({result: result})
enddef
# Send a request message to LSP server
-def s:sendMessage(lspserver: dict<any>, content: dict<any>): void
+def s:SendMessage(lspserver: dict<any>, content: dict<any>): void
var payload_js: string = content->json_encode()
var msg = "Content-Length: " .. payload_js->len() .. "\r\n\r\n"
var ch = lspserver.job->job_getchannel()
# 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<any>, req: dict<any>)
+def s:WaitForReponse(lspserver: dict<any>, req: dict<any>)
var maxCount: number = 2500
var key: string = req.id->string()
# Send a LSP "textDocument/didOpen" notification
# Params: DidOpenTextDocumentParams
-def s:textdocDidOpen(lspserver: dict<any>, bnr: number, ftype: string): void
+def s:TextdocDidOpen(lspserver: dict<any>, bnr: number, ftype: string): void
var notif: dict<any> = lspserver.createNotification('textDocument/didOpen')
# interface DidOpenTextDocumentParams
enddef
# Send a LSP "textDocument/didClose" notification
-def s:textdocDidClose(lspserver: dict<any>, bnr: number): void
+def s:TextdocDidClose(lspserver: dict<any>, bnr: number): void
var notif: dict<any> = lspserver.createNotification('textDocument/didClose')
# interface DidCloseTextDocumentParams
# Send a LSP "textDocument/didChange" notification
# Params: DidChangeTextDocumentParams
-def s:textdocDidChange(lspserver: dict<any>, bnr: number, start: number,
+def s:TextdocDidChange(lspserver: dict<any>, bnr: number, start: number,
end: number, added: number,
changes: list<dict<number>>): void
var notif: dict<any> = lspserver.createNotification('textDocument/didChange')
# 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<number>
+def s:GetLspPosition(): dict<number>
var lnum: number = line('.') - 1
var col: number = charcol('.') - 1
return {line: lnum, character: col}
# Return the current file name and current cursor position as a LSP
# TextDocumentPositionParams structure
-def s:getLspTextDocPosition(): dict<dict<any>>
+def s:GetLspTextDocPosition(): dict<dict<any>>
# 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<any>, triggerKind_arg: number): void
+def s:GetCompletion(lspserver: dict<any>, 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")
# interface CompletionParams
# interface TextDocumentPositionParams
- req.params = s:getLspTextDocPosition()
+ req.params = s:GetLspTextDocPosition()
# interface CompletionContext
req.params.context = {triggerKind: triggerKind_arg}
# Request: "textDocument/definition"
# Param: DefinitionParams
-def s:gotoDefinition(lspserver: dict<any>, peek: bool)
+def s:GotoDefinition(lspserver: dict<any>, peek: bool)
# Check whether LSP server supports jumping to a definition
if !lspserver.caps->has_key('definitionProvider')
|| !lspserver.caps.definitionProvider
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)
# Request: "textDocument/declaration"
# Param: DeclarationParams
-def s:gotoDeclaration(lspserver: dict<any>, peek: bool): void
+def s:GotoDeclaration(lspserver: dict<any>, peek: bool): void
# Check whether LSP server supports jumping to a declaration
if !lspserver.caps->has_key('declarationProvider')
|| !lspserver.caps.declarationProvider
# interface DeclarationParams
# interface TextDocumentPositionParams
- req.params->extend(s:getLspTextDocPosition())
+ req.params->extend(s:GetLspTextDocPosition())
lspserver.sendMessage(req)
# Request: "textDocument/typeDefinition"
# Param: TypeDefinitionParams
-def s:gotoTypeDef(lspserver: dict<any>, peek: bool): void
+def s:GotoTypeDef(lspserver: dict<any>, peek: bool): void
# Check whether LSP server supports jumping to a type definition
if !lspserver.caps->has_key('typeDefinitionProvider')
|| !lspserver.caps.typeDefinitionProvider
# interface TypeDefinitionParams
# interface TextDocumentPositionParams
- req.params->extend(s:getLspTextDocPosition())
+ req.params->extend(s:GetLspTextDocPosition())
lspserver.sendMessage(req)
# Request: "textDocument/implementation"
# Param: ImplementationParams
-def s:gotoImplementation(lspserver: dict<any>, peek: bool): void
+def s:GotoImplementation(lspserver: dict<any>, peek: bool): void
# Check whether LSP server supports jumping to a implementation
if !lspserver.caps->has_key('implementationProvider')
|| !lspserver.caps.implementationProvider
# interface ImplementationParams
# interface TextDocumentPositionParams
- req.params->extend(s:getLspTextDocPosition())
+ req.params->extend(s:GetLspTextDocPosition())
lspserver.sendMessage(req)
# get symbol signature help.
# Request: "textDocument/signatureHelp"
# Param: SignatureHelpParams
-def s:showSignature(lspserver: dict<any>): void
+def s:ShowSignature(lspserver: dict<any>): void
# Check whether LSP server supports signature help
if !lspserver.caps->has_key('signatureHelpProvider')
util.ErrMsg("Error: LSP server does not support signature help")
var req = lspserver.createRequest('textDocument/signatureHelp')
# interface SignatureHelpParams
# interface TextDocumentPositionParams
- req.params->extend(s:getLspTextDocPosition())
+ req.params->extend(s:GetLspTextDocPosition())
lspserver.sendMessage(req)
endif
enddef
-def s:didSaveFile(lspserver: dict<any>, bnr: number): void
+def s:DidSaveFile(lspserver: dict<any>, 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
# get the hover information
# Request: "textDocument/hover"
# Param: HoverParams
-def s:hover(lspserver: dict<any>): void
+def s:Hover(lspserver: dict<any>): void
# Check whether LSP server supports getting hover information
if !lspserver.caps->has_key('hoverProvider')
|| !lspserver.caps.hoverProvider
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
# Request: "textDocument/references"
# Param: ReferenceParams
-def s:showReferences(lspserver: dict<any>, peek: bool): void
+def s:ShowReferences(lspserver: dict<any>, peek: bool): void
# Check whether LSP server supports getting reference information
if !lspserver.caps->has_key('referencesProvider')
|| !lspserver.caps.referencesProvider
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
# Request: "textDocument/documentHighlight"
# Param: DocumentHighlightParams
-def s:docHighlight(lspserver: dict<any>): void
+def s:DocHighlight(lspserver: dict<any>): void
# Check whether LSP server supports getting highlight information
if !lspserver.caps->has_key('documentHighlightProvider')
|| !lspserver.caps.documentHighlightProvider
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
# Request: "textDocument/documentSymbol"
# Param: DocumentSymbolParams
-def s:getDocSymbols(lspserver: dict<any>, fname: string): void
+def s:GetDocSymbols(lspserver: dict<any>, fname: string): void
# Check whether LSP server supports getting document symbol information
if !lspserver.caps->has_key('documentSymbolProvider')
|| !lspserver.caps.documentSymbolProvider
# or
# Request: "textDocument/rangeFormatting"
# Param: DocumentRangeFormattingParams
-def s:textDocFormat(lspserver: dict<any>, fname: string, rangeFormat: bool,
+def s:TextDocFormat(lspserver: dict<any>, fname: string, rangeFormat: bool,
start_lnum: number, end_lnum: number)
# Check whether LSP server supports formatting documents
if !lspserver.caps->has_key('documentFormattingProvider')
# Request: "textDocument/prepareCallHierarchy"
# Param: CallHierarchyPrepareParams
-def s:prepareCallHierarchy(lspserver: dict<any>, fname: string)
+def s:PrepareCallHierarchy(lspserver: dict<any>, fname: string)
# Check whether LSP server supports call hierarchy
if !lspserver.caps->has_key('callHierarchyProvider')
|| !lspserver.caps.callHierarchyProvider
# 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<any>, hierItem: dict<any>)
+def s:IncomingCalls(lspserver: dict<any>, hierItem: dict<any>)
# Check whether LSP server supports call hierarchy
if !lspserver.caps->has_key('callHierarchyProvider')
|| !lspserver.caps.callHierarchyProvider
# Request: "callHierarchy/outgoingCalls"
# Param: CallHierarchyItem
-def s:outgoingCalls(lspserver: dict<any>, hierItem: dict<any>)
+def s:OutgoingCalls(lspserver: dict<any>, hierItem: dict<any>)
# Check whether LSP server supports call hierarchy
if !lspserver.caps->has_key('callHierarchyProvider')
|| !lspserver.caps.callHierarchyProvider
# Request: "textDocument/rename"
# Param: RenameParams
-def s:renameSymbol(lspserver: dict<any>, newName: string)
+def s:RenameSymbol(lspserver: dict<any>, newName: string)
# Check whether LSP server supports rename operation
if !lspserver.caps->has_key('renameProvider')
|| !lspserver.caps.renameProvider
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
# Request: "textDocument/codeAction"
# Param: CodeActionParams
-def s:codeAction(lspserver: dict<any>, fname_arg: string)
+def s:CodeAction(lspserver: dict<any>, fname_arg: string)
# Check whether LSP server supports code action operation
if !lspserver.caps->has_key('codeActionProvider')
|| !lspserver.caps.codeActionProvider
# List project-wide symbols matching query string
# Request: "workspace/symbol"
# Param: WorkspaceSymbolParams
-def s:workspaceQuerySymbols(lspserver: dict<any>, query: string): bool
+def s:WorkspaceQuerySymbols(lspserver: dict<any>, query: string): bool
# Check whether the LSP server supports listing workspace symbols
if !lspserver.caps->has_key('workspaceSymbolProvider')
|| !lspserver.caps.workspaceSymbolProvider
# Add a workspace folder to the LSP server.
# Request: "workspace/didChangeWorkspaceFolders"
# Param: DidChangeWorkspaceFoldersParams
-def s:addWorkspaceFolder(lspserver: dict<any>, dirName: string): void
+def s:AddWorkspaceFolder(lspserver: dict<any>, dirName: string): void
if !lspserver.caps->has_key('workspace')
|| !lspserver.caps.workspace->has_key('workspaceFolders')
|| !lspserver.caps.workspace.workspaceFolders->has_key('supported')
# Remove a workspace folder from the LSP server.
# Request: "workspace/didChangeWorkspaceFolders"
# Param: DidChangeWorkspaceFoldersParams
-def s:removeWorkspaceFolder(lspserver: dict<any>, dirName: string): void
+def s:RemoveWorkspaceFolder(lspserver: dict<any>, dirName: string): void
if !lspserver.caps->has_key('workspace')
|| !lspserver.caps.workspace->has_key('workspaceFolders')
|| !lspserver.caps.workspace.workspaceFolders->has_key('supported')
# select the text around the current cursor location
# Request: "textDocument/selectionRange"
# Param: SelectionRangeParams
-def s:selectionRange(lspserver: dict<any>, fname: string)
+def s:SelectionRange(lspserver: dict<any>, fname: string)
# Check whether LSP server supports selection ranges
if !lspserver.caps->has_key('selectionRangeProvider')
|| !lspserver.caps.selectionRangeProvider
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<any>)
+def s:SelectionExpand(lspserver: dict<any>)
# Check whether LSP server supports selection ranges
if !lspserver.caps->has_key('selectionRangeProvider')
|| !lspserver.caps.selectionRangeProvider
enddef
# Shrink the previous selection or start a new one
-def s:selectionShrink(lspserver: dict<any>)
+def s:SelectionShrink(lspserver: dict<any>)
# Check whether LSP server supports selection ranges
if !lspserver.caps->has_key('selectionRangeProvider')
|| !lspserver.caps.selectionRangeProvider
# fold the entire document
# Request: "textDocument/foldingRange"
# Param: FoldingRangeParams
-def s:foldRange(lspserver: dict<any>, fname: string)
+def s:FoldRange(lspserver: dict<any>, fname: string)
# Check whether LSP server supports fold ranges
if !lspserver.caps->has_key('foldingRangeProvider')
|| !lspserver.caps.foldingRangeProvider
# Request the LSP server to execute a command
# Request: workspace/executeCommand
# Params: ExecuteCommandParams
-def s:executeCommand(lspserver: dict<any>, cmd: dict<any>)
+def s:ExecuteCommand(lspserver: dict<any>, cmd: dict<any>)
var req = lspserver.createRequest('workspace/executeCommand')
req.params->extend(cmd)
lspserver.sendMessage(req)
# Display the LSP server capabilities (received during the initialization
# stage).
-def s:showCapabilities(lspserver: dict<any>)
+def s:ShowCapabilities(lspserver: dict<any>)
echo "Capabilities of '" .. lspserver.path .. "' LSP server:"
for k in lspserver.caps->keys()->sort()
echo k .. ": " .. lspserver.caps[k]->string()
}
# 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
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
return skipRefresh
enddef
-def s:addSymbolText(bnr: number,
+def s:AddSymbolText(bnr: number,
symbolTypeTable: dict<list<dict<any>>>,
pfx: string,
text: list<string>,
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
# First two lines in the buffer display comment information
var lnumMap: list<dict<any>> = [{}, {}]
var text: list<string> = []
- 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}
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
enddef
# when the outline window is closed, do the cleanup
-def s:outlineCleanup()
+def s:OutlineCleanup()
# Remove the outline autocommands
:silent! autocmd! LSPOutline
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()
endif
# Visually (character-wise) select the text in a range
-def s:selectText(bnr: number, range: dict<dict<number>>)
+def s:SelectText(bnr: number, range: dict<dict<number>>)
var start_col: number = util.GetLineByteFromPos(bnr, range.start) + 1
var end_col: number = util.GetLineByteFromPos(bnr, range.end)
# 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<any>, level: number): dict<any>
+def s:GetSelRangeAtLevel(selRange: dict<any>, level: number): dict<any>
var r: dict<any> = selRange
var idx: number = 0
# Returns true if the current visual selection matches a range in the
# selection reply from LSP.
-def s:selectionFromLSP(range: dict<any>, startpos: list<number>, endpos: list<number>): bool
+def s:SelectionFromLSP(range: dict<any>, startpos: list<number>, endpos: list<number>): bool
return startpos[1] == range.start.line + 1
&& endpos[1] == range.end.line + 1
&& startpos[2] == range.start.character + 1
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')
# 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
endif
# close the signature popup window
-def s:closeSignaturePopup(lspserver: dict<any>)
+def s:CloseSignaturePopup(lspserver: dict<any>)
lspserver.signaturePopup->popup_close()
lspserver.signaturePopup = -1
enddef
-def s:closeCurBufSignaturePopup()
+def s:CloseCurBufSignaturePopup()
var lspserver: dict<any> = buf.CurbufGetServer()
if lspserver->empty()
return
endif
- s:closeSignaturePopup(lspserver)
+ s:CloseSignaturePopup(lspserver)
enddef
# Initialize the signature triggers for the current buffer
.. "<C-R>=LspShowSignature()<CR>"
endfor
# close the signature popup when leaving insert mode
- autocmd InsertLeave <buffer> call s:closeCurBufSignaturePopup()
+ autocmd InsertLeave <buffer> call s:CloseCurBufSignaturePopup()
enddef
# Display the symbol signature help
export def SignatureDisplay(lspserver: dict<any>, sighelp: dict<any>): 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
endif
# Handle keys pressed when the workspace symbol popup menu is displayed
-def s:filterSymbols(lspserver: dict<any>, popupID: number, key: string): bool
+def s:FilterSymbols(lspserver: dict<any>, popupID: number, key: string): bool
var key_handled: bool = false
var update_popup: bool = false
var query: string = lspserver.workspaceSymbolQuery
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 ''
# numbers.
# 'a': {'A': [lnum, col], 'B': [lnum, col]}
# 'b': {'A': [lnum, col], 'B': [lnum, col]}
-def s:edit_sort_func(a: dict<any>, b: dict<any>): number
+def s:Edit_sort_func(a: dict<any>, b: dict<any>): number
# line number
if a.A[0] != b.A[0]
return b.A[0] - a.A[0]
# 'new_lines' A list of strings to replace the original
#
# returns the modified 'lines'
-def s:set_lines(lines: list<string>, A: list<number>, B: list<number>,
+def s:Set_lines(lines: list<string>, A: list<number>, B: list<number>,
new_lines: list<string>): list<string>
var i_0: number = A[0]
# 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<string> = bnr->getbufline(start_line + 1, finish_line + 1)
var fix_eol: bool = bnr->getbufvar('&fixeol')
for e in updated_edits
var A: list<number> = [e.A[0] - start_line, e.A[1]]
var B: list<number> = [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)
enddef
# interface TextDocumentEdit
-def s:applyTextDocumentEdit(textDocEdit: dict<any>)
+def s:ApplyTextDocumentEdit(textDocEdit: dict<any>)
var bnr: number = bufnr(util.LspUriToFile(textDocEdit.textDocument.uri))
if bnr == -1
util.ErrMsg('Error: Text Document edit, buffer ' .. textDocEdit.textDocument.uri .. ' is not found')
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
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
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