location = reply.result
endif
- # Convert to 'LocationLink'
- if !location->has_key('targetUri')
- location = util.LspLocationToLocationLink(location)
- endif
-
symbol.GotoSymbol(lspserver, location, peekSymbol, cmdmods)
enddef
taglocations = [reply.result]
endif
- taglocations = taglocations->map((key, location) => {
- # Already a 'LocationLink'
- if location->has_key('targetUri')
- return location
- endif
- return util.LspLocationToLocationLink(location)
- })
-
return symbol.TagFunc(lspserver, taglocations, pat)
enddef
lspserver.peekSymbolFilePopup = popup_create(bnr, popupAttrs)
var cmds =<< trim eval END
+ setlocal number
[{refs[n].range.start.line + 1}, 1]->cursor()
normal! z.
END
# Display the file specified by LSP 'LocationLink' in a popup window and
# highlight the range in 'location'.
def PeekSymbolLocation(lspserver: dict<any>, location: dict<any>)
- var fname = util.LspUriToFile(location.targetUri)
+ var [uri, range] = util.LspLocationParse(location)
+ var fname = util.LspUriToFile(uri)
var bnum = fname->bufadd()
if bnum == 0
# Failed to create or find a buffer
var pos: list<number> = []
var start_col: number
var end_col: number
- start_col = util.GetLineByteFromPos(pwbuf, location.targetSelectionRange.start) + 1
- end_col = util.GetLineByteFromPos(pwbuf, location.targetSelectionRange.end) + 1
- pos->add(location.targetSelectionRange.start.line + 1)
+ start_col = util.GetLineByteFromPos(pwbuf, range.start) + 1
+ end_col = util.GetLineByteFromPos(pwbuf, range.end) + 1
+ pos->add(range.start.line + 1)
pos->extend([start_col, end_col - start_col])
matchaddpos('Search', [pos], 10, 101, {window: pwid})
var cmds =<< trim eval END
- [{location.targetSelectionRange.start.line + 1}, 1]->cursor()
+ [{range.start.line + 1}, 1]->cursor()
normal! z.
END
win_execute(pwid, cmds, 'silent!')
var tagitem = {}
tagitem.name = pat
- tagitem.filename = util.LspUriToFile(tagloc.targetUri)
- tagitem.cmd = $"/\\%{tagloc.targetSelectionRange.start.line + 1}l\\%{tagloc.targetSelectionRange.start.character + 1}c"
+ var [uri, range] = util.LspLocationParse(tagloc)
+ tagitem.filename = util.LspUriToFile(uri)
+ tagitem.cmd = $"/\\%{range.start.line + 1}l\\%{range.start.character + 1}c"
retval->add(tagitem)
endfor
writefile([], $'{lsp_log_dir}lsp-server.err')
enddef
-# Convert a 'Location' to a dict that looks a lot like a 'LocationLink' but with
-# the caveat that 'targetRange' is null.
-export def LspLocationToLocationLink(location: dict<any>): dict<any>
- return {
- targetUri: location.uri,
- targetSelectionRange: location.range,
- targetRange: null,
- originSelectionRange: null
- }
+# Parse a LSP Location or LocationLink type and return a List with two items.
+# The first item is the DocumentURI and the second item is the Range.
+export def LspLocationParse(lsploc: dict<any>): list<any>
+ if lsploc->has_key('targetUri')
+ # LocationLink
+ return [lsploc.targetUri, lsploc.targetSelectionRange]
+ else
+ # Location
+ return [lsploc.uri, lsploc.range]
+ endif
enddef
# Convert a LSP file URI (file://<absolute_path>) to a Vim file name
# number and character number. The user specified window command modifiers
# (e.g. topleft) are in 'cmdmods'.
export def JumpToLspLocation(location: dict<any>, cmdmods: string)
- var fname = LspUriToFile(location.targetUri)
+ var [uri, range] = LspLocationParse(location)
+ var fname = LspUriToFile(uri)
# jump to the file and line containing the symbol
if cmdmods == ''
# Set the previous cursor location mark. Instead of using setpos(), m' is
# used so that the current location is added to the jump list.
normal m'
- setcursorcharpos(location.targetSelectionRange.start.line + 1,
- location.targetSelectionRange.start.character + 1)
+ setcursorcharpos(range.start.line + 1, range.start.character + 1)
enddef
# 'indexof' is to new to use it, use this instead.
# write since last change" error message. To disable this message, mark the
# buffer as not modified.
setlocal nomodified
- cursor(1, 5)
+ cursor(10, 6)
:LspPeekReferences
var ids = popup_list()
assert_equal(2, ids->len())
var refPopupAttrs = ids[1]->popup_getoptions()
assert_match('Xtest', filePopupAttrs.title)
assert_equal('References', refPopupAttrs.title)
- assert_equal(1, line('.', ids[0]))
+ assert_equal(10, line('.', ids[0]))
+ assert_equal(3, line('$', ids[1]))
+ feedkeys("jj\<CR>", 'xt')
+ assert_equal(12, line('.'))
+ assert_equal([], popup_list())
popup_clear()
bw!