-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3088 from bhcleek/lsp/callers
calls: update :GoCallers to use gopls
- Loading branch information
Showing
8 changed files
with
193 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
" don't spam the user when Vim is started in Vi compatibility mode | ||
let s:cpo_save = &cpo | ||
set cpo&vim | ||
|
||
function! go#calls#Callers() abort | ||
if !go#config#GoplsEnabled() | ||
call go#util#EchoError("go_referrers_mode is 'gopls', but gopls is disabled") | ||
endif | ||
let [l:line, l:col] = getpos('.')[1:2] | ||
let [l:line, l:col] = go#lsp#lsp#Position(l:line, l:col) | ||
let l:fname = expand('%:p') | ||
call go#lsp#Callers(l:fname, l:line, l:col, funcref('s:parse_output', ['callers'])) | ||
return | ||
endfunction | ||
|
||
" This uses Vim's errorformat to parse the output and put it into a quickfix | ||
" or locationlist. | ||
function! s:parse_output(mode, output) abort | ||
let errformat = ",%f:%l:%c:\ %m" | ||
let l:listtype = go#list#Type("GoCallers") | ||
call go#list#ParseFormat(l:listtype, errformat, a:output, a:mode, 0) | ||
|
||
let errors = go#list#Get(l:listtype) | ||
call go#list#Window(l:listtype, len(errors)) | ||
endfunction | ||
|
||
" restore Vi compatibility settings | ||
let &cpo = s:cpo_save | ||
unlet s:cpo_save | ||
|
||
" vim: sw=2 ts=2 et |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
" don't spam the user when Vim is started in Vi compatibility mode | ||
let s:cpo_save = &cpo | ||
set cpo&vim | ||
|
||
scriptencoding utf-8 | ||
|
||
func! Test_Callers() abort | ||
try | ||
let l:tmp = gotest#write_file('calls/caller.go', [ | ||
\ 'package main', | ||
\ '', | ||
\ 'import "fmt"', | ||
\ '', | ||
\ 'func Quux() {}', | ||
\ '', | ||
\ 'func main() {', | ||
\ "\tQuux()", | ||
\ "\tQuux()", | ||
\ '', | ||
\ "\tfmt.Println(\"vim-go\")", | ||
\ '}', | ||
\ ]) | ||
|
||
let l:expected = [ | ||
\ {'lnum': 8, 'bufnr': bufnr(''), 'col': 2, 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'module': '', 'text': 'main'}, | ||
\ {'lnum': 9, 'bufnr': bufnr(''), 'col': 2, 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'module': '', 'text': 'main'}, | ||
\ ] | ||
|
||
call go#calls#Callers() | ||
|
||
let l:actual = getloclist(0) | ||
let l:start = reltime() | ||
while len(l:actual) != len(l:expected) && reltimefloat(reltime(l:start)) < 10 | ||
sleep 100m | ||
let l:actual = getloclist(0) | ||
endwhile | ||
|
||
call gotest#assert_quickfix(l:actual, l:expected) | ||
finally | ||
call delete(l:tmp, 'rf') | ||
endtry | ||
endfunc | ||
|
||
" restore Vi compatibility settings | ||
let &cpo = s:cpo_save | ||
unlet s:cpo_save | ||
|
||
" vim: sw=2 ts=2 et |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters