Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol extensions #15

Open
Shatur opened this issue Mar 24, 2020 · 20 comments
Open

Protocol extensions #15

Shatur opened this issue Mar 24, 2020 · 20 comments

Comments

@Shatur
Copy link
Contributor

Shatur commented Mar 24, 2020

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.

@hrsh7th
Copy link
Owner

hrsh7th commented Mar 25, 2020

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
Copy link
Owner

hrsh7th commented Mar 25, 2020

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
Copy link
Owner

hrsh7th commented Mar 25, 2020

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

@Shatur
Copy link
Contributor Author

Shatur commented Mar 25, 2020

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?

@hrsh7th
Copy link
Owner

hrsh7th commented Mar 25, 2020

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?

@Shatur
Copy link
Contributor Author

Shatur commented Mar 25, 2020

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

@hrsh7th
Copy link
Owner

hrsh7th commented Mar 26, 2020

OK, I will install clangd.

@hrsh7th
Copy link
Owner

hrsh7th commented Mar 26, 2020

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

@Shatur
Copy link
Contributor Author

Shatur commented Mar 26, 2020

😅 Thank you a lot! It works. Maybe include this into plugin? It will be very helpful for C++ developers. Maybe as an option?

@hrsh7th
Copy link
Owner

hrsh7th commented Mar 26, 2020

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?

@Shatur
Copy link
Contributor Author

Shatur commented Mar 26, 2020

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.

@hrsh7th
Copy link
Owner

hrsh7th commented Mar 26, 2020

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

I'm japanese so I worry to naming everytime.

@Shatur
Copy link
Contributor Author

Shatur commented Mar 26, 2020

vim-lamp-extensions

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

@hrsh7th
Copy link
Owner

hrsh7th commented Apr 9, 2020

llvm/llvm-project@71177ac#diff-bc83abf3e556418f438c09a672856449

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

@Shatur
Copy link
Contributor Author

Shatur commented Apr 9, 2020

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

@hrsh7th
Copy link
Owner

hrsh7th commented Apr 9, 2020

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.

@Shatur
Copy link
Contributor Author

Shatur commented Apr 9, 2020

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

@Shatur
Copy link
Contributor Author

Shatur commented Apr 22, 2020

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?

@hrsh7th
Copy link
Owner

hrsh7th commented Apr 23, 2020

No.
It related to textDocument/documentHighlight capability.

@Shatur
Copy link
Contributor Author

Shatur commented May 13, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants