1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
vim9script
# Unit tests for Vim Language Server Protocol (LSP) golang client
source common.vim
var lspServers = [{
filetype: ['go'],
path: exepath('gopls'),
args: ['serve']
}]
call LspAddServer(lspServers)
echomsg systemlist($'{lspServers[0].path} version')
# Test for :LspGotoDefinition, :LspGotoDeclaration, etc.
# This test also tests that multiple locations will be
# shown in a list or popup
def g:Test_LspGoto()
:silent! edit Xtest.go
var bnr = bufnr()
sleep 200m
var lines =<< trim END
package main
type A/*goto implementation*/ interface {
Hello()
}
type B struct{}
func (b *B) Hello() {}
type C struct{}
func (c *C) Hello() {}
func main() {
}
END
setline(1, lines)
:redraw!
g:WaitForServerFileLoad(0)
cursor(9, 10)
:LspGotoDefinition
assert_equal([7, 6], [line('.'), col('.')])
exe "normal! \<C-t>"
assert_equal([9, 10], [line('.'), col('.')])
cursor(9, 13)
:LspGotoImpl
assert_equal([4, 9], [line('.'), col('.')])
cursor(13, 13)
:LspGotoImpl
assert_equal([4, 9], [line('.'), col('.')])
# Two implementions needs to be shown in a location list
cursor(4, 9)
assert_equal('', execute('LspGotoImpl'))
sleep 200m
var loclist: list<dict<any>> = getloclist(0)
assert_equal('quickfix', getwinvar(winnr('$'), '&buftype'))
assert_equal(2, loclist->len())
assert_equal(bnr, loclist[0].bufnr)
assert_equal([9, 13, ''], [loclist[0].lnum, loclist[0].col, loclist[0].type])
assert_equal([13, 13, ''], [loclist[1].lnum, loclist[1].col, loclist[1].type])
lclose
# Two implementions needs to be shown in a quickfix list
g:LspOptionsSet({ useQuickfixForLocations: true })
cursor(4, 9)
assert_equal('', execute('LspGotoImpl'))
sleep 200m
var qfl: list<dict<any>> = getqflist()
assert_equal('quickfix', getwinvar(winnr('$'), '&buftype'))
assert_equal(2, qfl->len())
assert_equal(bnr, qfl[0].bufnr)
assert_equal([9, 13, ''], [qfl[0].lnum, qfl[0].col, qfl[0].type])
assert_equal([13, 13, ''], [qfl[1].lnum, qfl[1].col, qfl[1].type])
cclose
g:LspOptionsSet({ useQuickfixForLocations: false })
# Two implementions needs to be peeked in a popup
cursor(4, 9)
:LspPeekImpl
sleep 10m
var ids = popup_list()
assert_equal(2, ids->len())
var filePopupAttrs = ids[0]->popup_getoptions()
var refPopupAttrs = ids[1]->popup_getoptions()
assert_match('Xtest', filePopupAttrs.title)
assert_match('Implementation', refPopupAttrs.title)
assert_equal(9, line('.', ids[0])) # current line in left panel
assert_equal(2, line('$', ids[1])) # last line in right panel
feedkeys("j\<CR>", 'xt')
assert_equal(13, line('.'))
assert_equal([], popup_list())
popup_clear()
# Jump to the first implementation
cursor(4, 9)
assert_equal('', execute(':1LspGotoImpl'))
assert_equal([9, 13], [line('.'), col('.')])
# Jump to the second implementation
cursor(4, 9)
assert_equal('', execute(':2LspGotoImpl'))
assert_equal([13, 13], [line('.'), col('.')])
bw!
enddef
# Start the gopls language server. Returns true on success and false on
# failure.
def g:StartLangServer(): bool
return g:StartLangServerWithFile('Xtest.go')
enddef
# vim: shiftwidth=2 softtabstop=2 noexpandtab
|