\ 'args': ['--nthreads=1', '--use_signature_help', '--hover_signature']
\ }
\ ]
- call lsp#addServer(lspServers)
+ call LspAddServer(lspServers)
```
The above lines add the LSP servers for C, C++, Javascript, Typescript, Shell script, Vim script, Go and Python file types.
path|complete path to the LSP server executable (without any arguments).
args|a list of command-line arguments passed to the LSP server. Each argument is a separate List item.
-The LSP servers are added using the lsp#addServer() function. This function accepts a list of LSP servers with the above information.
+The LSP servers are added using the LspAddServer() function. This function accepts a list of LSP servers with the above information.
## Supported Commands
Command|Description
if opt.lspOptions.showSignature && caps->has_key('signatureHelpProvider')
var triggers = caps.signatureHelpProvider.triggerCharacters
for ch in triggers
- exe 'inoremap <buffer> <silent> ' .. ch .. ' ' .. ch .. "<C-R>=lsp#showSignature()<CR>"
+ exe 'inoremap <buffer> <silent> ' .. ch .. ' ' .. ch .. "<C-R>=LspShowSignature()<CR>"
endfor
endif
&& caps.documentHighlightProvider
# Highlight all the occurrences of the current keyword
augroup LSPBufferAutocmds
- autocmd CursorMoved <buffer> call lsp#docHighlightClear()
- | call lsp#docHighlight()
+ autocmd CursorMoved <buffer> call g:LspDocHighlightClear()
+ | call g:LspDocHighlight()
augroup END
endif
import './symbol.vim' as symbol_import
import './outline.vim' as outline_import
- opt.LspOptionsSet = opt_import.LspOptionsSet
opt.lspOptions = opt_import.lspOptions
lserver.NewLspServer = server_import.NewLspServer
util.WarnMsg = util_import.WarnMsg
outline.OpenOutlineWindow = outline_import.OpenOutlineWindow
outline.SkipOutlineRefresh = outline_import.SkipOutlineRefresh
else
- import {lspOptions, LspOptionsSet} from './lspoptions.vim'
+ import {lspOptions} from './lspoptions.vim'
import NewLspServer from './lspserver.vim'
import {WarnMsg,
ErrMsg,
import ShowSymbolMenu from './symbol.vim'
import {OpenOutlineWindow, SkipOutlineRefresh} from './outline.vim'
- opt.LspOptionsSet = LspOptionsSet
opt.lspOptions = lspOptions
lserver.NewLspServer = NewLspServer
util.WarnMsg = WarnMsg
var lspInitializedOnce = false
-# Set user configurable LSP options
-def lsp#setOptions(lspOpts: dict<any>)
- opt.LspOptionsSet(lspOpts)
-enddef
-
def s:lspInitOnce()
# Signs used for LSP diagnostics
sign_define([{name: 'LspDiagError', text: 'E ', texthl: 'ErrorMsg',
ftypeOmniCtrlMap->extend({[ftype]: enabled})
enddef
-def lsp#enableServerTrace()
+export def EnableServerTrace()
util.ClearTraceLogs()
util.ServerTrace(true)
enddef
# Show information about all the LSP servers
-def lsp#showServers()
+export def ShowServers()
for [ftype, lspserver] in ftypeServerMap->items()
var msg = ftype .. " "
if lspserver.running
enddef
# Go to a definition using "textDocument/definition" LSP request
-def lsp#gotoDefinition(peek: bool)
+export def GotoDefinition(peek: bool)
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# Go to a declaration using "textDocument/declaration" LSP request
-def lsp#gotoDeclaration(peek: bool)
+export def GotoDeclaration(peek: bool)
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# Go to a type definition using "textDocument/typeDefinition" LSP request
-def lsp#gotoTypedef(peek: bool)
+export def GotoTypedef(peek: bool)
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# Go to a implementation using "textDocument/implementation" LSP request
-def lsp#gotoImplementation(peek: bool)
+export def GotoImplementation(peek: bool)
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
# Show the signature using "textDocument/signatureHelp" LSP method
# Invoked from an insert-mode mapping, so return an empty string.
-def lsp#showSignature(): string
+def g:LspShowSignature(): string
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return ''
enddef
# buffer change notification listener
-def lsp#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> = s:curbufGetServer()
if lspserver->empty() || !lspserver.running
return
enddef
# Called after leaving insert mode. Used to process diag messages (if any)
-def lsp#leftInsertMode()
+def g:LspLeftInsertMode()
if !exists('b:LspDiagsUpdatePending')
return
endif
enddef
# A new buffer is opened. If LSP is supported for this buffer, then add it
-def lsp#addFile(bnr: number): void
+export def AddFile(bnr: number): void
if bufnrToServer->has_key(bnr)
# LSP server for this buffer is already initialized and running
return
lspserver.textdocDidOpen(bnr, ftype)
# add a listener to track changes to this buffer
- listener_add(function('lsp#bufchange_listener'), bnr)
+ listener_add(function('s:bufchange_listener'), bnr)
# set options for insert mode completion
if opt.lspOptions.autoComplete
endif
else
if s:lspOmniComplEnabled(ftype)
- setbufvar(bnr, '&omnifunc', 'lsp#omniFunc')
+ setbufvar(bnr, '&omnifunc', 'LspOmniFunc')
endif
endif
- setbufvar(bnr, '&balloonexpr', 'LspDiagExpr()')
+ setbufvar(bnr, '&balloonexpr', 'g:LspDiagExpr()')
# map characters that trigger signature help
if opt.lspOptions.showSignature &&
var triggers = lspserver.caps.signatureHelpProvider.triggerCharacters
for ch in triggers
exe 'inoremap <buffer> <silent> ' .. ch .. ' ' .. ch
- .. "<C-R>=lsp#showSignature()<CR>"
+ .. "<C-R>=LspShowSignature()<CR>"
endfor
endif
if opt.lspOptions.autoComplete
# Trigger 24x7 insert mode completion when text is changed
- exe 'autocmd TextChangedI <buffer=' .. bnr .. '> call lsp#complete()'
+ exe 'autocmd TextChangedI <buffer=' .. bnr .. '> call LspComplete()'
endif
# Update the diagnostics when insert mode is stopped
- exe 'autocmd InsertLeave <buffer=' .. bnr .. '> call lsp#leftInsertMode()'
+ exe 'autocmd InsertLeave <buffer=' .. bnr .. '> call LspLeftInsertMode()'
if opt.lspOptions.autoHighlight &&
lspserver.caps->has_key('documentHighlightProvider')
&& lspserver.caps.documentHighlightProvider
# Highlight all the occurrences of the current keyword
exe 'autocmd CursorMoved <buffer=' .. bnr .. '> '
- .. 'call lsp#docHighlightClear() | call lsp#docHighlight()'
+ .. 'call LspDocHighlightClear() | call LspDocHighlight()'
endif
augroup END
enddef
# Notify LSP server to remove a file
-def lsp#removeFile(bnr: number): void
+export def RemoveFile(bnr: number): void
var lspserver: dict<any> = s:bufGetServer(bnr)
if lspserver->empty() || !lspserver.running
return
enddef
# Stop all the LSP servers
-def lsp#stopAllServers()
+export def StopAllServers()
for lspserver in lspServers
if lspserver.running
lspserver.stopServer()
enddef
# Register a LSP server for one or more file types
-def lsp#addServer(serverList: list<dict<any>>)
+export def AddServer(serverList: list<dict<any>>)
for server in serverList
if !server->has_key('filetype') || !server->has_key('path')
util.ErrMsg('Error: LSP server information is missing filetype or path')
# The LSP server is considered ready when the server capabilities are
# received ('initialize' LSP reply message)
-def lsp#serverReady(): bool
+export def ServerReady(): bool
var fname: string = @%
if fname == ''
return false
# set the LSP server trace level for the current buffer
# Params: SetTraceParams
-def lsp#setTraceServer(traceVal: string)
+export def SetTraceServer(traceVal: string)
if ['off', 'message', 'verbose']->index(traceVal) == -1
util.ErrMsg("Error: Unsupported LSP server trace value " .. traceVal)
return
# Display the diagnostic messages from the LSP server for the current buffer
# in a quickfix list
-def lsp#showDiagnostics(): void
+export def ShowDiagnostics(): void
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# Show the diagnostic message for the current line
-def lsp#showCurrentDiag()
+export def LspShowCurrentDiag()
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# Display the diagnostics for the current line in the status line.
-def lsp#showCurrentDiagInStatusLine()
+export def LspShowCurrentDiagInStatusLine()
var fname: string = @%
if fname == ''
return
enddef
# get the count of diagnostics in the current buffer
-def lsp#errorCount(): dict<number>
+export def ErrorCount(): dict<number>
var res = {'Error': 0, 'Warn': 0, 'Info': 0, 'Hint': 0}
var fname: string = @%
if fname == ''
enddef
# jump to the next/previous/first diagnostic message in the current buffer
-def lsp#jumpToDiag(which: string): void
+export def JumpToDiag(which: string): void
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
# Insert mode completion handler. Used when 24x7 completion is enabled
# (default).
-def lsp#complete()
+def g:LspComplete()
var lspserver: dict<any> = s:curbufGetServer()
if lspserver->empty() || !lspserver.running || !lspserver.ready
return
enddef
# omni complete handler
-def lsp#omniFunc(findstart: number, base: string): any
+def g:LspOmniFunc(findstart: number, base: string): any
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return -2
# Display the hover message from the LSP server for the current cursor
# location
-def lsp#hover()
+export def Hover()
var lspserver: dict<any> = s:curbufGetServer()
if lspserver->empty() || !lspserver.running || !lspserver.ready
return
enddef
# show symbol references
-def lsp#showReferences(peek: bool)
+export def ShowReferences(peek: bool)
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# highlight all the places where a symbol is referenced
-def lsp#docHighlight()
+def g:LspDocHighlight()
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# clear the symbol reference highlight
-def lsp#docHighlightClear()
+def g:LspDocHighlightClear()
prop_remove({'type': 'LspTextRef', 'all': true}, 1, line('$'))
prop_remove({'type': 'LspReadRef', 'all': true}, 1, line('$'))
prop_remove({'type': 'LspWriteRef', 'all': true}, 1, line('$'))
enddef
-def lsp#requestDocSymbols()
+def g:LspRequestDocSymbols()
if outline.SkipOutlineRefresh()
return
endif
enddef
# open a window and display all the symbols in a file (outline)
-def lsp#outline()
+export def Outline()
outline.OpenOutlineWindow()
- lsp#requestDocSymbols()
+ g:LspRequestDocSymbols()
enddef
# Format the entire file
-def lsp#textDocFormat(range_args: number, line1: number, line2: number)
+export def TextDocFormat(range_args: number, line1: number, line2: number)
if !&modifiable
util.ErrMsg('Error: Current file is not a modifiable file')
return
# Display all the locations where the current symbol is called from.
# Uses LSP "callHierarchy/incomingCalls" request
-def lsp#incomingCalls()
+export def IncomingCalls()
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
# Display all the symbols used by the current symbol.
# Uses LSP "callHierarchy/outgoingCalls" request
-def lsp#outgoingCalls()
+export def OutgoingCalls()
:echomsg 'Error: Not implemented yet'
enddef
# Rename a symbol
# Uses LSP "textDocument/rename" request
-def lsp#rename()
+export def Rename()
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
# Perform a code action
# Uses LSP "textDocument/codeAction" request
-def lsp#codeAction()
+export def CodeAction()
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
# Perform a workspace wide symbol lookup
# Uses LSP "workspace/symbol" request
-def lsp#symbolSearch(queryArg: string)
+export def SymbolSearch(queryArg: string)
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# Display the list of workspace folders
-def lsp#listWorkspaceFolders()
+export def ListWorkspaceFolders()
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# Add a workspace folder. Default is to use the current folder.
-def lsp#addWorkspaceFolder(dirArg: string)
+export def AddWorkspaceFolder(dirArg: string)
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# Remove a workspace folder. Default is to use the current folder.
-def lsp#removeWorkspaceFolder(dirArg: string)
+export def RemoveWorkspaceFolder(dirArg: string)
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# visually select a range of positions around the current cursor.
-def lsp#selectionRange()
+export def SelectionRange()
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# fold the entire document
-def lsp#foldDocument()
+export def FoldDocument()
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
enddef
# Enable diagnostic highlighting for all the buffers
-def lsp#diagHighlightEnable()
+export def DiagHighlightEnable()
diag.DiagsHighlightEnable()
enddef
# Disable diagnostic highlighting for all the buffers
-def lsp#diagHighlightDisable()
+export def DiagHighlightDisable()
diag.DiagsHighlightDisable()
enddef
# Display the LSP server capabilities
-def lsp#showServerCapabilities()
+export def ShowServerCapabilities()
var lspserver: dict<any> = s:curbufGetServerChecked()
if lspserver->empty()
return
vim9script
# LSP plugin options
-# User can override these by calling the lsp#setOptions() function.
+# User can override these by calling the LspOptionsSet() function.
export var lspOptions: dict<any> = {
# In insert mode, complete the current symbol automatically
# Otherwise, use omni-completion
else
import GetLineByteFromPos from './util.vim'
import lspOptions from './lspoptions.vim'
+
util.GetLineByteFromPos = GetLineByteFromPos
opt.lspOptions = lspOptions
endif
augroup LSPOutline
au!
- autocmd BufEnter * call lsp#requestDocSymbols()
+ 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()
==============================================================================
4. Configuration *lsp-configuration*
-To register one or more LSP servers, use the lsp#addServer() function with a
+To register one or more LSP servers, use the LspAddServer() function with a
list of LSP server details in the .vimrc file.
For example, to add the LSP servers for the Javascript, Typescript and Python
\ 'args': ['--check-parent-process', '-v']
\ }
\ ]
- call lsp#addServer(lspServers)
+ call LspAddServer(lspServers)
<
Depending on the location of the typescript and python pyls language servers
installed in your system, update the 'path' in the above snippet
\ args: ['--stdio']
\ }
\ ]
- call lsp#addServer(lspServers)
+ call LspAddServer(lspServers)
<
To add a LSP server, the following information is needed:
omnicompl a boolean value that enables (true) or disables
(false) omni-completion for this file type.
-The LSP servers are added using the lsp#addServer() function. This function
+The LSP servers are added using the LspAddServer() function. This function
accepts a list of LSP servers with the above information.
*lsp-options*
Some of the LSP plugin features can be enabled or disabled by using the
-lsp#setOptions() function. This function accepts a dictionary argument with the
+LspOptionsSet() function. This function accepts a dictionary argument with the
following optional items:
autoComplete In insert mode, automatically complete the current
For example, to disable the automatic placement of signs for the LSP
diagnostic messages, you can add the following line to your .vimrc file:
- call lsp#setOptions({'autoHighlightDiags': v:false})
+ call LspOptionsSet({'autoHighlightDiags': v:false})
==============================================================================
5. Commands *lsp-commands*
*:LspShowServers*
:LspShowServers Displays the list of registered LSP servers and their
status. The LSP servers are registered using the
- lsp#addServer() function. The output shows the Vim
+ LspAddServer() function. The output shows the Vim
file type, the corresponding LSP server status and the
path to the LSP server executable.
this, you can set the showSignature option to false in
your .vimrc file: >
- call lsp#setOptions({'showSignature': v:false})
+ call LspOptionsSet({'showSignature': v:false})
<
Default is true.
You can get the function signature echoed in cmdline
rather than displayed in popup if you use >
- call lsp#setOptions({'echoSignature': v:true})
+ call LspOptionsSet({'echoSignature': v:true})
<
Default is false.
documentation in the preview window instead of in a
popup set >
- call lsp#setOptions({'hoverInPreview': v:true})
+ call LspOptionsSet({'hoverInPreview': v:true})
<
Default is false
To disable the auto-compeltion, you can set the autoComplete option to v:false
in your .vimrc file: >
- call lsp#setOptions({'autoComplete': v:false})
+ call LspOptionsSet({'autoComplete': v:false})
<
If this variable is set, then the LSP plugin doesn't automatically start
completion in insert mode and instead supports omni-completion (|compl-omni|).
endif
var opt = {}
-if has('patch-8.2.4019')
+var lspf = {}
+if has('patch-8.2.4257')
+ import '../autoload/lspoptions.vim' as lspoptions
+ import autoload 'lsp.vim'
+
+ opt.LspOptionsSet = lspoptions.LspOptionsSet
+ opt.lspOptions = lspoptions.lspOptions
+ lspf.enableServerTrace = lsp.EnableServerTrace
+ lspf.addServer = lsp.AddServer
+ lspf.LspServerReady = lsp.ServerReady
+ lspf.addFile = lsp.AddFile
+ lspf.removeFile = lsp.RemoveFile
+ lspf.showCurrentDiagInStatusLine = lsp.LspShowCurrentDiagInStatusLine
+ lspf.showServers = lsp.ShowServers
+ lspf.showServerCapabilities = lsp.ShowServerCapabilities
+ lspf.setTraceServer = lsp.SetTraceServer
+ lspf.gotoDefinition = lsp.GotoDefinition
+ lspf.gotoDeclaration = lsp.GotoDeclaration
+ lspf.gotoTypedef = lsp.GotoTypedef
+ lspf.gotoImplementation = lsp.GotoImplementation
+ lspf.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.outgoingCalls = lsp.OutgoingCalls
+ lspf.rename = lsp.Rename
+ lspf.codeAction = lsp.CodeAction
+ lspf.symbolSearch = lsp.SymbolSearch
+ lspf.hover = lsp.Hover
+ lspf.selectionRange = lsp.SelectionRange
+ lspf.foldDocument = lsp.FoldDocument
+ lspf.listWorkspaceFolders = lsp.ListWorkspaceFolders
+ lspf.addWorkspaceFolder = lsp.AddWorkspaceFolder
+ lspf.removeWorkspaceFolder = lsp.RemoveWorkspaceFolder
+elseif has('patch-8.2.4019')
import '../autoload/lspoptions.vim' as opt_import
+ import '../autoload/lsp.vim' as lsp_import
+
+ opt.LspOptionsSet = opt_import.LspOptionsSet
opt.lspOptions = opt_import.lspOptions
+ lspf.enableServerTrace = lsp_import.EnableServerTrace
+ lspf.addServer = lsp_import.AddServer
+ lspf.LspServerReady = lsp_import.ServerReady
+ lspf.addFile = lsp_import.AddFile
+ lspf.removeFile = lsp_import.RemoveFile
+ lspf.showCurrentDiagInStatusLine = lsp_import.LspShowCurrentDiagInStatusLine
+ lspf.showServers = lsp_import.ShowServers
+ lspf.showServerCapabilities = lsp_import.ShowServerCapabilities
+ lspf.setTraceServer = lsp_import.SetTraceServer
+ lspf.gotoDefinition = lsp_import.GotoDefinition
+ lspf.gotoDeclaration = lsp_import.GotoDeclaration
+ lspf.gotoTypedef = lsp_import.GotoTypedef
+ lspf.gotoImplementation = lsp_import.GotoImplementation
+ lspf.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
+ lspf.outgoingCalls = lsp_import.OutgoingCalls
+ lspf.rename = lsp_import.Rename
+ lspf.codeAction = lsp_import.CodeAction
+ lspf.symbolSearch = lsp_import.SymbolSearch
+ lspf.hover = lsp_import.Hover
+ lspf.selectionRange = lsp_import.SelectionRange
+ lspf.foldDocument = lsp_import.FoldDocument
+ lspf.listWorkspaceFolders = lsp_import.ListWorkspaceFolders
+ lspf.addWorkspaceFolder = lsp_import.AddWorkspaceFolder
+ lspf.removeWorkspaceFolder = lsp_import.RemoveWorkspaceFolder
else
- import lspOptions from '../autoload/lspoptions.vim'
+ import {lspOptions, LspOptionsSet} from '../autoload/lspoptions.vim'
+ import {EnableServerTrace,
+ AddServer,
+ ServerReady,
+ AddFile,
+ RemoveFile,
+ LspShowCurrentDiagInStatusLine,
+ ShowServers,
+ ShowServerCapabilities,
+ SetTraceServer,
+ GotoDefinition,
+ GotoDeclaration,
+ GotoTypedef,
+ GotoImplementation,
+ ShowDiagnostics,
+ LspShowCurrentDiag,
+ JumpToDiag,
+ DiagHighlightEnable,
+ DiagHighlightDisable,
+ ShowReferences,
+ Outline,
+ TextDocFormat,
+ IncomingCalls,
+ OutgoingCalls,
+ Rename,
+ CodeAction,
+ SymbolSearch,
+ Hover,
+ SelectionRange,
+ FoldDocument,
+ ListWorkspaceFolders,
+ AddWorkspaceFolder,
+ RemoveWorkspaceFolder} from '../autoload/lsp.vim'
+
+ opt.LspOptionsSet = LspOptionsSet
opt.lspOptions = lspOptions
+ lspf.enableServerTrace = EnableServerTrace
+ lspf.addServer = AddServer
+ lspf.LspServerReady = ServerReady
+ lspf.addFile = AddFile
+ lspf.removeFile = RemoveFile
+ lspf.showCurrentDiagInStatusLine = LspShowCurrentDiagInStatusLine
+ lspf.showServers = ShowServers
+ lspf.showServerCapabilities = ShowServerCapabilities
+ lspf.setTraceServer = SetTraceServer
+ lspf.gotoDefinition = GotoDefinition
+ lspf.gotoDeclaration = GotoDeclaration
+ lspf.gotoTypedef = GotoTypedef
+ lspf.gotoImplementation = GotoImplementation
+ lspf.gotoDefinition = GotoDefinition
+ lspf.gotoDeclaration = GotoDeclaration
+ lspf.gotoTypedef = GotoTypedef
+ lspf.gotoImplementation = GotoImplementation
+ lspf.showDiagnostics = ShowDiagnostics
+ lspf.showCurrentDiag = LspShowCurrentDiag
+ lspf.jumpToDiag = JumpToDiag
+ lspf.jumpToDiag = JumpToDiag
+ lspf.jumpToDiag = JumpToDiag
+ lspf.diagHighlightEnable = DiagHighlightEnable
+ lspf.diagHighlightDisable = DiagHighlightDisable
+ lspf.showReferences = ShowReferences
+ lspf.showReferences = ShowReferences
+ lspf.outline = Outline
+ lspf.textDocFormat = TextDocFormat
+ lspf.incomingCalls = IncomingCalls
+ lspf.outgoingCalls = OutgoingCalls
+ lspf.rename = Rename
+ lspf.codeAction = CodeAction
+ lspf.symbolSearch = SymbolSearch
+ lspf.hover = Hover
+ lspf.selectionRange = SelectionRange
+ lspf.foldDocument = FoldDocument
+ lspf.listWorkspaceFolders = ListWorkspaceFolders
+ lspf.addWorkspaceFolder = AddWorkspaceFolder
+ lspf.removeWorkspaceFolder = RemoveWorkspaceFolder
endif
+g:LspOptionsSet = s:opt.LspOptionsSet
+g:LspServerTraceEnable = s:lspf.enableServerTrace
+
+def g:LspAddServer(serverList: list<dict<any>>)
+ lspf.addServer(serverList)
+enddef
+
+def g:LspServerReady(): bool
+ return lspf.LspServerReady()
+enddef
+
+var TshowServers = s:lspf.showServers
+var TshowServerCapabilities = s:lspf.showServerCapabilities
+var TsetTraceServer = s:lspf.setTraceServer
+var TaddFile = s:lspf.addFile
+var TremoveFile = s:lspf.removeFile
+var TshowCurrentDiagInStatusLine = s:lspf.showCurrentDiagInStatusLine
+var TgotoDefinition = s:lspf.gotoDefinition
+var TgotoDeclaration = s:lspf.gotoDeclaration
+var TgotoTypedef = s:lspf.gotoTypedef
+var TgotoImplementation = s:lspf.gotoImplementation
+var TshowDiagnostics = s:lspf.showDiagnostics
+var TshowCurrentDiag = s:lspf.showCurrentDiag
+var TjumpToDiag = s:lspf.jumpToDiag
+var TdiagHighlightEnable = s:lspf.diagHighlightEnable
+var TdiagHighlightDisable = s:lspf.diagHighlightDisable
+var TshowReferences = s:lspf.showReferences
+var Toutline = s:lspf.outline
+var TtextDocFormat = s:lspf.textDocFormat
+var TincomingCalls = s:lspf.incomingCalls
+var ToutgoingCalls = s:lspf.outgoingCalls
+var Trename = s:lspf.rename
+var TcodeAction = s:lspf.codeAction
+var TsymbolSearch = s:lspf.symbolSearch
+var Thover = s:lspf.hover
+var TselectionRange = s:lspf.selectionRange
+var TfoldDocument = s:lspf.foldDocument
+var TlistWorkspaceFolders = s:lspf.listWorkspaceFolders
+var TaddWorkspaceFolder = s:lspf.addWorkspaceFolder
+var TremoveWorkspaceFolder = s:lspf.removeWorkspaceFolder
+
augroup LSPAutoCmds
au!
- autocmd BufNewFile,BufReadPost * lsp#addFile(expand('<abuf>')->str2nr())
+ autocmd BufNewFile,BufReadPost * TaddFile(expand('<abuf>')->str2nr())
# Note that when BufWipeOut is invoked, the current buffer may be different
# from the buffer getting wiped out.
- autocmd BufWipeOut * lsp#removeFile(expand('<abuf>')->str2nr())
+ autocmd BufWipeOut * TremoveFile(expand('<abuf>')->str2nr())
if opt.lspOptions.showDiagOnStatusLine
- autocmd CursorMoved * lsp#showCurrentDiagInStatusLine()
+ autocmd CursorMoved * TshowCurrentDiagInStatusLine()
endif
augroup END
# TODO: Is it needed to shutdown all the LSP servers when exiting Vim?
# This takes some time.
-# autocmd VimLeavePre * call lsp#stopAllServers()
+# autocmd VimLeavePre * call TstopAllServers()
# LSP commands
-command! -nargs=0 -bar LspShowServers call lsp#showServers()
-command! -nargs=0 -bar LspShowServerCapabilities call lsp#showServerCapabilities()
-command! -nargs=1 -bar LspSetTrace call lsp#setTraceServer(<q-args>)
-command! -nargs=0 -bar LspGotoDefinition call lsp#gotoDefinition(v:false)
-command! -nargs=0 -bar LspGotoDeclaration call lsp#gotoDeclaration(v:false)
-command! -nargs=0 -bar LspGotoTypeDef call lsp#gotoTypedef(v:false)
-command! -nargs=0 -bar LspGotoImpl call lsp#gotoImplementation(v:false)
-command! -nargs=0 -bar LspPeekDefinition call lsp#gotoDefinition(v:true)
-command! -nargs=0 -bar LspPeekDeclaration call lsp#gotoDeclaration(v:true)
-command! -nargs=0 -bar LspPeekTypeDef call lsp#gotoTypedef(v:true)
-command! -nargs=0 -bar LspPeekImpl call lsp#gotoImplementation(v:true)
-command! -nargs=0 -bar LspShowSignature call lsp#showSignature()
-command! -nargs=0 -bar LspDiagShow call lsp#showDiagnostics()
-command! -nargs=0 -bar LspDiagCurrent call lsp#showCurrentDiag()
-command! -nargs=0 -bar LspDiagFirst call lsp#jumpToDiag('first')
-command! -nargs=0 -bar LspDiagNext call lsp#jumpToDiag('next')
-command! -nargs=0 -bar LspDiagPrev call lsp#jumpToDiag('prev')
-command! -nargs=0 -bar LspDiagHighlightEnable call lsp#diagHighlightEnable()
-command! -nargs=0 -bar LspDiagHighlightDisable call lsp#diagHighlightDisable()
-command! -nargs=0 -bar LspShowReferences call lsp#showReferences(v:false)
-command! -nargs=0 -bar LspPeekReferences call lsp#showReferences(v:true)
-command! -nargs=0 -bar LspHighlight call lsp#docHighlight()
-command! -nargs=0 -bar LspHighlightClear call lsp#docHighlightClear()
-command! -nargs=0 -bar LspOutline call lsp#outline()
-command! -nargs=0 -bar -range=% LspFormat call lsp#textDocFormat(<range>, <line1>, <line2>)
-command! -nargs=0 -bar LspCalledBy call lsp#incomingCalls()
-command! -nargs=0 -bar LspCalling call lsp#outgoingCalls()
-command! -nargs=0 -bar LspRename call lsp#rename()
-command! -nargs=0 -bar LspCodeAction call lsp#codeAction()
-command! -nargs=? -bar LspSymbolSearch call lsp#symbolSearch(<q-args>)
-command! -nargs=0 -bar LspHover call lsp#hover()
-command! -nargs=0 -bar LspSelectionRange call lsp#selectionRange()
-command! -nargs=0 -bar LspFold call lsp#foldDocument()
-command! -nargs=0 -bar LspWorkspaceListFolders call lsp#listWorkspaceFolders()
-command! -nargs=1 -bar -complete=dir LspWorkspaceAddFolder call lsp#addWorkspaceFolder(<q-args>)
-command! -nargs=1 -bar -complete=dir LspWorkspaceRemoveFolder call lsp#removeWorkspaceFolder(<q-args>)
+command! -nargs=0 -bar LspShowServers call s:TshowServers()
+command! -nargs=0 -bar LspShowServerCapabilities call s:TshowServerCapabilities()
+command! -nargs=1 -bar LspSetTrace call TsetTraceServer(<q-args>)
+command! -nargs=0 -bar LspGotoDefinition call TgotoDefinition(v:false)
+command! -nargs=0 -bar LspGotoDeclaration call TgotoDeclaration(v:false)
+command! -nargs=0 -bar LspGotoTypeDef call TgotoTypedef(v:false)
+command! -nargs=0 -bar LspGotoImpl call TgotoImplementation(v:false)
+command! -nargs=0 -bar LspPeekDefinition call TgotoDefinition(v:true)
+command! -nargs=0 -bar LspPeekDeclaration call TgotoDeclaration(v:true)
+command! -nargs=0 -bar LspPeekTypeDef call TgotoTypedef(v:true)
+command! -nargs=0 -bar LspPeekImpl call TgotoImplementation(v:true)
+command! -nargs=0 -bar LspShowSignature call LspShowSignature()
+command! -nargs=0 -bar LspDiagShow call TshowDiagnostics()
+command! -nargs=0 -bar LspDiagCurrent call TshowCurrentDiag()
+command! -nargs=0 -bar LspDiagFirst call TjumpToDiag('first')
+command! -nargs=0 -bar LspDiagNext call TjumpToDiag('next')
+command! -nargs=0 -bar LspDiagPrev call TjumpToDiag('prev')
+command! -nargs=0 -bar LspDiagHighlightEnable call TdiagHighlightEnable()
+command! -nargs=0 -bar LspDiagHighlightDisable call TdiagHighlightDisable()
+command! -nargs=0 -bar LspShowReferences call s:TshowReferences(v:false)
+command! -nargs=0 -bar LspPeekReferences call s:TshowReferences(v:true)
+command! -nargs=0 -bar LspHighlight call LspDocHighlight()
+command! -nargs=0 -bar LspHighlightClear call LspDocHighlightClear()
+command! -nargs=0 -bar LspOutline call Toutline()
+command! -nargs=0 -bar -range=% LspFormat call TtextDocFormat(<range>, <line1>, <line2>)
+command! -nargs=0 -bar LspCalledBy call TincomingCalls()
+command! -nargs=0 -bar LspCalling call ToutgoingCalls()
+command! -nargs=0 -bar LspRename call Trename()
+command! -nargs=0 -bar LspCodeAction call TcodeAction()
+command! -nargs=? -bar LspSymbolSearch call TsymbolSearch(<q-args>)
+command! -nargs=0 -bar LspHover call Thover()
+command! -nargs=0 -bar LspSelectionRange call TselectionRange()
+command! -nargs=0 -bar LspFold call TfoldDocument()
+command! -nargs=0 -bar LspWorkspaceListFolders call TlistWorkspaceFolders()
+command! -nargs=1 -bar -complete=dir LspWorkspaceAddFolder call TaddWorkspaceFolder(<q-args>)
+command! -nargs=1 -bar -complete=dir LspWorkspaceRemoveFolder call TremoveWorkspaceFolder(<q-args>)
# Add the GUI menu entries
if has('gui_running')
- anoremenu <silent> L&sp.Goto.Definition :call lsp#gotoDefinition(v:false)<CR>
- anoremenu <silent> L&sp.Goto.Declaration :call lsp#gotoDeclaration(v:false)<CR>
- anoremenu <silent> L&sp.Goto.Implementation :call lsp#gotoImplementation(v:false)<CR>
- anoremenu <silent> L&sp.Goto.TypeDef :call lsp#gotoTypedef(v:false)<CR>
+ anoremenu <silent> L&sp.Goto.Definition :LspGotoDefinition<CR>
+ anoremenu <silent> L&sp.Goto.Declaration :LspGotoDeclaration<CR>
+ anoremenu <silent> L&sp.Goto.Implementation :LspGotoImpl<CR>
+ anoremenu <silent> L&sp.Goto.TypeDef :LspGotoTypeDef<CR>
- anoremenu <silent> L&sp.Show\ Signature :call lsp#showSignature()<CR>
- anoremenu <silent> L&sp.Show\ References :call lsp#showReferences(v:false)<CR>
- anoremenu <silent> L&sp.Show\ Detail :call lsp#hover()<CR>
- anoremenu <silent> L&sp.Outline :call lsp#outline()<CR>
+ anoremenu <silent> L&sp.Show\ Signature :LspShowSignature<CR>
+ anoremenu <silent> L&sp.Show\ References :LspShowReferences<CR>
+ anoremenu <silent> L&sp.Show\ Detail :LspHover<CR>
+ anoremenu <silent> L&sp.Outline :LspOutline<CR>
- anoremenu <silent> L&sp.Symbol\ Search :call lsp#symbolSearch('')<CR>
- anoremenu <silent> L&sp.CalledBy :call lsp#incomingCalls()<CR>
- anoremenu <silent> L&sp.Calling :call lsp#outgoingCalls()<CR>
- anoremenu <silent> L&sp.Rename :call lsp#rename()<CR>
- anoremenu <silent> L&sp.Code\ Action :call lsp#codeAction()<CR>
+ anoremenu <silent> L&sp.Symbol\ Search :LspSymbolSearch<CR>
+ anoremenu <silent> L&sp.CalledBy :LspCalledBy<CR>
+ anoremenu <silent> L&sp.Calling :LspCalling<CR>
+ anoremenu <silent> L&sp.Rename :LspRename<CR>
+ anoremenu <silent> L&sp.Code\ Action :LspCodeAction<CR>
- anoremenu <silent> L&sp.Highlight\ Symbol :call lsp#docHighlight()<CR>
- anoremenu <silent> L&sp.Highlight\ Clear :call lsp#docHighlightClear()<CR>
+ anoremenu <silent> L&sp.Highlight\ Symbol :LspHighlight<CR>
+ anoremenu <silent> L&sp.Highlight\ Clear :LspHighlightClear<CR>
# Diagnostics
- anoremenu <silent> L&sp.Diagnostics.Current :call lsp#showCurrentDiag<CR>
- anoremenu <silent> L&sp.Diagnostics.Show\ All :call lsp#showDiagnostics()<CR>
- anoremenu <silent> L&sp.Diagnostics.First :call lsp#jumpToDiag('first')<CR>
- anoremenu <silent> L&sp.Diagnostics.Next :call lsp#jumpToDiag('next')<CR>
- anoremenu <silent> L&sp.Diagnostics.Prev :call lsp#jumpToDiag('prev')<CR>
+ anoremenu <silent> L&sp.Diagnostics.Current :LspDiagCurrent<CR>
+ anoremenu <silent> L&sp.Diagnostics.Show\ All :LspDiagShow<CR>
+ anoremenu <silent> L&sp.Diagnostics.First :LspDiagFirst<CR>
+ anoremenu <silent> L&sp.Diagnostics.Next :LspDiagNext<CR>
+ anoremenu <silent> L&sp.Diagnostics.Prev :LspDiagPrev<CR>
if &mousemodel =~ 'popup'
anoremenu <silent> PopUp.L&sp.Go\ to\ Definition
- \ :call lsp#gotoDefinition(v:false)<CR>
+ \ :LspGotoDefinition<CR>
anoremenu <silent> PopUp.L&sp.Go\ to\ Declaration
- \ :call lsp#gotoDeclaration(v:false)<CR>
+ \ :LspGotoDeclaration<CR>
anoremenu <silent> Popup.L&sp.Find\ All\ References
- \ :call lsp#showReferences(v:false)<CR>
+ \ :LspShowReferences<CR>
anoremenu <silent> PopUp.L&sp.Show\ Detail
- \ :call lsp#hover()<CR>
+ \ :LspHover<CR>
anoremenu <silent> PopUp.L&sp.Highlight\ Symbol
- \ :call lsp#docHighlight()<CR>
+ \ :LspHighlight<CR>
anoremenu <silent> PopUp.L&sp.Highlight\ Clear
- \ :call lsp#docHighlightClear()<CR>
+ \ :LspHighlightClear<CR>
endif
endif
profile! file */lsp/*
endif
-set rtp+=../
-source ../plugin/lsp.vim
+set packpath+=../../../../../
+packadd lsp
var lspServers = [{
filetype: ['c', 'cpp'],
path: '/usr/bin/clangd-12',
args: ['--background-index', '--clang-tidy']
}]
-lsp#addServer(lspServers)
+call LspAddServer(lspServers)
g:LSPTest = true
cursor(1, 13)
:LspHighlight
:sleep 1
- assert_equal([{'id': 0, 'col': 13, 'type_bufnr': 0, 'end': 1, 'type': 'LspTextRef', 'length': 3, 'start': 1}], prop_list(1))
- assert_equal([{'id': 0, 'col': 11, 'type_bufnr': 0, 'end': 1, 'type': 'LspReadRef', 'length': 3, 'start': 1}], prop_list(3))
- assert_equal([{'id': 0, 'col': 3, 'type_bufnr': 0, 'end': 1, 'type': 'LspWriteRef', 'length': 3, 'start': 1}], prop_list(4))
+ var expected: dict<any>
+ expected = {id: 0, col: 13, end: 1, type: 'LspTextRef', length: 3, start: 1}
+ if has('patch-8.2.3233')
+ expected.type_bufnr = 0
+ endif
+ assert_equal([expected], prop_list(1))
+ expected = {id: 0, col: 11, end: 1, type: 'LspReadRef', length: 3, start: 1}
+ if has('patch-8.2.3233')
+ expected.type_bufnr = 0
+ endif
+ assert_equal([expected], prop_list(3))
+ expected = {id: 0, col: 3, end: 1, type: 'LspWriteRef', length: 3, start: 1}
+ if has('patch-8.2.3233')
+ expected.type_bufnr = 0
+ endif
+ assert_equal([expected], prop_list(4))
:LspHighlightClear
:sleep 1
assert_equal([], prop_list(1))
var bnr: number = winbufnr(p[0])
assert_equal(1, p->len())
assert_equal(['MyFunc(int a, int b) -> int'], getbufline(bnr, 1, '$'))
- assert_equal([{'id': 0, 'col': 8, 'type_bufnr': 11, 'end': 1, 'type': 'signature', 'length': 5, 'start': 1}], prop_list(1, {bufnr: bnr}))
+ var expected: dict<any>
+ expected = {id: 0, col: 8, end: 1, type: 'signature', length: 5, start: 1}
+ if has('patch-8.2.3233')
+ expected.type_bufnr = 11
+ endif
+ assert_equal([expected], prop_list(1, {bufnr: bnr}))
popup_close(p[0])
setline(line('.'), ' MyFunc(10, ')
bnr = winbufnr(p[0])
assert_equal(1, p->len())
assert_equal(['MyFunc(int a, int b) -> int'], getbufline(bnr, 1, '$'))
- assert_equal([{'id': 0, 'col': 15, 'type_bufnr': 11, 'end': 1, 'type': 'signature', 'length': 5, 'start': 1}], prop_list(1, {bufnr: bnr}))
+ expected = {id: 0, col: 15, end: 1, type: 'signature', length: 5, start: 1}
+ if has('patch-8.2.3233')
+ expected.type_bufnr = 11
+ endif
+ assert_equal([expected], prop_list(1, {bufnr: bnr}))
popup_close(p[0])
:%bw!
enddef
:edit Xtest.c
# Wait for the LSP server to become ready (max 10 seconds)
var maxcount = 100
- while maxcount > 0 && !lsp#serverReady()
+ while maxcount > 0 && !g:LspServerReady()
:sleep 100m
maxcount -= 1
endwhile