location = reply.result
endif
- symbol.GotoSymbol(lspserver, location)
+ symbol.GotoSymbol(lspserver, location, req.method)
enddef
# process the 'textDocument/signatureHelp' reply from the LSP server
# Jump to the definition, declaration or implementation of a symbol.
# Also, used to peek at the definition, declaration or implementation of a
# symbol.
-export def GotoSymbol(lspserver: dict<any>, location: dict<any>)
+export def GotoSymbol(lspserver: dict<any>, location: dict<any>, type: string)
if location->empty()
- util.WarnMsg("Error: definition is not found")
+ var msg: string
+ if type ==# 'textDocument/declaration'
+ msg = 'Error: declaration is not found'
+ elseif type ==# 'textDocument/typeDefinition'
+ msg = 'Error: type definition is not found'
+ elseif type ==# 'textDocument/implementation'
+ msg = 'Error: implementation is not found'
+ else
+ msg = 'Error: definition is not found'
+ endif
+
+ util.WarnMsg(msg)
if !lspserver.peekSymbol
# pop the tag stack
var tagstack: dict<any> = gettagstack()
:%bw!
enddef
+# Test for LSP goto symobl definition, declaration and implementation
+def Test_lsp_goto_definition()
+ silent! edit Xtest.cpp
+ var lines: list<string> =<< trim END
+ #include <iostream>
+ using namespace std;
+
+ class base {
+ public:
+ virtual void print();
+ };
+
+ void base::print()
+ {
+ }
+
+ class derived : public base {
+ public:
+ void print() {}
+ };
+
+ void f1(void)
+ {
+ base *bp;
+ derived d;
+ bp = &d;
+
+ bp->print();
+ }
+ END
+ setline(1, lines)
+ :sleep 500m
+ cursor(24, 6)
+ :LspGotoDeclaration
+ :sleep 500m
+ assert_equal([6, 19], [line('.'), col('.')])
+ exe "normal! \<C-t>"
+ assert_equal([24, 6], [line('.'), col('.')])
+ :LspGotoDefinition
+ :sleep 500m
+ assert_equal([9, 12], [line('.'), col('.')])
+ exe "normal! \<C-t>"
+ assert_equal([24, 6], [line('.'), col('.')])
+ :LspGotoImpl
+ :sleep 500m
+ assert_equal([15, 11], [line('.'), col('.')])
+ exe "normal! \<C-t>"
+ assert_equal([24, 6], [line('.'), col('.')])
+
+ # Error cases
+ :messages clear
+ cursor(14, 5)
+ :LspGotoDeclaration
+ sleep 500m
+ var m = execute('messages')->split("\n")
+ assert_equal('Error: declaration is not found', m[1])
+ :messages clear
+ :LspGotoDefinition
+ sleep 500m
+ m = execute('messages')->split("\n")
+ assert_equal('Error: definition is not found', m[1])
+ :messages clear
+ :LspGotoImpl
+ sleep 500m
+ m = execute('messages')->split("\n")
+ assert_equal('Error: implementation is not found', m[1])
+ :%bw!
+enddef
+
def LspRunTests()
:set nomore
:set debug=beep