Skip to content

Commit 74718e5

Browse files
authored
Support custom locations request (#587)
* Support custom locations request * specify server name in FindLocations * Rename LspFindLocations
1 parent 235dcdf commit 74718e5

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

autoload/lsp/buffer.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,15 @@ export def CurbufGetServerChecked(feature: string = null_string): dict<any>
191191
return lspserver
192192
enddef
193193

194+
export def CurbufGetServerByName(name: string): dict<any>
195+
var lspservers: list<dict<any>> = CurbufGetServers()
196+
197+
for lspserver in lspservers
198+
if lspserver.name == name
199+
return lspserver
200+
endif
201+
endfor
202+
return {}
203+
enddef
204+
194205
# vim: tabstop=8 shiftwidth=2 softtabstop=2

autoload/lsp/lsp.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,24 @@ export def ShowReferences(peek: bool)
832832
lspserver.showReferences(peek)
833833
enddef
834834

835+
# send custom locations request
836+
def g:LspFindLocations(server_name: string, peek: bool, method: string, args: dict<any> = {})
837+
var lspserver: dict<any> = buf.CurbufGetServerByName(server_name)
838+
if lspserver->empty()
839+
return
840+
endif
841+
if !lspserver.running
842+
util.ErrMsg($'Language server "{server_name}" is not running')
843+
return
844+
endif
845+
if !lspserver.ready
846+
util.ErrMsg($'Language server "{server_name}" is not ready')
847+
return
848+
endif
849+
850+
lspserver.findLocations(peek, method, args)
851+
enddef
852+
835853
# highlight all the places where a symbol is referenced
836854
def g:LspDocHighlight(bnr: number = bufnr(), cmdmods: string = '')
837855
var lspserver: dict<any> = buf.CurbufGetServerChecked('documentHighlight')

autoload/lsp/lspserver.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,29 @@ def ShowReferences(lspserver: dict<any>, peek: bool): void
10061006
symbol.ShowLocations(lspserver, reply.result, peek, 'Symbol References')
10071007
enddef
10081008

1009+
# send custom locations request
1010+
def FindLocations(lspserver: dict<any>, peek: bool, method: string, args: dict<any>): void
1011+
var param: dict<any>
1012+
param = lspserver.getTextDocPosition(true)->extend(args)
1013+
var reply = lspserver.rpc(method, param)
1014+
1015+
# Result: Location[] | null
1016+
if reply->empty() || reply.result->empty()
1017+
util.WarnMsg('No references found')
1018+
return
1019+
endif
1020+
1021+
if lspserver.needOffsetEncoding
1022+
# Decode the position encoding in all the reference locations
1023+
reply.result->map((_, loc) => {
1024+
lspserver.decodeLocation(loc)
1025+
return loc
1026+
})
1027+
endif
1028+
1029+
symbol.ShowLocations(lspserver, reply.result, peek, 'Symbol References')
1030+
enddef
1031+
10091032
# process the 'textDocument/documentHighlight' reply from the LSP server
10101033
# Result: DocumentHighlight[] | null
10111034
def DocHighlightReply(lspserver: dict<any>, docHighlightReply: any,
@@ -1948,6 +1971,7 @@ export def NewLspServer(serverParams: dict<any>): dict<any>
19481971
didSaveFile: function(DidSaveFile, [lspserver]),
19491972
hover: function(ShowHoverInfo, [lspserver]),
19501973
showReferences: function(ShowReferences, [lspserver]),
1974+
findLocations: function(FindLocations, [lspserver]),
19511975
docHighlight: function(DocHighlight, [lspserver]),
19521976
getDocSymbols: function(GetDocSymbols, [lspserver]),
19531977
textDocFormat: function(TextDocFormat, [lspserver]),

0 commit comments

Comments
 (0)