summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/util.vim5
-rw-r--r--test/test_go_to_definition.vader22
2 files changed, 26 insertions, 1 deletions
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index c01b6dd0..0350efc6 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -56,7 +56,10 @@ function! ale#util#Open(filename, line, column, options) abort
if get(a:options, 'open_in_tab', 0)
call ale#util#Execute('tabedit ' . fnameescape(a:filename))
else
- call ale#util#Execute('edit ' . fnameescape(a:filename))
+ " Open another file only if we need to.
+ if bufnr(a:filename) isnot bufnr('')
+ call ale#util#Execute('edit ' . fnameescape(a:filename))
+ endif
endif
call cursor(a:line, a:column)
diff --git a/test/test_go_to_definition.vader b/test/test_go_to_definition.vader
index 3a1d7458..78373a65 100644
--- a/test/test_go_to_definition.vader
+++ b/test/test_go_to_definition.vader
@@ -187,6 +187,28 @@ Execute(Other files should be jumped to for LSP definition responses):
AssertEqual [3, 7], getpos('.')[1:2]
AssertEqual {}, ale#definition#GetMap()
+Execute(Locations inside the same file should be jumped to without using :edit):
+ call ale#definition#SetMap({3: {'open_in_tab': 0}})
+ call ale#definition#HandleLSPResponse(
+ \ 1,
+ \ {
+ \ 'id': 3,
+ \ 'result': {
+ \ 'uri': ale#path#ToURI(ale#path#Simplify(expand('%:p'))),
+ \ 'range': {
+ \ 'start': {'line': 2, 'character': 7},
+ \ },
+ \ },
+ \ }
+ \)
+
+ AssertEqual
+ \ [
+ \ ],
+ \ g:expr_list
+ AssertEqual [3, 7], getpos('.')[1:2]
+ AssertEqual {}, ale#definition#GetMap()
+
Execute(Other files should be jumped to in tabs for LSP definition responses):
call ale#definition#SetMap({3: {'open_in_tab': 1}})
call ale#definition#HandleLSPResponse(