Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions autoload/lsp/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,16 @@ export def ShowReferences(peek: bool)
lspserver.showReferences(peek)
enddef

# send custom locations request
def g:FindLocations(peek: bool, method: string, args: dict<any> = {})
var lspserver: dict<any> = buf.CurbufGetServerChecked('references')
Comment thread
bennyyip marked this conversation as resolved.
Outdated
if lspserver->empty()
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
Copy Markdown
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