Skip to content

Commit

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

This reverts commit 46d3564.
  • Loading branch information
kohnish committed Jun 30, 2023
1 parent 47e29d3 commit 2a1b853
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 70 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ 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
5 changes: 0 additions & 5 deletions autoload/lsc/config.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
let s:default_maps = {
\ 'GoToDefinition': '<C-]>',
\ 'GoToDefinitionSplit': ['<C-W>]', '<C-W><C-]>'],
\ 'GoToDeclaration': 'gd',
\ 'FindReferences': 'gr',
\ 'IncomingCalls': 'gi',
\ 'OutgoingCalls': 'gn',
Expand Down Expand Up @@ -53,8 +52,6 @@ function! lsc#config#mapKeys() abort
for l:command in [
\ 'GoToDefinition',
\ 'GoToDefinitionSplit',
\ 'GoToDeclaration',
\ 'GoToDeclarationSplit',
\ 'FindReferences',
\ 'IncomingCalls',
\ 'OutgoingCalls',
Expand Down Expand Up @@ -106,8 +103,6 @@ function! lsc#config#UnmapKeys() abort
for l:command in [
\ 'GoToDefinition',
\ 'GoToDefinitionSplit',
\ 'GoToDeclaration',
\ 'GoToDeclarationSplit',
\ 'FindReferences',
\ 'IncomingCalls',
\ 'OutgoingCalls',
Expand Down
75 changes: 30 additions & 45 deletions autoload/lsc/reference.vim
Original file line number Diff line number Diff line change
@@ -1,63 +1,48 @@
let s:popup_id = 0

function! lsc#reference#goToDeclaration(mods, issplit) abort
call lsc#common#FileFlushChanges()
call lsc#server#userCall('textDocument/declaration',
\ lsc#params#documentPosition(),
\ lsc#common#GateResult('GoTo',
\ { msg -> s:GoTo('declaration', a:mods, a:issplit) }, []))
endfunction

function! lsc#reference#goToDefinition(mods, issplit) abort
call lsc#common#FileFlushChanges()
call lsc#server#userCall('textDocument/definition',
\ lsc#params#documentPosition(),
\ lsc#common#GateResult('GoTo',
\ function('<SID>GoTo', ['definition', a:mods, a:issplit]), []))
\ lsc#common#GateResult('GoToDefinition', { msg -> s:GoToDefinition(a:mods, a:issplit, msg) }, [])
\ )
endfunction

function! s:GoTo(label, mods, issplit, result) abort
function! s:GoToDefinition(mods, issplit, result) abort
if !has_key(a:result, "result")
echom a:result
return
endif
let l:result = a:result["result"]
if type(l:result) == type(v:null) ||
\ (type(l:result) == type([]) && len(l:result) == 0)
call lsc#message#error('No'. a:label .'found')
call lsc#message#error('No definition found')
return
endif
if type(l:result) == type([]) && (a:label ==# 'declaration' || len(l:result) == 1)
let l:location = l:result[0]
elseif type(l:result) == type([]) && len(l:result) > 1
call s:setQuickFixLocations('Definitions', l:result)
let l:results = a:result["result"]
if type(l:results) == type([]) && len(l:results) == 1
let l:location = l:results[0]
elseif type(l:results) == type([]) && len(l:results) > 2
call s:setQuickFixLocations('Definitions', l:results)
copen
else
let l:location = l:result
let l:location = l:results
endif
if exists('l:location')
let l:file = lsc#uri#documentPath(l:location.uri)
let l:line = l:location.range.start.line + 1
let l:character = l:location.range.start.character + 1
let l:dotag = &tagstack && exists('*gettagstack') && exists('*settagstack')
if l:dotag
let l:from = [bufnr('%'), line('.'), col('.'), 0]
let l:tagname = expand('<cword>')
let l:stack = gettagstack()
if l:stack.curidx > 1
let l:stack.items = l:stack.items[0:l:stack.curidx-2]
else
let l:stack.items = []
endif
let l:stack.items += [{'from': l:from, 'tagname': l:tagname}]
let l:stack.curidx = len(l:stack.items)
call settagstack(win_getid(), l:stack)
endif
call s:goTo(l:file, l:line, l:character, a:mods, a:issplit)
if l:dotag
let l:curidx = gettagstack().curidx + 1
call settagstack(win_getid(), {'curidx': l:curidx})
let l:file = lsc#uri#documentPath(l:location.uri)
let l:line = l:location.range.start.line + 1
let l:character = l:location.range.start.character + 1
let l:dotag = &tagstack && exists('*gettagstack') && exists('*settagstack')
if l:dotag
let l:from = [bufnr('%'), line('.'), col('.'), 0]
let l:tagname = expand('<cword>')
let l:stack = gettagstack()
if l:stack.curidx > 1
let l:stack.items = l:stack.items[0:l:stack.curidx-2]
else
let l:stack.items = []
endif
let l:stack.items += [{'from': l:from, 'tagname': l:tagname}]
let l:stack.curidx = len(l:stack.items)
call settagstack(win_getid(), l:stack)
endif
call s:goTo(l:file, l:line, l:character, a:mods, a:issplit)
if l:dotag
let l:curidx = gettagstack().curidx + 1
call settagstack(win_getid(), {'curidx': l:curidx})
endif
endfunction

Expand Down
9 changes: 0 additions & 9 deletions doc/lsc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ will default to opening a vertical split, while >
<
will prefer a new tab.

*:LSClientGoToDeclaration*
Similiar to |LSClientGoToDefinition| but expects only a single result when
issuing the default binding `gd`.
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
5 changes: 0 additions & 5 deletions test/integration/test/vim_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ 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 2a1b853

Please sign in to comment.