Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions autoload/lsp/buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,15 @@ export def CurbufGetServerChecked(feature: string = null_string): dict<any>
return lspserver
enddef

export def CurbufGetServerByName(name: string): dict<any>
var lspservers: list<dict<any>> = CurbufGetServers()

for lspserver in lspservers
if lspserver.name == name
return lspserver
endif
endfor
return {}
enddef

# vim: tabstop=8 shiftwidth=2 softtabstop=2
18 changes: 18 additions & 0 deletions autoload/lsp/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,24 @@ export def ShowReferences(peek: bool)
lspserver.showReferences(peek)
enddef

# send custom locations request
def g:LspFindLocations(server_name: string, peek: bool, method: string, args: dict<any> = {})
var lspserver: dict<any> = buf.CurbufGetServerByName(server_name)
if lspserver->empty()
return
endif
if !lspserver.running
util.ErrMsg($'Language server "{server_name}" is not running')
return
endif
if !lspserver.ready
util.ErrMsg($'Language server "{server_name}" is not ready')
return
endif

lspserver.findLocations(peek, method, args)
enddef

# highlight all the places where a symbol is referenced
def g:LspDocHighlight(bnr: number = bufnr(), cmdmods: string = '')
var lspserver: dict<any> = buf.CurbufGetServerChecked('documentHighlight')
Expand Down
24 changes: 24 additions & 0 deletions autoload/lsp/lspserver.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,29 @@ def ShowReferences(lspserver: dict<any>, peek: bool): void
symbol.ShowLocations(lspserver, reply.result, peek, 'Symbol References')
enddef

# send custom locations request
def FindLocations(lspserver: dict<any>, peek: bool, method: string, args: dict<any>): void
var param: dict<any>
param = lspserver.getTextDocPosition(true)->extend(args)
var reply = lspserver.rpc(method, param)

# Result: Location[] | null
if reply->empty() || reply.result->empty()
util.WarnMsg('No references found')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to your example in the OP, looks your custom msg were not all for references, but do location related things, so:

  1. the description here and next symbol.ShowLocations looks not accurate?
  2. for now so-called 'custom request' actually only for 'location' related things.

return
endif

if lspserver.needOffsetEncoding
# Decode the position encoding in all the reference locations
reply.result->map((_, loc) => {
lspserver.decodeLocation(loc)
return loc
})
endif

symbol.ShowLocations(lspserver, reply.result, peek, 'Symbol References')
enddef

# process the 'textDocument/documentHighlight' reply from the LSP server
# Result: DocumentHighlight[] | null
def DocHighlightReply(lspserver: dict<any>, docHighlightReply: any,
Expand Down Expand Up @@ -1948,6 +1971,7 @@ export def NewLspServer(serverParams: dict<any>): dict<any>
didSaveFile: function(DidSaveFile, [lspserver]),
hover: function(ShowHoverInfo, [lspserver]),
showReferences: function(ShowReferences, [lspserver]),
findLocations: function(FindLocations, [lspserver]),
docHighlight: function(DocHighlight, [lspserver]),
getDocSymbols: function(GetDocSymbols, [lspserver]),
textDocFormat: function(TextDocFormat, [lspserver]),
Expand Down