Skip to content

Commit 0d6a0c2

Browse files
Thomas Hagethchha
Thomas Hage
authored andcommitted
the PR natebosch#449 requests the ability to handle multiple definitions.
This branch is concerned with compability. It should: * enable jumping to (1) declaration => with split, only one binding * extend the existing documentation => reference parent impl * extend the existing tests => copy dart-test
1 parent c6050e5 commit 0d6a0c2

File tree

6 files changed

+40
-5
lines changed

6 files changed

+40
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ using the default mappings) to jump to the location of the definition. When
148148
multiple definitions are available, the quickfix list will be opened.
149149
If the cursor moves before the server responds the response will be ignored.
150150

151+
### Jump to declaration
152+
153+
While the cursor is on any identifier call `LSClientGoToDeclaration` (`gd` if
154+
using the default mappings) to jump to the location of the declaration.
155+
If the cursor moves before the server responds the response will be ignored.
156+
151157
### Find references
152158

153159
While the cursor is on any identifier call `LSClientFindReferences` (`gr` if

autoload/lsc/config.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ if !exists('s:initialized')
33
let s:default_maps = {
44
\ 'GoToDefinition': '<C-]>',
55
\ 'GoToDefinitionSplit': ['<C-W>]', '<C-W><C-]>'],
6+
\ 'GoToDeclaration': 'gd',
7+
\ 'GoToDeclarationSplit': ['<C-W>]', '<C-W>gd'],
68
\ 'FindReferences': 'gr',
79
\ 'NextReference': '<C-n>',
810
\ 'PreviousReference': '<C-p>',
@@ -54,6 +56,8 @@ function! lsc#config#mapKeys() abort
5456
for l:command in [
5557
\ 'GoToDefinition',
5658
\ 'GoToDefinitionSplit',
59+
\ 'GoToDeclaration',
60+
\ 'GoToDeclarationSplit',
5761
\ 'FindReferences',
5862
\ 'NextReference',
5963
\ 'PreviousReference',

autoload/lsc/reference.vim

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
let s:popup_id = 0
22

3+
function! lsc#reference#goToDeclaration(mods, issplit) abort
4+
call lsc#file#flushChanges()
5+
call lsc#server#userCall('textDocument/declaration',
6+
\ lsc#params#documentPosition(),
7+
\ lsc#util#gateResult('GoTo',
8+
\ function('<SID>GoTo', ['declaration', a:mods, a:issplit])))
9+
endfunction
10+
311
function! lsc#reference#goToDefinition(mods, issplit) abort
412
call lsc#file#flushChanges()
513
call lsc#server#userCall('textDocument/definition',
614
\ lsc#params#documentPosition(),
7-
\ lsc#util#gateResult('GoToDefinition',
8-
\ function('<SID>GoToDefinition', [a:mods, a:issplit])))
15+
\ lsc#util#gateResult('GoTo',
16+
\ function('<SID>GoTo', ['definition', a:mods, a:issplit])))
917
endfunction
1018

11-
function! s:GoToDefinition(mods, issplit, result) abort
19+
function! s:GoTo(label, mods, issplit, result) abort
1220
if type(a:result) == type(v:null) ||
1321
\ (type(a:result) == type([]) && len(a:result) == 0)
14-
call lsc#message#error('No definition found')
22+
call lsc#message#error('No'. a:label .'found')
1523
return
1624
endif
17-
if type(a:result) == type([]) && len(a:result) == 1
25+
if type(a:result) == type([]) && (a:label ==# 'declaration' || len(a:result) == 1)
1826
let l:location = a:result[0]
1927
elseif type(a:result) == type([]) && len(a:result) > 2
2028
call s:setQuickFixLocations('Definitions', a:result)

doc/lsc.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ will default to opening a vertical split, while >
7676
<
7777
will prefer a new tab.
7878

79+
*:LSClientGoToDeclaration*
80+
Similiar to |LSClientGoToDefinition| but expects only a single result.
81+
This is not compliant to the current protocol since it accepts multiple
82+
declaration results as well.
83+
84+
*:LSClientGoToDeclarationSplit*
85+
In accordance to |LSClientGoToDeclaration| and |LSClientGoToDefinitionSplit|.
86+
7987
*:LSClientFindReferences*
8088
Populate the |quickfix| with a list of location which reference the element
8189
under the cursor, including it's definition. Sends a "textDocument/references"

plugin/lsc.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ command! LSClientGoToDefinitionSplit
2525
\ call lsc#reference#goToDefinition(<q-mods>, 1)
2626
command! LSClientGoToDefinition
2727
\ call lsc#reference#goToDefinition(<q-mods>, 0)
28+
command! LSClientGoToDeclarationSplit
29+
\ call lsc#reference#goToDeclaration(<q-mods>, 1)
30+
command! LSClientGoToDeclaration
31+
\ call lsc#reference#goToDeclaration(<q-mods>, 0)
2832
command! LSClientFindReferences call lsc#reference#findReferences()
2933
command! LSClientNextReference call lsc#reference#findNext(1)
3034
command! LSClientPreviousReference call lsc#reference#findNext(-1)

test/integration/test/vim_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ void main() {
3535
expect(result, '2');
3636
});
3737

38+
test('loads plugin', () async {
39+
final result = await vim.expr('exists(\':LSClientGoToDeclaration\')');
40+
expect(result, '1');
41+
});
42+
3843
test('opens files, has filetype detection', () async {
3944
await vim.edit('foo.txt');
4045
expect(await vim.expr('&ft'), 'text');

0 commit comments

Comments
 (0)