Skip to content

Commit

Permalink
def: fix jumping to definition
Browse files Browse the repository at this point in the history
Fix jumping to a definition so that it uses the actual definition line
to calculate the position of the definition when the definition is not
in the current buffer.
  • Loading branch information
bhcleek committed Dec 5, 2023
1 parent 4e0f092 commit 48201c5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,14 @@ function! s:definitionHandler(next, msg) abort dict

" gopls returns a []Location; just take the first one.
let l:msg = a:msg[0]
let l:args = [[printf('%s:%d:%d: %s', go#path#FromURI(l:msg.uri), l:msg.range.start.line+1, go#lsp#lsp#PositionOf(getline(l:msg.range.start.line+1), l:msg.range.start.character), 'lsp does not supply a description')]]

let l:line = s:lineinfile(go#path#FromURI(l:msg.uri), l:msg.range.start.line+1)
if l:line is -1
call go#util#Warn('could not find definition')
return
endif

let l:args = [[printf('%s:%d:%d: %s', go#path#FromURI(l:msg.uri), l:msg.range.start.line+1, go#lsp#lsp#PositionOf(l:line, l:msg.range.start.character), 'lsp does not supply a description')]]
call call(a:next, l:args)
endfunction

Expand All @@ -641,7 +648,13 @@ function! s:typeDefinitionHandler(next, msg) abort dict

" gopls returns a []Location; just take the first one.
let l:msg = a:msg[0]
let l:args = [[printf('%s:%d:%d: %s', go#path#FromURI(l:msg.uri), l:msg.range.start.line+1, go#lsp#lsp#PositionOf(getline(l:msg.range.start.line+1), l:msg.range.start.character), 'lsp does not supply a description')]]

let l:line = s:lineinfile(go#path#FromURI(l:msg.uri), l:msg.range.start.line+1)
if l:line is -1
call go#util#Warn('could not find definition')
return

let l:args = [[printf('%s:%d:%d: %s', go#path#FromURI(l:msg.uri), l:msg.range.start.line+1, go#lsp#lsp#PositionOf(l:line, l:msg.range.start.character), 'lsp does not supply a description')]]
call call(a:next, l:args)
endfunction

Expand Down

0 comments on commit 48201c5

Please sign in to comment.