diff options
Diffstat (limited to 'autoload/ale/definition.vim')
-rw-r--r-- | autoload/ale/definition.vim | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/autoload/ale/definition.vim b/autoload/ale/definition.vim index b20c01a0..6c70b64c 100644 --- a/autoload/ale/definition.vim +++ b/autoload/ale/definition.vim @@ -13,20 +13,8 @@ function! ale#definition#SetMap(map) abort let s:go_to_definition_map = a:map endfunction -" This function is used so we can check the execution of commands without -" running them. -function! ale#definition#Execute(expr) abort - execute a:expr -endfunction - -function! ale#definition#Open(options, filename, line, column) abort - if a:options.open_in_tab - call ale#definition#Execute('tabedit ' . fnameescape(a:filename)) - else - call ale#definition#Execute('edit ' . fnameescape(a:filename)) - endif - - call cursor(a:line, a:column) +function! ale#definition#ClearLSPData() abort + let s:go_to_definition_map = {} endfunction function! ale#definition#HandleTSServerResponse(conn_id, response) abort @@ -34,12 +22,12 @@ function! ale#definition#HandleTSServerResponse(conn_id, response) abort \&& has_key(s:go_to_definition_map, a:response.request_seq) let l:options = remove(s:go_to_definition_map, a:response.request_seq) - if get(a:response, 'success', v:false) is v:true + if get(a:response, 'success', v:false) is v:true && !empty(a:response.body) let l:filename = a:response.body[0].file let l:line = a:response.body[0].start.line let l:column = a:response.body[0].start.offset - call ale#definition#Open(l:options, l:filename, l:line, l:column) + call ale#util#Open(l:filename, l:line, l:column, l:options) endif endif endfunction @@ -63,7 +51,7 @@ function! ale#definition#HandleLSPResponse(conn_id, response) abort let l:line = l:item.range.start.line + 1 let l:column = l:item.range.start.character - call ale#definition#Open(l:options, l:filename, l:line, l:column) + call ale#util#Open(l:filename, l:line, l:column, l:options) break endfor endif @@ -77,14 +65,13 @@ function! s:GoToLSPDefinition(linter, options) abort \ ? function('ale#definition#HandleTSServerResponse') \ : function('ale#definition#HandleLSPResponse') - let l:lsp_details = ale#linter#StartLSP(l:buffer, a:linter, l:Callback) + let l:lsp_details = ale#lsp_linter#StartLSP(l:buffer, a:linter, l:Callback) if empty(l:lsp_details) return 0 endif let l:id = l:lsp_details.connection_id - let l:root = l:lsp_details.project_root if a:linter.lsp is# 'tsserver' let l:message = ale#lsp#tsserver_message#Definition( @@ -95,7 +82,7 @@ function! s:GoToLSPDefinition(linter, options) abort else " Send a message saying the buffer has changed first, or the " definition position probably won't make sense. - call ale#lsp#Send(l:id, ale#lsp#message#DidChange(l:buffer), l:root) + call ale#lsp#NotifyForChanges(l:lsp_details) let l:column = min([l:column, len(getline(l:line))]) @@ -105,7 +92,7 @@ function! s:GoToLSPDefinition(linter, options) abort 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:root) + 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), |