2 # Unit tests for Vim Language Server Protocol (LSP) golang client
8 path: exepath('gopls'),
11 call LspAddServer(lspServers)
12 echomsg systemlist($'{lspServers[0].path} version')
14 # Test for :LspGotoDefinition, :LspGotoDeclaration, etc.
15 # This test also tests that multiple locations will be
16 # shown in a list or popup
18 :silent! edit Xtest.go
23 var lines =<< trim END
26 type A/*goto implementation*/ interface {
32 func (b *B) Hello() {}
36 func (c *C) Hello() {}
44 g:WaitForServerFileLoad(0)
48 assert_equal([7, 6], [line('.'), col('.')])
50 assert_equal([9, 10], [line('.'), col('.')])
54 assert_equal([4, 9], [line('.'), col('.')])
58 assert_equal([4, 9], [line('.'), col('.')])
60 # Two implementions needs to be shown in a location list
62 assert_equal('', execute('LspGotoImpl'))
64 var loclist: list<dict<any>> = getloclist(0)
65 assert_equal('quickfix', getwinvar(winnr('$'), '&buftype'))
66 assert_equal(2, loclist->len())
67 assert_equal(bnr, loclist[0].bufnr)
68 assert_equal([9, 13, ''], [loclist[0].lnum, loclist[0].col, loclist[0].type])
69 assert_equal([13, 13, ''], [loclist[1].lnum, loclist[1].col, loclist[1].type])
72 # Two implementions needs to be shown in a quickfix list
73 g:LspOptionsSet({ useQuickfixForLocations: true })
75 assert_equal('', execute('LspGotoImpl'))
77 var qfl: list<dict<any>> = getqflist()
78 assert_equal('quickfix', getwinvar(winnr('$'), '&buftype'))
79 assert_equal(2, qfl->len())
80 assert_equal(bnr, qfl[0].bufnr)
81 assert_equal([9, 13, ''], [qfl[0].lnum, qfl[0].col, qfl[0].type])
82 assert_equal([13, 13, ''], [qfl[1].lnum, qfl[1].col, qfl[1].type])
84 g:LspOptionsSet({ useQuickfixForLocations: false })
86 # Two implementions needs to be peeked in a popup
90 var ids = popup_list()
91 assert_equal(2, ids->len())
92 var filePopupAttrs = ids[0]->popup_getoptions()
93 var refPopupAttrs = ids[1]->popup_getoptions()
94 assert_match('Xtest', filePopupAttrs.title)
95 assert_match('Implementation', refPopupAttrs.title)
96 assert_equal(9, line('.', ids[0])) # current line in left panel
97 assert_equal(2, line('$', ids[1])) # last line in right panel
98 feedkeys("j\<CR>", 'xt')
99 assert_equal(13, line('.'))
100 assert_equal([], popup_list())
103 # Jump to the first implementation
105 assert_equal('', execute(':1LspGotoImpl'))
106 assert_equal([9, 13], [line('.'), col('.')])
108 # Jump to the second implementation
110 assert_equal('', execute(':2LspGotoImpl'))
111 assert_equal([13, 13], [line('.'), col('.')])
115 # Start the gopls language server. Returns true on success and false on
117 def g:StartLangServer(): bool
118 return g:StartLangServerWithFile('Xtest.go')
121 # vim: shiftwidth=2 softtabstop=2 noexpandtab