Protocol extensions
Are you planning on implementing protocol extensions? I would like to suggest to add Semantic highlighting. It's implemented in vim-lsp(hove some performance issues!) and LanguageClient-neovim. Also It is supported in other editors (in VSCode, for example). This is very useful, and I think it could become the standard. Also I would like to suggest to add Switch between source/header extension. It's already implemented in vim-lsp-clangd-switch. This is needed only for C / C++, but very convenient.
Semantic Highlighting is not official spec so I would not be planning implement it but... The semanticTokens is official spec candidates.
Protocol extensions can be implemented but I don't plan it. But I can providing the code snippet for the support it.
command! LampClangdSwitchSourceHeader call s:clangd_switch_source_header()
function! s:clangd_switch_source_header() abort
if &filetype !=# 'cpp'
return
endif
let l:server = lamp#server#registry#get_by_name('clangd name')
if empty(l:server)
echomsg 'clangd does not exists'
return
endif
let l:header = lamp#sync(l:server.request('textDocument/switchSourceHeader', {
'textDocument': lamp#protocol#document#identifier(bufnr('%'))
});
if strlen(l:header) == 0
echomsg 'source header does not found.'
return
endif
execute printf('edit %s', fnameescape(lamp#protocol#document#decode_uri(l:header)))
endfunction
semantic highlights is bit interesting. I will implement it if I don't busy.
Semantic Highlighting is not official spec so I would not be planning implement it but... The semanticTokens is official spec candidates. I will implement it if I don't busy.
Yes, I hope it will be merged into standard. If I understood correctly, clangd uses it now. Thank you for your interest.
But I can providing the code snippet for the support it.
Thanks for the snippet! But I can't get it working. I fixed missing closing bracket in lamp#sync and added two / to indicate newline. So, I use the following:
command! LampClangdSwitchSourceHeader call s:clangd_switch_source_header()
function! s:clangd_switch_source_header() abort
if &filetype !=# 'cpp'
return
endif
let l:server = lamp#server#registry#get_by_name('clangd')
if empty(l:server)
echomsg 'clangd does not exists'
return
endif
let l:header = lamp#sync(l:server.request('textDocument/switchSourceHeader', {
\ 'textDocument': lamp#protocol#document#identifier(bufnr('%'))
\ }))
if strlen(l:header) == 0
echomsg 'source header does not found.'
return
endif
execute printf('edit %s', fnameescape(lamp#protocol#document#decode_uri(l:header)))
endfunction
But it gives me the following error:
Am I using it correctly?
Oh... clangd is strange...
https://github.com/micchy326/vim-lsp-clangd-switch/blob/master/autoload/lsp_clangd_switch.vim#L23
It seems we should change to uri instead of textDocument: { uri: ... }.
command! LampClangdSwitchSourceHeader call s:clangd_switch_source_header()
function! s:clangd_switch_source_header() abort
if &filetype !=# 'cpp'
return
endif
let l:server = lamp#server#registry#get_by_name('clangd')
if empty(l:server)
echomsg 'clangd does not exists'
return
endif
let l:header = lamp#sync(l:server.request('textDocument/switchSourceHeader', {
\ 'uri': lamp#protocol#document#identifier(bufnr('%'))
\ }))
if strlen(l:header) == 0
echomsg 'source header does not found.'
return
endif
execute printf('edit %s', fnameescape(lamp#protocol#document#decode_uri(l:header)))
endfunction
Could you test this on your environment?
Of course! Tested, but I have the same error.
OK, I will install clangd.
Sorry, it was simple mistake 😅
command! LampClangdSwitchSourceHeader call s:clangd_switch_source_header()
function! s:clangd_switch_source_header() abort
if &filetype !=# 'c'
return
endif
let l:server = lamp#server#registry#get_by_name('clangd')
if empty(l:server)
echomsg 'clangd does not exists'
return
endif
let l:header = lamp#sync(l:server.request('textDocument/switchSourceHeader', {
\ 'uri': lamp#protocol#document#identifier(bufnr('%')).uri
\ }))
if strlen(l:header) == 0
echomsg 'source header does not found.'
return
endif
execute printf('edit %s', fnameescape(lamp#protocol#document#decode_uri(l:header)))
endfunction
:sweat_smile: Thank you a lot! It works. Maybe include this into plugin? It will be very helpful for C++ developers. Maybe as an option?
If we provide it, we should create separated plugin.
But I can't think of it's name.
vim-lamp-ext? vim-lamp-extension-pack?
vim-lamp-extension-pack
Personally, I like this variant more because it more self-explanatory :)
Or just vim-lamp-extensions look good as for me too.
Is vim-lamp-extensions good for you? So I will create it.
I'm japanese so I worry to naming everytime.
vim-lamp-extensions
As for me yes, but I'm not native speaker too, I'm Ukrainian :)
https://github.com/llvm/llvm-project/commit/71177ac16801ceced4b7dcdd21b05345416f31df#diff-bc83abf3e556418f438c09a672856449
The clangd seems supported textDocument/sementicTokens.
I plan to implement it.
This is not the same as semantic highlighting? It looks like it was added 17 days ago and will be released in clangd 11.
The semanticTokens is an official spec candidate but the sementicHighlights is not.
And the sementicHighlights is heavy in vim because all tokens are encoded to base64. the sementicTokens has no this problem.
Nice ti hear. Will wait for the implementation :) I also can compile clangd from source to test if needed.
I have a question. vim-lsp have Highlight references feature. It just add semi-transparent rectangle on reference under cursor by default:
Is this related to semantic highlighting or semantic tokens?
No. It related to textDocument/documentHighlight capability.
I found a solution to have fast sementicHighlights with vim-lamp that available in current clangd release. I just installed LanguageClient-neovim and configured only semantic highlighting in it (without any diagnostics). Maybe someone will be interested.