Skip to content

Commit

Permalink
the PR natebosch#449 requests the ability to handle multiple definiti…
Browse files Browse the repository at this point in the history
…ons.

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
  • Loading branch information
Thomas Hage authored and kohnish committed Mar 27, 2023
1 parent 7385eb3 commit 46d3564
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ using the default mappings) to jump to the location of the definition. When
multiple definitions are available, the quickfix list will be opened.
If the cursor moves before the server responds the response will be ignored.

### Jump to declaration

While the cursor is on any identifier call `LSClientGoToDeclaration` (`gd` if
using the default mappings) to jump to the location of the declaration.
If the cursor moves before the server responds the response will be ignored.

### Find references

While the cursor is on any identifier call `LSClientFindReferences` (`gr` if
Expand Down
4 changes: 4 additions & 0 deletions autoload/lsc/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ if !exists('s:initialized')
let s:default_maps = {
\ 'GoToDefinition': '<C-]>',
\ 'GoToDefinitionSplit': ['<C-W>]', '<C-W><C-]>'],
\ 'GoToDeclaration': 'gd',
\ 'GoToDeclarationSplit': ['<C-W>]', '<C-W>gd'],
\ 'FindReferences': 'gr',
\ 'IncomingCalls': 'gi',
\ 'OutgoingCalls': 'gn',
Expand Down Expand Up @@ -55,6 +57,8 @@ function! lsc#config#mapKeys() abort
for l:command in [
\ 'GoToDefinition',
\ 'GoToDefinitionSplit',
\ 'GoToDeclaration',
\ 'GoToDeclarationSplit',
\ 'FindReferences',
\ 'IncomingCalls',
\ 'OutgoingCalls',
Expand Down
18 changes: 13 additions & 5 deletions autoload/lsc/reference.vim
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
let s:popup_id = 0

function! lsc#reference#goToDeclaration(mods, issplit) abort
call lsc#file#flushChanges()
call lsc#server#userCall('textDocument/declaration',
\ lsc#params#documentPosition(),
\ lsc#util#gateResult('GoTo',
\ function('<SID>GoTo', ['declaration', a:mods, a:issplit])))
endfunction

function! lsc#reference#goToDefinition(mods, issplit) abort
call lsc#file#flushChanges()
call lsc#server#userCall('textDocument/definition',
\ lsc#params#documentPosition(),
\ lsc#util#gateResult('GoToDefinition',
\ function('<SID>GoToDefinition', [a:mods, a:issplit])))
\ lsc#util#gateResult('GoTo',
\ function('<SID>GoTo', ['definition', a:mods, a:issplit])))
endfunction

function! s:GoToDefinition(mods, issplit, result) abort
function! s:GoTo(label, mods, issplit, result) abort
if type(a:result) == type(v:null) ||
\ (type(a:result) == type([]) && len(a:result) == 0)
call lsc#message#error('No definition found')
call lsc#message#error('No'. a:label .'found')
return
endif
if type(a:result) == type([]) && len(a:result) == 1
if type(a:result) == type([]) && (a:label ==# 'declaration' || len(a:result) == 1)
let l:location = a:result[0]
elseif type(a:result) == type([]) && len(a:result) > 2
call s:setQuickFixLocations('Definitions', a:result)
Expand Down
8 changes: 8 additions & 0 deletions doc/lsc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ will default to opening a vertical split, while >
<
will prefer a new tab.

*:LSClientGoToDeclaration*
Similiar to |LSClientGoToDefinition| but expects only a single result.
This is not compliant to the current protocol since it accepts multiple
declaration results as well.

*:LSClientGoToDeclarationSplit*
In accordance to |LSClientGoToDeclaration| and |LSClientGoToDefinitionSplit|.

*:LSClientFindReferences*
Populate the |quickfix| with a list of location which reference the element
under the cursor, including it's definition. Sends a "textDocument/references"
Expand Down
4 changes: 4 additions & 0 deletions plugin/lsc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ command! LSClientGoToDefinitionSplit
\ call lsc#reference#goToDefinition(<q-mods>, 1)
command! LSClientGoToDefinition
\ call lsc#reference#goToDefinition(<q-mods>, 0)
command! LSClientGoToDeclarationSplit
\ call lsc#reference#goToDeclaration(<q-mods>, 1)
command! LSClientGoToDeclaration
\ call lsc#reference#goToDeclaration(<q-mods>, 0)
command! LSClientFindReferences call lsc#reference#findReferences()
command! LSClientIncomingCalls call lsc#hierarchy#PrepCallHierarchy("incoming")
command! LSClientOutgoingCalls call lsc#hierarchy#PrepCallHierarchy("outgoing")
Expand Down
5 changes: 5 additions & 0 deletions test/integration/test/vim_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ void main() {
expect(result, '2');
});

test('loads plugin', () async {
final result = await vim.expr('exists(\':LSClientGoToDeclaration\')');
expect(result, '1');
});

test('opens files, has filetype detection', () async {
await vim.edit('foo.txt');
expect(await vim.expr('&ft'), 'text');
Expand Down

0 comments on commit 46d3564

Please sign in to comment.