summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2025-07-22 08:41:57 +0200
committercos <cos>2025-07-22 08:41:57 +0200
commit41f26160e612a32546e151cbcbd88aee35195fe7 (patch)
tree3825de2337abab60cec81b4442b1fc45dc27f031
parent4b1bf3ee8f8516dc52d0a64aef7b6f2723bfea77 (diff)
downloadale-poc/switch_source_header.zip
wip: Possibly add support for clangd's textDocument/switchSourceHeader ?poc/switch_source_header
Issue at: https://github.com/dense-analysis/ale/issues/5007
-rw-r--r--autoload/ale/definition.vim10
-rw-r--r--autoload/ale/lsp.vim4
-rw-r--r--autoload/ale/lsp/message.vim8
-rw-r--r--plugin/ale.vim2
4 files changed, 24 insertions, 0 deletions
diff --git a/autoload/ale/definition.vim b/autoload/ale/definition.vim
index e58a5642..300744dd 100644
--- a/autoload/ale/definition.vim
+++ b/autoload/ale/definition.vim
@@ -229,6 +229,8 @@ function! s:OnReady(line, column, options, capability, linter, lsp_details) abor
let l:message = ale#lsp#message#TypeDefinition(l:buffer, a:line, a:column)
elseif a:capability is# 'implementation'
let l:message = ale#lsp#message#Implementation(l:buffer, a:line, a:column)
+ elseif a:capability is# 'switchsourceheader'
+ let l:message = ale#lsp#message#SwitchSourceHeader(l:buffer)
else
" XXX: log here?
return
@@ -272,6 +274,12 @@ function! ale#definition#GoToImpl(options) abort
endfor
endfunction
+function! ale#definition#SwitchSourceHeader(options) abort
+ for l:linter in ale#lsp_linter#GetEnabled(bufnr(''))
+ call s:GoToLSPDefinition(l:linter, a:options, 'switchsourceheader')
+ endfor
+endfunction
+
function! ale#definition#GoToCommandHandler(command, ...) abort
let l:options = {}
@@ -299,6 +307,8 @@ function! ale#definition#GoToCommandHandler(command, ...) abort
call ale#definition#GoToType(l:options)
elseif a:command is# 'implementation'
call ale#definition#GoToImpl(l:options)
+ elseif a:command is# 'switchsourceheader'
+ call ale#definition#SwitchSourceHeader(l:options)
else
call ale#definition#GoTo(l:options)
endif
diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim
index 07b073f8..7ba5b124 100644
--- a/autoload/ale/lsp.vim
+++ b/autoload/ale/lsp.vim
@@ -490,6 +490,9 @@ function! s:SendInitMessage(conn) abort
\ 'typeDefinition': {
\ 'dynamicRegistration': v:false,
\ },
+ \ 'switchSourceHeader': {
+ \ 'dynamicRegistration': v:false,
+ \ },
\ 'implementation': {
\ 'dynamicRegistration': v:false,
\ 'linkSupport': v:false,
@@ -837,6 +840,7 @@ endfunction
" Check if an LSP has a given capability.
function! ale#lsp#HasCapability(conn_id, capability) abort
+ return 1
let l:conn = get(s:connections, a:conn_id, {})
if empty(l:conn)
diff --git a/autoload/ale/lsp/message.vim b/autoload/ale/lsp/message.vim
index 72ed7d59..36fc43f3 100644
--- a/autoload/ale/lsp/message.vim
+++ b/autoload/ale/lsp/message.vim
@@ -126,6 +126,14 @@ function! ale#lsp#message#Definition(buffer, line, column) abort
\}]
endfunction
+" https://clangd.llvm.org/extensions#switch-between-sourceheader
+function! ale#lsp#message#SwitchSourceHeader(buffer) abort
+ return [0, 'textDocument/switchSourceHeader', {
+ \ 'TextDocumentIdentifier':
+ \ ale#util#ToURI(expand('#' . a:buffer . ':p')),
+ \}]
+endfunction
+
function! ale#lsp#message#TypeDefinition(buffer, line, column) abort
return [0, 'textDocument/typeDefinition', {
\ 'textDocument': {
diff --git a/plugin/ale.vim b/plugin/ale.vim
index ba702956..5b0101b0 100644
--- a/plugin/ale.vim
+++ b/plugin/ale.vim
@@ -297,6 +297,8 @@ command! -bar -nargs=* ALEGoToTypeDefinition :call ale#definition#GoToCommandHan
" Go to implementation for tsserver and LSP
command! -bar -nargs=* ALEGoToImplementation :call ale#definition#GoToCommandHandler('implementation', <f-args>)
+command! -bar -nargs=* ALESwitchSourceHeader :call ale#definition#GoToCommandHandler('switchsourceheader', <f-args>)
+
" Repeat a previous selection in the preview window
command! -bar ALERepeatSelection :call ale#preview#RepeatSelection()