summaryrefslogtreecommitdiff
path: root/autoload/ale/definition.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/ale/definition.vim')
-rw-r--r--autoload/ale/definition.vim74
1 files changed, 39 insertions, 35 deletions
diff --git a/autoload/ale/definition.vim b/autoload/ale/definition.vim
index 6c7d7d32..984a4f9d 100644
--- a/autoload/ale/definition.vim
+++ b/autoload/ale/definition.vim
@@ -40,16 +40,16 @@ function! ale#definition#HandleLSPResponse(conn_id, response) abort
" The result can be a Dictionary item, a List of the same, or null.
let l:result = get(a:response, 'result', v:null)
- if type(l:result) is type({})
+ if type(l:result) is v:t_dict
let l:result = [l:result]
- elseif type(l:result) isnot type([])
+ elseif type(l:result) isnot v:t_list
let l:result = []
endif
for l:item in l:result
let l:filename = ale#path#FromURI(l:item.uri)
let l:line = l:item.range.start.line + 1
- let l:column = l:item.range.start.character
+ let l:column = l:item.range.start.character + 1
call ale#util#Open(l:filename, l:line, l:column, l:options)
break
@@ -57,6 +57,39 @@ function! ale#definition#HandleLSPResponse(conn_id, response) abort
endif
endfunction
+function! s:OnReady(linter, lsp_details, line, column, options, ...) abort
+ let l:buffer = a:lsp_details.buffer
+ let l:id = a:lsp_details.connection_id
+
+ let l:Callback = a:linter.lsp is# 'tsserver'
+ \ ? function('ale#definition#HandleTSServerResponse')
+ \ : function('ale#definition#HandleLSPResponse')
+ call ale#lsp#RegisterCallback(l:id, l:Callback)
+
+ if a:linter.lsp is# 'tsserver'
+ let l:message = ale#lsp#tsserver_message#Definition(
+ \ l:buffer,
+ \ a:line,
+ \ a:column
+ \)
+ else
+ " Send a message saying the buffer has changed first, or the
+ " definition position probably won't make sense.
+ call ale#lsp#NotifyForChanges(l:id, l:buffer)
+
+ " For LSP completions, we need to clamp the column to the length of
+ " the line. python-language-server and perhaps others do not implement
+ " this correctly.
+ let l:message = ale#lsp#message#Definition(l:buffer, a:line, a:column)
+ endif
+
+ let l:request_id = ale#lsp#Send(l:id, l:message)
+
+ let s:go_to_definition_map[l:request_id] = {
+ \ 'open_in_tab': get(a:options, 'open_in_tab', 0),
+ \}
+endfunction
+
function! s:GoToLSPDefinition(linter, options) abort
let l:buffer = bufnr('')
let [l:line, l:column] = getcurpos()[1:2]
@@ -71,39 +104,10 @@ function! s:GoToLSPDefinition(linter, options) abort
endif
let l:id = l:lsp_details.connection_id
- let l:root = l:lsp_details.project_root
-
- function! OnReady(...) abort closure
- let l:Callback = a:linter.lsp is# 'tsserver'
- \ ? function('ale#definition#HandleTSServerResponse')
- \ : function('ale#definition#HandleLSPResponse')
- call ale#lsp#RegisterCallback(l:id, l:Callback)
-
- if a:linter.lsp is# 'tsserver'
- let l:message = ale#lsp#tsserver_message#Definition(
- \ l:buffer,
- \ l:line,
- \ l:column
- \)
- else
- " Send a message saying the buffer has changed first, or the
- " definition position probably won't make sense.
- call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer)
-
- " For LSP completions, we need to clamp the column to the length of
- " the line. python-language-server and perhaps others do not implement
- " this correctly.
- let l:message = ale#lsp#message#Definition(l:buffer, l:line, l:column)
- endif
-
- let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root)
-
- let s:go_to_definition_map[l:request_id] = {
- \ 'open_in_tab': get(a:options, 'open_in_tab', 0),
- \}
- endfunction
- call ale#lsp#WaitForCapability(l:id, l:root, 'definition', function('OnReady'))
+ call ale#lsp#WaitForCapability(l:id, 'definition', function('s:OnReady', [
+ \ a:linter, l:lsp_details, l:line, l:column, a:options
+ \]))
endfunction
function! ale#definition#GoTo(options) abort