vim-lamp icon indicating copy to clipboard operation
vim-lamp copied to clipboard

Protocol extensions

Open Shatur opened this issue 5 years ago • 20 comments

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.

Shatur avatar Mar 24 '20 08:03 Shatur

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.

hrsh7th avatar Mar 25 '20 05:03 hrsh7th

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

hrsh7th avatar Mar 25 '20 05:03 hrsh7th

semantic highlights is bit interesting. I will implement it if I don't busy.

hrsh7th avatar Mar 25 '20 05:03 hrsh7th

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?

Shatur avatar Mar 25 '20 14:03 Shatur

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?

hrsh7th avatar Mar 25 '20 14:03 hrsh7th

Of course! Tested, but I have the same error.

Shatur avatar Mar 25 '20 18:03 Shatur

OK, I will install clangd.

hrsh7th avatar Mar 26 '20 03:03 hrsh7th

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

hrsh7th avatar Mar 26 '20 10:03 hrsh7th

: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?

Shatur avatar Mar 26 '20 16:03 Shatur

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?

hrsh7th avatar Mar 26 '20 17:03 hrsh7th

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.

Shatur avatar Mar 26 '20 17:03 Shatur

Is vim-lamp-extensions good for you? So I will create it.

I'm japanese so I worry to naming everytime.

hrsh7th avatar Mar 26 '20 17:03 hrsh7th

vim-lamp-extensions

As for me yes, but I'm not native speaker too, I'm Ukrainian :)

Shatur avatar Mar 26 '20 17:03 Shatur

https://github.com/llvm/llvm-project/commit/71177ac16801ceced4b7dcdd21b05345416f31df#diff-bc83abf3e556418f438c09a672856449

The clangd seems supported textDocument/sementicTokens. I plan to implement it.

hrsh7th avatar Apr 09 '20 15:04 hrsh7th

This is not the same as semantic highlighting? It looks like it was added 17 days ago and will be released in clangd 11.

Shatur avatar Apr 09 '20 15:04 Shatur

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.

hrsh7th avatar Apr 09 '20 16:04 hrsh7th

Nice ti hear. Will wait for the implementation :) I also can compile clangd from source to test if needed.

Shatur avatar Apr 09 '20 16:04 Shatur

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?

Shatur avatar Apr 22 '20 20:04 Shatur

No. It related to textDocument/documentHighlight capability.

hrsh7th avatar Apr 23 '20 00:04 hrsh7th

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.

Shatur avatar May 13 '20 22:05 Shatur