yegappan / lsp Goto Github PK
View Code? Open in Web Editor NEWLanguage Server Protocol (LSP) plugin for Vim9
License: MIT License
Language Server Protocol (LSP) plugin for Vim9
License: MIT License
While i using typescript language server and accessing to the properties, autocomplete is overwriting even a dot. But when i using rust-analyzer, it doesn't autocompleting like typescript lang server. It works properly.
Seems like rust-analyzer's autocomplete is not activated with dot key input, but typescript does.
Temporary i'm adding below codes after this block and it seems like working properly with other language servers.
if matchstr(getline('.'), '\%' .. (col('.') - 1) .. 'c.') == '.'
start_col += 1
endif
Or is there any option to handle this?
diff --git a/plugin/lsp.vim b/plugin/lsp.vim
index 561f14c..ff60759 100644
--- a/plugin/lsp.vim
+++ b/plugin/lsp.vim
@@ -24,25 +24,20 @@ if has('patch-8.2.4257')
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
@@ -70,25 +65,20 @@ elseif has('patch-8.2.4019')
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
@@ -148,25 +138,20 @@ else
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
most compl looks set icase=1 or had option to set it,
and/or i remember you added 'matchfuzzy' func into vim, how about add this to filter, perhaps that's a good feature as well.
g:markdown_fenced_languages = ['help', 'python', 'bash=sh', 'vim', 'rust'] # add as needed
g:markdown_syntax_conceal = 1
set completeopt=menuone,popup,noinsert,popuphidden
def MarkdownPopup()
w:vim9lsp_md_applied = get(w:, 'vim9lsp_md_applied', 0)
var win = popup_findinfo()
if w:vim9lsp_md_applied == 0
var buf = winbufnr(win)
if !!buf && buf != 1
setwinvar(win, "&conceallevel", 3)
setbufvar(buf, "&number", "0")
setbufvar(buf, "&filetype", "markdown")
w:vim9lsp_md_applied = 1
endif
endif
popup_show(win)
enddef
autocmd CompleteChanged * MarkdownPopup()
I've been working on getting markdown syntax into the popup like the other lsp clients. I ended up using a similar strategy to how
complete-popuphidden
does it, to integrate with vim's own complete()
function and complete_info(dict)
Line 292 in 7cc46b2
bufadd
and then popup_create
).
There is still some things I'd like to improve. vim-lsp, for example unbinds the default markdown syntax regions (in the complete-popup that is) to achieve an even higher level of cleanliness. Mainly what it does is that it joins ``` lang markdown-tokens (or code-fences) so they conceal on the same line (not leaving an empty line where ``` was concealed). Also it defines its own fenced_languages, so your g:markdown_fenced_languages
can stay agnostic and unassuming to your own .md
-filetype preferences. I like this, I have already done it and saved lines that I can add to this function later, goes something like this
syntax sync clear
unlet g:markdown_fenced_languages
runtime! syntax/markdown.vim
let g:markdown_fenced_languages = ['help']
syntax clear markdownCodeBlock | syntax clear markdownCode
syntax region markdownCode matchgroup=Conceal start=/\%(``\)\@!`/ matchgroup=Conceal end=/\%(``\)\@!`/ containedin=TOP keepend concealends
syntax clear markdownEscape
syntax region markdownEscape matchgroup=markdownEscape start=/\\\ze[\\\x60*{}\[\]()#+\-,.!_>~|"$%&'\/:;<=?@^ ]/ end=/./ containedin=ALL keepend oneline concealends
Try it out and see if you encounter issues.
Would you prefer this as a PR for the README.md
as customization or would you like me to attempt to integrate it with an option? Both are equally viable I guess, as there is no way to prematurely spice the complete-popup anyways without autocmd (that I know of).
PS.
I'm also going to attempt to make a function that searches root_uri
-detecting files like Cargo.toml
, package.json
in parent-dirs when you open a file like vim src/rust/test/test.rs
instead of cd src/rust/test && vim test.rs
or vim
, :cd src/test
and :e test.rs
(Notice the LSP server does not initialize properly without cd
to workspace-dir first)
diff --git a/autoload/handlers.vim b/autoload/handlers.vim
index d94d59b..fa37e39 100644
--- a/autoload/handlers.vim
+++ b/autoload/handlers.vim
@@ -301,13 +301,13 @@ def s:processHoverReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>):
endif
endfor
elseif reply.result.contents->type() == v:t_string
if reply.result.contents->empty()
return
endif
- hoverText->add(reply.result.contents)
+ hoverText->extend(reply.result.contents->split("\n"))
else
ErrMsg('Error: Unsupported hover contents (' .. reply.result.contents .. ')')
return
endif
hoverWinid = hoverText->popup_atcursor({moved: 'word'})
if hoverWinid > 0
Apparently jdt-ls extends lsp and return jdt:// URI for compiled libraries. And I'm assuming it's not support by this lsp
Nvim looks like they let another plugin to handle this.
https://github.com/mfussenegger/nvim-jdtls
example lsp config (excerpt)
# work dir for jdtls(it has to be outside the project source)
var lsp_work_dir = $HOME .. "/.cache/lsp/" .. getcwd()
# lsp config for java
# get tgz from https://download.eclipse.org/jdtls/snapshots/?d and add bin to $PATH for jdtls command(python script)
\ { 'filetype': ['java'], 'path': "jdtls", 'args': ["-data", lsp_work_dir] },
# Opening example project
git clone https://github.com/eclipse/eclipse.jdt.ls.git --depth=1
cd eclipse.jdt.ls
./mvnw compile
vim org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/LanguageServer.java
# jdt:// stuff are most likely raising error(cannot be resolved), after finish loading completely.
Other than external,standard libraries, this amazing lsp plugin works perfectly. :)
var ch = lspserver.job->job_getchannel()
ch->ch_sendraw(msg)
of s:sendMessage
, looks not right, ch
maybe not open, closed or buffered, then 'E906', cannot send.
// this happened when trying with ts lsp server.
Error(LSP): request workspace/executeCommand failed (No delegateCommandHandler for java.apply.workspaceEdit, code = -32601)
code action not impl yet, for now just a list of code action hint.
those lsp server were implemented variedly, due to some reason :-) may had to delay init lsp#addServer after vimenter,
// or whatever that may happen in user side anyhow......
if so, looks lsp would not startup IF startup vim with a fs argument.
e.g 'vim x.sh', and check by 'LspShowServers', server is Not running..
I tried following config with this lsp. And simply jumping to the function in the same file stops working, when the file name isn't .sh.
error message:
Error(LSP): request textDocument/definition failed (Request textDocument/definition failed with message: Cannot read properties of undefined (reading 'rootNode'), code = -32603)
relevant config
\ { 'filetype': ['sh'], 'path': 'bash-language-server', 'args': ['start'] },
\ { 'filetype': ['bash'], 'path': 'bash-language-server', 'args': ['start'] },
\ { 'filetype': ['zsh'], 'path': 'bash-language-server', 'args': ['start'] },
In vim-lsc, any filename with shebang #!/bin/sh works with a configuration like this.
packadd vim-lsc
g:lsc_auto_map = true
set completeopt-=preview
g:lsc_server_commands = {
'sh': 'bash-language-server start',
}
It maybe a vim9script bug?
looks haveNot impl method: ‘workspace/didChangeConfiguration’ yet
supposed you knew, but for a mark, so opening this ticket...
def SendResponse(lspserver: dict<any>, request: dict<any>, result: dict<any>, error: dict<any>)
var resp: dict<any> = lspserver.createResponse(request.id)
autoload/handlers.vim|728 col 31-33| 'initialize': function('s:ProcessInitializeReply'),
autoload/handlers.vim|729 col 44-46| 'textDocument/definition': function('s:ProcessDefDeclReply'),
autoload/handlers.vim|730 col 45-47| 'textDocument/declaration': function('s:ProcessDefDeclReply'),
autoload/handlers.vim|731 col 48-50| 'textDocument/typeDefinition': function('s:ProcessDefDeclReply'),
autoload/handlers.vim|732 col 48-50| 'textDocument/implementation': function('s:ProcessDefDeclReply'),
autoload/handlers.vim|733 col 47-49| 'textDocument/signatureHelp': function('s:ProcessSignaturehelpReply'),
autoload/handlers.vim|734 col 44-46| 'textDocument/completion': function('s:ProcessCompletionReply'),
autoload/handlers.vim|735 col 39-41| 'textDocument/hover': function('s:ProcessHoverReply'),
autoload/handlers.vim|736 col 44-46| 'textDocument/references': function('s:ProcessReferencesReply'),
autoload/handlers.vim|737 col 51-53| 'textDocument/documentHighlight': function('s:ProcessDocHighlightReply'),
autoload/handlers.vim|738 col 48-50| 'textDocument/documentSymbol': function('s:ProcessDocSymbolReply'),
autoload/handlers.vim|739 col 44-46| 'textDocument/formatting': function('s:ProcessFormatReply'),
autoload/handlers.vim|740 col 49-51| 'textDocument/rangeFormatting': function('s:ProcessFormatReply'),
autoload/handlers.vim|741 col 40-42| 'textDocument/rename': function('s:ProcessRenameReply'),
autoload/handlers.vim|742 col 44-46| 'textDocument/codeAction': function('s:ProcessCodeActionReply'),
autoload/handlers.vim|743 col 48-50| 'textDocument/selectionRange': function('s:ProcessSelectionRangeReply'),
autoload/handlers.vim|744 col 46-48| 'textDocument/foldingRange': function('s:ProcessFoldingRangeReply'),
autoload/handlers.vim|745 col 45-47| 'workspace/executeCommand': function('s:ProcessWorkspaceExecuteReply'),
autoload/handlers.vim|746 col 37-39| 'workspace/symbol': function('s:ProcessWorkspaceSymbolReply'),
autoload/handlers.vim|747 col 54-56| 'textDocument/prepareCallHierarchy': function('s:ProcessPrepareCallHierarchy'),
autoload/handlers.vim|748 col 48-50| 'callHierarchy/incomingCalls': function('s:ProcessIncomingCalls'),
autoload/handlers.vim|749 col 48-50| 'callHierarchy/outgoingCalls': function('s:ProcessOutgoingCalls')
autoload/handlers.vim|812 col 39-41| 'window/showMessage': function('s:ProcessShowMsgNotif'),
autoload/handlers.vim|813 col 38-40| 'window/logMessage': function('s:ProcessLogMsgNotif'),
autoload/handlers.vim|814 col 52-54| 'textDocument/publishDiagnostics': function('s:ProcessDiagNotif'),
autoload/handlers.vim|815 col 31-33| '$/progress': function('s:ProcessUnsupportedNotif'),
autoload/handlers.vim|816 col 36-38| 'telemetry/event': function('s:ProcessUnsupportedNotif'),
autoload/handlers.vim|819 col 36-38| 'language/status': function('s:IgnoreNotif')
autoload/handlers.vim|854 col 40-42| 'workspace/applyEdit': function('s:ProcessApplyEditReq'),
autoload/handlers.vim|855 col 51-53| 'window/workDoneProgress/create': function('s:ProcessUnsupportedReq'),
autoload/handlers.vim|856 col 46-48| 'client/registerCapability': function('s:ProcessUnsupportedReq'),
autoload/handlers.vim|857 col 48-50| 'client/unregisterCapability': function('s:ProcessUnsupportedReq'),
autoload/handlers.vim|858 col 47-49| 'workspace/workspaceFolders': function('s:ProcessUnsupportedReq'),
autoload/handlers.vim|859 col 44-46| 'workspace/configuration': function('s:ProcessUnsupportedReq'),
autoload/handlers.vim|860 col 47-49| 'workspace/codeLens/refresh': function('s:ProcessUnsupportedReq'),
autoload/handlers.vim|861 col 53-55| 'workspace/semanticTokens/refresh': function('s:ProcessUnsupportedReq')
autoload/lsp.vim|368 col 26-28| listener_add(function('s:Bufchange_listener'), bnr)
autoload/lspserver.vim|93 col 21-23| out_cb: function('s:Output_cb', [lspserver]),
autoload/lspserver.vim|94 col 21-23| err_cb: function('s:Error_cb', [lspserver]),
autoload/lspserver.vim|95 col 22-24| exit_cb: function('s:Exit_cb', [lspserver])}
autoload/lspserver.vim|457 col 22-24| req.params->extend(s:GetLspTextDocPosition())
autoload/lspserver.vim|481 col 22-24| req.params->extend(s:GetLspTextDocPosition())
autoload/lspserver.vim|506 col 22-24| req.params->extend(s:GetLspTextDocPosition())
autoload/lspserver.vim|531 col 22-24| req.params->extend(s:GetLspTextDocPosition())
autoload/lspserver.vim|551 col 22-24| req.params->extend(s:GetLspTextDocPosition())
autoload/lspserver.vim|590 col 22-24| req.params->extend(s:GetLspTextDocPosition())
autoload/lspserver.vim|611 col 22-24| req.params->extend(s:GetLspTextDocPosition())
autoload/lspserver.vim|635 col 22-24| req.params->extend(s:GetLspTextDocPosition())
autoload/lspserver.vim|732 col 22-24| req.params->extend(s:GetLspTextDocPosition())
autoload/lspserver.vim|924 col 82-84| req.params->extend({textDocument: {uri: util.LspFileToUri(fname)}, positions: [s:GetLspPosition()]})
autoload/lspserver.vim|1021 col 28-30| startServer: function('s:StartServer', [lspserver]),
autoload/lspserver.vim|1022 col 27-29| initServer: function('s:InitServer', [lspserver]),
autoload/lspserver.vim|1023 col 27-29| stopServer: function('s:StopServer', [lspserver]),
autoload/lspserver.vim|1024 col 31-33| shutdownServer: function('s:ShutdownServer', [lspserver]),
autoload/lspserver.vim|1025 col 27-29| exitServer: function('s:ExitServer', [lspserver]),
autoload/lspserver.vim|1026 col 25-27| setTrace: function('s:SetTrace', [lspserver]),
autoload/lspserver.vim|1027 col 26-28| nextReqID: function('s:NextReqID', [lspserver]),
autoload/lspserver.vim|1028 col 30-32| createRequest: function('s:CreateRequest', [lspserver]),
autoload/lspserver.vim|1029 col 31-33| createResponse: function('s:CreateResponse', [lspserver]),
autoload/lspserver.vim|1030 col 35-37| createNotification: function('s:CreateNotification', [lspserver]),
autoload/lspserver.vim|1031 col 29-31| sendResponse: function('s:SendResponse', [lspserver]),
autoload/lspserver.vim|1032 col 28-30| sendMessage: function('s:SendMessage', [lspserver]),
autoload/lspserver.vim|1033 col 31-33| waitForReponse: function('s:WaitForReponse', [lspserver]),
autoload/lspserver.vim|1039 col 31-33| textdocDidOpen: function('s:TextdocDidOpen', [lspserver]),
autoload/lspserver.vim|1040 col 32-34| textdocDidClose: function('s:TextdocDidClose', [lspserver]),
autoload/lspserver.vim|1041 col 33-35| textdocDidChange: function('s:TextdocDidChange', [lspserver]),
autoload/lspserver.vim|1042 col 37-39| sendInitializedNotif: function('s:SendInitializedNotif', [lspserver]),
autoload/lspserver.vim|1043 col 30-32| getCompletion: function('s:GetCompletion', [lspserver]),
autoload/lspserver.vim|1044 col 31-33| gotoDefinition: function('s:GotoDefinition', [lspserver]),
autoload/lspserver.vim|1045 col 32-34| gotoDeclaration: function('s:GotoDeclaration', [lspserver]),
autoload/lspserver.vim|1046 col 28-30| gotoTypeDef: function('s:GotoTypeDef', [lspserver]),
autoload/lspserver.vim|1047 col 35-37| gotoImplementation: function('s:GotoImplementation', [lspserver]),
autoload/lspserver.vim|1048 col 30-32| showSignature: function('s:ShowSignature', [lspserver]),
autoload/lspserver.vim|1049 col 28-30| didSaveFile: function('s:DidSaveFile', [lspserver]),
autoload/lspserver.vim|1050 col 22-24| hover: function('s:Hover', [lspserver]),
autoload/lspserver.vim|1051 col 31-33| showReferences: function('s:ShowReferences', [lspserver]),
autoload/lspserver.vim|1052 col 29-31| docHighlight: function('s:DocHighlight', [lspserver]),
autoload/lspserver.vim|1053 col 30-32| getDocSymbols: function('s:GetDocSymbols', [lspserver]),
autoload/lspserver.vim|1054 col 30-32| textDocFormat: function('s:TextDocFormat', [lspserver]),
autoload/lspserver.vim|1055 col 37-39| prepareCallHierarchy: function('s:PrepareCallHierarchy', [lspserver]),
autoload/lspserver.vim|1056 col 30-32| incomingCalls: function('s:IncomingCalls', [lspserver]),
autoload/lspserver.vim|1057 col 30-32| outgoingCalls: function('s:OutgoingCalls', [lspserver]),
autoload/lspserver.vim|1058 col 29-31| renameSymbol: function('s:RenameSymbol', [lspserver]),
autoload/lspserver.vim|1059 col 27-29| codeAction: function('s:CodeAction', [lspserver]),
autoload/lspserver.vim|1060 col 31-33| workspaceQuery: function('s:WorkspaceQuerySymbols', [lspserver]),
autoload/lspserver.vim|1061 col 35-37| addWorkspaceFolder: function('s:AddWorkspaceFolder', [lspserver]),
autoload/lspserver.vim|1062 col 38-40| removeWorkspaceFolder: function('s:RemoveWorkspaceFolder', [lspserver]),
autoload/lspserver.vim|1063 col 31-33| selectionRange: function('s:SelectionRange', [lspserver]),
autoload/lspserver.vim|1064 col 32-34| selectionExpand: function('s:SelectionExpand', [lspserver]),
autoload/lspserver.vim|1065 col 32-34| selectionShrink: function('s:SelectionShrink', [lspserver]),
autoload/lspserver.vim|1066 col 26-28| foldRange: function('s:FoldRange', [lspserver]),
autoload/lspserver.vim|1067 col 31-33| executeCommand: function('s:ExecuteCommand', [lspserver]),
autoload/lspserver.vim|1068 col 33-35| showCapabilities: function('s:ShowCapabilities', [lspserver])
autoload/outline.vim|102 col 2-4| s:AddSymbolText(bnr, s.children, prefix, text, lnumMap, true)
autoload/symbol.vim|163 col 25-27| filter: function('s:filterSymbols', [lspserver]),
autoload/symbol.vim|164 col 27-29| callback: function('s:jumpToWorkspaceSymbol')
autoload/textedit.vim|156 col 24-26| updated_edits->sort('s:Edit_sort_func')
autoload/textedit.vim|221 col 2-4| s:ApplyTextDocumentEdit(change)
plugin/lsp.vim|232 col 44-46| command! -nargs=0 -bar LspShowServers call s:TshowServers()
plugin/lsp.vim|233 col 55-57| command! -nargs=0 -bar LspShowServerCapabilities call s:TshowServerCapabilities()
plugin/lsp.vim|251 col 47-49| command! -nargs=0 -bar LspShowReferences call s:TshowReferences(v:false)
plugin/lsp.vim|252 col 47-49| command! -nargs=0 -bar LspPeekReferences call s:TshowReferences(v:true)
hanlders.vim :
def ProcessSignaturehelpReply(lspserver: dict<any>, req: dict<any>, reply: dict<any>): void
signature.SignatureDisplay(lspserver, reply.result)
enddef
|| E1013: Argument 2: type mismatch, expected dict<any> but got special
Would it be possible to add a such feature? vim-lsc had it and it was useful for re-reading compile commands json with clangd.
lsp/autoload/handlers.vim[22]..function diag#DiagNotification:
line 24:
E117: Unknown function: UpdateDiags
recently vim and this changed much, not some err not very sure what happened... :-)
Every LspGoto* command creates a window split instead of reusing the current window. Please add <mods>
support for such commands, so the user can specify whether to use split or not.
chg from pr ea1020b :
autoload/handlers.vim
line#138
label = sig.parameters[result.activeParameter].documentation
E1012: Type mismatch; expected string but got special
// by the way: the doc about 'setOption', the key should add quote.
line# 252 and 259
e.g
call lsp#setOptions({showSignature: v:false})
For files that are opened from command line (e.g. vim src/main.cpp
) the LSP isn't properly loaded when using Plug and the VimEnter
autocommand. After vim is opened the LSP isn't active. When re-loading the file with :e
the LSP is activated. I suppose the VimEnter
autocommand is executed too late in this case.
Edit: Adding through lsp#lsp#AddServer()
works btw.
I'd received the feature request for supporting yegappan/lsp
on vim-vsnip and vim-vsnip-integ.
I'd add the support but yegappan/lsp does not provide the way to turn on snipptSupport=true
.
Provide the global configuration option to snippetSupport = true
.
I think it should use in
lsp/autoload/lsp/lspserver.vim
Line 97 in 97da893
The line lsp.vim:47
set ballooneval balloonevalterm
makes buffer scroll up whenever the mouse is moved.
This does not happen in gvim.
Reproduction steps:
These steps cause buffer to scroll up until first line is visible.
This also causes not to show the balloon when it should (again only in vim).
In case it is relevant:
By the way, very nice piece of code.
I'm using it everyday (but it've disabled balloonevalterm due to the scrolling).
diff --git a/autoload/lsp/handlers.vim b/autoload/lsp/handlers.vim
index 80f3ed8..47cab24 100644
--- a/autoload/lsp/handlers.vim
+++ b/autoload/lsp/handlers.vim
@@ -131,20 +131,18 @@ enddef
# process the 'textDocument/definition' / 'textDocument/declaration' /
# 'textDocument/typeDefinition' and 'textDocument/implementation' replies from
# the LSP server
# Result: Location | Location[] | LocationLink[] | null
def 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()
- location = reply.result[0]
- else
- location = {}
- endif
- else
+ if reply.result->type() == v:t_list && !reply.result->empty() && reply.result[0]->type() == v:t_dict
+ location = reply.result[0]
+ elseif reply.result->type() == v:t_dict
location = reply.result
+ else
+ location = {}
endif
symbol.GotoSymbol(lspserver, location, req.method)
enddef
# process the 'textDocument/switchSourceHeader' reply from the LSP server
Opening vim I get this below error, I'm using the git clone https://github.com/yegappan/lsp method to install
Error: LSP server /usr/local/bin/clangd is not found
How i can use snippets with this lsp ?
Selected function How Auto-complete bracket
I have a simple vimrc vim9script config for python:
vim9script
plug#begin()
...
Plug 'yegappan/lsp'
plug#end()
...
var lspServers = [
{
'filetype': ['python'],
'path': '/usr/bin/pylsp',
'args': []
}
]
call LspAddServer(lspServers)
...
Vim version:
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Feb 24 2022 18:41:57)
Included patches: 1-4464
I was able to run call LspAddServer()
after opening a *.py file, LspShowServers shows that pylsp
was added, but is currently stopped:
python not running /usr/bin/pylsp
But when i try to restart it with LspServerRestart i get:
Error: LSP server for "test.py" is not found
I'm looking for a solution to format files before writing.
autocmd BufWritePre *.c,*.cpp,*.h :LspFormat
The problem is that :LspFormat
is asynchronous and the buffer gets written before formatting.
Moreover, sometimes I get corrupted buffer content. It seems that the formatting happens while the buffer is being written.
diff --git a/autoload/lsp.vim b/autoload/lsp.vim
index 1e7d766..f26520e 100644
--- a/autoload/lsp.vim
+++ b/autoload/lsp.vim
@@ -459,13 +459,13 @@ def lsp#addServer(serverList: list<dict<any>>)
if !executable(server.path)
if !opt.lspOptions.ignoreMissingServer
util.ErrMsg('Error: LSP server ' .. server.path .. ' is not found')
endif
return
endif
- var args = []
+ var args: list<string> = []
if server->has_key('args')
if server.args->type() != v:t_list
util.ErrMsg('Error: Arguments for LSP server ' .. server.args .. ' is not a List')
return
endif
args = server.args
Maybe it's a common knowledge among language server users, but in case of clangd, I discovered that rename seems to work with once opened files.
So the trick is to do LspShowReferences on the particular target and then call LspRename to refactor all other files, and then you can just do :wqa or :wa.
Would it be maybe possible to make LspRename work like that by default or provide new command like LspRenameAll?
i saw this plugin used to use window jump per winid..
it probably good for 'save-id -> do-something -> jump-back-To-saved-id' this style.
But:
var wid: number = fname->bufwinid()
wid->win_gotoid()
// I suggest to add a judgement for above case:
Please add support for clangd's 'textDocument/switchSourceHeader'
.
Alternatively, please expose API for sending custom requests to LSP server.
Hi, I'm having a hard time trying to use this the lsp package.
Here is my Vim version (I'm using MacVim):
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jul 25 2022 08:23:04)
macOS version - arm64
Included patches: 1-65
I made a small test vim rc:
$ cat ~/thing.vim
packadd lsp
let lspServers = [ { 'filetype': ['c', 'cpp'], 'path': '/usr/local/bin/clangd', 'args': ['--background-index'] } ]
call LspAddServer(lspServers)
I installed the plugin as the readme shows:
$ ls $HOME/.vim/pack/downloads/opt/lsp
lsp/
$ ls $HOME/.vim/pack/downloads/opt/lsp/lsp
LICENSE README.md autoload/ doc/ plugin/ test/
When I start Vim I get this error:
$ vi -u ~/thing.vim
Error detected while processing /Users/aaron/thing.vim:
line 3:
E117: Unknown function: LspAddServer
This error is similar to #61, but none of the workarounds in #61 would work for me. I'm not sure what I'm doing wrong.
Hi, first of all thanks for this lightning fast vim LSP server! This is a gamechanger.
While setting up my environment I noticed that when autocomplete is enabled and I manually set the omnifunc
to LspOmniFunc
it won't work. Is there any way to enable autocomplete and still have the omni func?
I have noticed odd behaviours while using autocompletion. I'm running vim 9.0.809
and I am using tsserver
for an lsp.
foo
and bar
in scope and you type the letter 'f' your first result will be bar
. Any more key presses filters down the list.foo
and press backspace the current list in the completion menu is removed and a new list is added to the completion menu. this list is also not filtered by what you have inserted so far.I have looked at how autocompletion is implemented in this plugin and noticed that it only fetches the autocompletion results when the completion menu is closed and a valid key is pressed. And I have also noticed that the completion results from the lsp
are not filtered down, I think that vims completion menu implementation filters this list down itself.
For the first scenario I think the following is happening. Because the result from the lsp
for autocompletion is asynchronous we have to wait for the suggested results. The problem is the vim completion menu only filters down the results on key press, so we are only given the full list from the lsp
.
For the second scenario I'm not completely sure what is going on. We already have the results from the lsp
, we shouldn't need to fetch those results a second time but we do. This isn't the usual behaviour of the completion menu, usually on backspace the completion menu stays visible. I could see fetching on backspace covering some edge cases though.
For anyone interested in testing and helping improving this - I created a small adapter for the mattn/vim-lsp-settings plugin to make it easier to install LSP servers for this plugin.
You can install it from https://github.com/normen/vim-lsp-settings-adapter
a headsup notice:
var content = lspserver.data[idx : idx + len - 1]
var msg = content->json_decode()
looks sometime ‘lsp.data->len - idx < len’ such judgement not good enough or somehow, that process json decode would raised e488 err,
But cannot solid reproduced, just a note...
# omni complete handler
def lsp#omniFunc(findstart: number, base: string): any # <-----
if !bufnrToServer->has_key(bufnr())
return # <------
endif
I am getting this error here in combination with the vim-language-server
when I execute the omni complete mapping without any preceding characters, seems like it tries to send some empty variables to the LSP.
Error(LSP): request textDocument/completion failed (Request textDocument/completi... arguments[[object Object], [object Object], undefined, undefined], code = -32603)
I haven't found a condition when it happens but sometimes fixing the clangd(clang-tidy) warning, highlight doesn't disappear. The only way to fix it is to restart the vim completely (e! doesn't help).
I'll update this issue as soon as I found the exact condition to reproduce this.
prop_type_add('LspOutlineHighlight', {bufnr: bufnr(), highlight: 'Search'})
// when/if opened a outline already -but to open another in another tab.
// 'Property type LspOutlineHighlight already defined'
I suggest replace such functions with capital first letter and prepend export
.
I'm not sure if vim8 vimrc will need to call import to call lsp#setOptions.
It might be a good idea to migrate to global variable based config like the old times, as it is bit awkward to call import during configuration.
for symbol in reply.result
if !symbol->has_key('location')
of processWorkspaceSymbolReply
, that reply.result
maybe a special
type, but here needs a list<any>
. so E1012.
// actually, perhaps better check all those funcs in ProcessReply
, check their type, not only if empty()
.
if lsp_reply_handlers->has_key(req.method)
lsp_reply_handlers[req.method](lspserver, req, reply)
else
of def ProcessReply
, perhaps can check there in totally, that replay
.
Hi,
it seems the openscad-lsp reports a {}
for the completionProvider
variable instead of true
which later gets recognized as false
here:
lsp/autoload/lsp/lspserver.vim
Line 674 in 446da38
When removing or changing the above check as below the LSP provides completion as expected.
if !lspserver.caps->has_key('completionProvider')
This is the debug output of LspDebug while initializing the openscad-lsp:
Sent [11/06/22 17:17:19]: {'method': 'initialize', 'params': {'rootUri': 'file:///Users/normenhansen/Documents/OpenSCAD/raumschiff/', 'workspaceFolders': [{'uri': 'file:///Users/normenhansen/Documents/OpenSCAD/raumschiff/', 'name': 'raumschiff'}], 'rootPath': '/Users/normenhansen/Documents/OpenSCAD/raumschiff', 'clientInfo': {'version': '9000800', 'name': 'Vim'}, 'processId': 48342, 'trace': 'off', 'capabilities': {'workspace': {'workspaceFolders': true, 'applyEdit': true}, 'window': {}, 'general': {}, 'textDocument': {'foldingRange': {'lineFoldingOnly': true}, 'documentSymbol': {'symbolKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}, 'hierarchicalDocumentSymbolSupport': true}, 'completion': {'completionItem': {'snippetSupport': false, 'resolveSupport': {'properties': ['detail', 'documentation']}, 'documentationFormat': ['plaintext', 'markdown']}, 'completionItemKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}}, 'hover': {'contentFormat': ['plaintext', 'markdown']}}}}}
Received [11/06/22 17:17:19]: {'id': 1, 'jsonrpc': '2.0', 'result': {'capabilities': {'hoverProvider': true, 'documentFormattingProvider': true, 'documentSymbolProvider': true, 'definitionProvider': true, 'completionProvider': {}, 'textDocumentSync': 2}}}
Received [11/06/22 17:52:05]: {'method': 'textDocument/publishDiagnostics', 'jsonrpc': '2.0', 'params': {'diagnostics': [], 'uri': 'file:///Users/normenhansen/Documents/OpenSCAD/raumschiff/switch.scad', 'version': 4}}
I'm not quite sure if this can be put down as a bug in the LSP server as it works fine in other contexts (VSCode etc).
I tried adding eslint language server as below but it seems not supported yet.
let lspServers = [
\ {
\ 'filetype': ['javascript', 'typescript', 'javascriptreact'],
\ 'path': 'path/to/typescript-language-server',
\ 'args': ['--stdio']
\ },
\ {
\ 'filetype': ['javascript', 'typescript', 'javascriptreact'],
\ 'path': 'path/to/vscode-eslint-language-server',
\ 'args': ['--stdio']
\ },
\ ]
call lsp#addServer(lspServers)
Error I get:
Error: LSP server does not support getting list of symbols
Error: Unsupported request message received from the LSP server (<path to server>), message = {'id':
0, 'jsonrpc': '2.0', 'method': 'workspace/configuration', 'params': {'items': [{'section': '', 'scopeUri': '<path>'}]}}
I am not sure if this is a language server limitation or this plugin.
Hi @yegappan, thanks for creating this plugin, that's what I am looking for, but why do not use lsp
as the default namespace, and put all files under autoload/lsp
directory. currently using top namespace, for example buffer#...
and util#...
will break users's config.
Apply clang-format of totally different format like llvm in vim project.
Undo the change, vim will completely get blocked with 100% usage for a while.
Hey,
to display the error count in my lightline status line I am using lsp#lsp#ErrorCount
which basically works but the status line isn't updated when the LSP detects new errors. I have to do some action like LspOutline
to update the status line.
The vim-lsp
plugin solves this by having an autocmd
called lsp_diagnostics_updated
which is executed when the LSP changes so I can update the status line like shown below. Maybe something like that could be added to this plugin.
autocmd User lsp_diagnostics_updated call lightline#update()
Cheers!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.