mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-20 08:38:31 +08:00
Closes #3019 - Implement default navigation
Default navigation for commands that jump to new locations has been implemented with the `ale_default_navigation` variable, and all commands that jump to locations now support `-tab`, `-split`, or `-vsplit` arguments for overriding the default navigation behavior.
This commit is contained in:
@@ -5,6 +5,7 @@ let s:go_to_definition_map = {}
|
||||
|
||||
" Enable automatic updates of the tagstack
|
||||
let g:ale_update_tagstack = get(g:, 'ale_update_tagstack', 1)
|
||||
let g:ale_default_navigation = get(g:, 'ale_default_navigation', 'buffer')
|
||||
|
||||
" Used to get the definition map in tests.
|
||||
function! ale#definition#GetMap() abort
|
||||
@@ -134,6 +135,10 @@ function! s:GoToLSPDefinition(linter, options, capability) abort
|
||||
endfunction
|
||||
|
||||
function! ale#definition#GoTo(options) abort
|
||||
if !get(g:, 'ale_ignore_2_7_warnings') && has_key(a:options, 'deprecated_command')
|
||||
execute 'echom '':' . a:options.deprecated_command . ' is deprecated. Use `let g:ale_ignore_2_7_warnings = 1` to disable this message.'''
|
||||
endif
|
||||
|
||||
for l:linter in ale#linter#Get(&filetype)
|
||||
if !empty(l:linter.lsp)
|
||||
call s:GoToLSPDefinition(l:linter, a:options, 'definition')
|
||||
@@ -142,6 +147,10 @@ function! ale#definition#GoTo(options) abort
|
||||
endfunction
|
||||
|
||||
function! ale#definition#GoToType(options) abort
|
||||
if !get(g:, 'ale_ignore_2_7_warnings') && has_key(a:options, 'deprecated_command')
|
||||
execute 'echom '':' . a:options.deprecated_command . ' is deprecated. Use `let g:ale_ignore_2_7_warnings = 1` to disable this message.'''
|
||||
endif
|
||||
|
||||
for l:linter in ale#linter#Get(&filetype)
|
||||
if !empty(l:linter.lsp)
|
||||
" TODO: handle typeDefinition for tsserver if supported by the
|
||||
@@ -154,3 +163,33 @@ function! ale#definition#GoToType(options) abort
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! ale#definition#GoToCommandHandler(command, ...) abort
|
||||
let l:options = {}
|
||||
|
||||
if len(a:000) > 0
|
||||
for l:option in a:000
|
||||
if l:option is? '-tab'
|
||||
let l:options.open_in = 'tab'
|
||||
elseif l:option is? '-split'
|
||||
let l:options.open_in = 'split'
|
||||
elseif l:option is? '-vsplit'
|
||||
let l:options.open_in = 'vsplit'
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if !has_key(l:options, 'open_in')
|
||||
let l:default_navigation = ale#Var(bufnr(''), 'default_navigation')
|
||||
|
||||
if index(['tab', 'split', 'vsplit'], l:default_navigation) >= 0
|
||||
let l:options.open_in = l:default_navigation
|
||||
endif
|
||||
endif
|
||||
|
||||
if a:command is# 'type'
|
||||
call ale#definition#GoToType(l:options)
|
||||
else
|
||||
call ale#definition#GoTo(l:options)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: Preview windows for showing whatever information in.
|
||||
|
||||
if !has_key(s:, 'last_selection_list')
|
||||
let s:last_selection_list = []
|
||||
endif
|
||||
|
||||
if !has_key(s:, 'last_selection_open_in')
|
||||
let s:last_selection_open_in = 'current-buffer'
|
||||
endif
|
||||
|
||||
" Open a preview window and show some lines in it.
|
||||
" A second argument can be passed as a Dictionary with options. They are...
|
||||
"
|
||||
@@ -67,9 +75,24 @@ function! ale#preview#ShowSelection(item_list, ...) abort
|
||||
|
||||
call ale#preview#Show(l:lines, {'filetype': 'ale-preview-selection'})
|
||||
let b:ale_preview_item_list = a:item_list
|
||||
let b:ale_preview_item_open_in = get(l:options, 'open_in', 'current-buffer')
|
||||
|
||||
" Remove the last preview
|
||||
let s:last_selection_list = b:ale_preview_item_list
|
||||
let s:last_selection_open_in = b:ale_preview_item_open_in
|
||||
endfunction
|
||||
|
||||
function! s:Open(open_in_tab) abort
|
||||
function! ale#preview#RepeatSelection() abort
|
||||
if empty(s:last_selection_list)
|
||||
return
|
||||
endif
|
||||
|
||||
call ale#preview#ShowSelection(s:last_selection_list, {
|
||||
\ 'open_in': s:last_selection_open_in,
|
||||
\})
|
||||
endfunction
|
||||
|
||||
function! s:Open(open_in) abort
|
||||
let l:item_list = get(b:, 'ale_preview_item_list', [])
|
||||
let l:item = get(l:item_list, getpos('.')[1] - 1, {})
|
||||
|
||||
@@ -77,22 +100,20 @@ function! s:Open(open_in_tab) abort
|
||||
return
|
||||
endif
|
||||
|
||||
if !a:open_in_tab
|
||||
:q!
|
||||
endif
|
||||
:q!
|
||||
|
||||
call ale#util#Open(
|
||||
\ l:item.filename,
|
||||
\ l:item.line,
|
||||
\ l:item.column,
|
||||
\ {'open_in_tab': a:open_in_tab},
|
||||
\ {'open_in': a:open_in},
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! ale#preview#OpenSelectionInBuffer() abort
|
||||
call s:Open(0)
|
||||
function! ale#preview#OpenSelection() abort
|
||||
call s:Open(b:ale_preview_item_open_in)
|
||||
endfunction
|
||||
|
||||
function! ale#preview#OpenSelectionInTab() abort
|
||||
call s:Open(1)
|
||||
call s:Open('tab')
|
||||
endfunction
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
let g:ale_default_navigation = get(g:, 'ale_default_navigation', 'buffer')
|
||||
|
||||
let s:references_map = {}
|
||||
|
||||
" Used to get the references map in tests.
|
||||
@@ -99,7 +101,8 @@ function! s:OnReady(line, column, options, linter, lsp_details) abort
|
||||
let l:request_id = ale#lsp#Send(l:id, l:message)
|
||||
|
||||
let s:references_map[l:request_id] = {
|
||||
\ 'use_relative_paths': has_key(a:options, 'use_relative_paths') ? a:options.use_relative_paths : 0
|
||||
\ 'use_relative_paths': has_key(a:options, 'use_relative_paths') ? a:options.use_relative_paths : 0,
|
||||
\ 'open_in': get(a:options, 'open_in', 'current-buffer'),
|
||||
\}
|
||||
endfunction
|
||||
|
||||
@@ -110,10 +113,24 @@ function! ale#references#Find(...) abort
|
||||
for l:option in a:000
|
||||
if l:option is? '-relative'
|
||||
let l:options.use_relative_paths = 1
|
||||
elseif l:option is? '-tab'
|
||||
let l:options.open_in = 'tab'
|
||||
elseif l:option is? '-split'
|
||||
let l:options.open_in = 'split'
|
||||
elseif l:option is? '-vsplit'
|
||||
let l:options.open_in = 'vsplit'
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if !has_key(l:options, 'open_in')
|
||||
let l:default_navigation = ale#Var(bufnr(''), 'default_navigation')
|
||||
|
||||
if index(['tab', 'split', 'vsplit'], l:default_navigation) >= 0
|
||||
let l:options.open_in = l:default_navigation
|
||||
endif
|
||||
endif
|
||||
|
||||
let l:buffer = bufnr('')
|
||||
let [l:line, l:column] = getpos('.')[1:2]
|
||||
let l:column = min([l:column, len(getline(l:line))])
|
||||
|
||||
@@ -91,17 +91,17 @@ endfunction
|
||||
" options['open_in'] can be:
|
||||
" current-buffer (default)
|
||||
" tab
|
||||
" vertical-split
|
||||
" horizontal-split
|
||||
" split
|
||||
" vsplit
|
||||
function! ale#util#Open(filename, line, column, options) abort
|
||||
let l:open_in = get(a:options, 'open_in', 'current-buffer')
|
||||
let l:args_to_open = '+' . a:line . ' ' . fnameescape(a:filename)
|
||||
|
||||
if l:open_in is# 'tab'
|
||||
call ale#util#Execute('tabedit ' . l:args_to_open)
|
||||
elseif l:open_in is# 'horizontal-split'
|
||||
elseif l:open_in is# 'split'
|
||||
call ale#util#Execute('split ' . l:args_to_open)
|
||||
elseif l:open_in is# 'vertical-split'
|
||||
elseif l:open_in is# 'vsplit'
|
||||
call ale#util#Execute('vsplit ' . l:args_to_open)
|
||||
elseif bufnr(a:filename) isnot bufnr('')
|
||||
" Open another file only if we need to.
|
||||
|
||||
Reference in New Issue
Block a user