hrsh7th / vim-lamp-extensions

2 stars 0 forks source link

Set textDocument/didChange with wantDiagnostics on buffer change #2

Open Shatur opened 4 years ago

Shatur commented 4 years ago

I just discovered that clangd have custom wantDiagnostics property in textDocument/didChange. Could you add an option to send textDocument/didChange with wantDiagnostics set to true on buffer change? I think it how QtCreator works. This could solve https://github.com/hrsh7th/vim-lamp/issues/23. It would be very cool improvement for C/C++ developers. I posted it here because this property is extension. I understand that this plugin currently not implemented, but just for the future.

hrsh7th commented 4 years ago

I was tried using wantDiagnostics but It seems not to effect to behavior that we want.

But I think we should have ability to modify all payload via extension side so I leave this issue.

Shatur commented 4 years ago

I was tried using wantDiagnostics but It seems not to effect to behavior that we want it.

Bad to hear :( Sometimes I need to reload the file to trigger diagnostics to reload.

hrsh7th commented 4 years ago

What do you think about following command?

"
" reload_document
"
command! ReloadDocument call s:reload_document()
function! s:reload_document()
  let l:bufnr = bufnr('%')
  let l:bufname = bufname(l:bufnr)
  enew
  let l:temp_bufnr = bufnr('%')
  try
    execute printf('%sbdelete!', l:bufnr)
  catch /.*/
  endtry
  execute printf('edit! %s', fnameescape(l:bufname))
  try
    execute printf('%sbdelete!', l:temp_bufnr)
  catch /.*/
  endtry
endfunction

Sorry, I don't want to include for vim-lamp as much as possible the feature that does not relate the LSP.

Shatur commented 4 years ago

Thank you, I will use it. Unfortunately, this also reloads the syntax highlighting, but this is better than reloading the document manually...

Sorry, I don't want to include for vim-lamp as much as possible the feature that does not relate the LSP.

Of course, it's completely okay. It's just clangd problem. Now I trying to figure out how QtCreator deal with it. It works perfectly, I even do not need to save header file on disk.

hrsh7th commented 4 years ago

OK. I will try to implement reloading document completely with refactor.

hrsh7th commented 4 years ago

I found the workaround that more convenient than the currently proposed one.

command! TouchDocument call s:touch_document() 
function! s:touch_document() abort
  let l:bufnr = bufnr('%')
  for l:server in lamp#server#registry#find_by_filetype(&filetype)
    call l:server.notify('textDocument/didChange', {
    \   'textDocument': lamp#protocol#document#versioned_identifier(l:bufnr),
    \   'contentChanges': []
    \ })
  endfor
endfunction

NOTE: Working this workaround is dependent to clangd implementation.

Shatur commented 4 years ago

I found the workaround that more convenient than the currently proposed one.

Thank you a lot! Will use it.

I will try to implement reloading document completely with refactor.

I think that the solution above will be enough.

Sorry for stupid question, but can the issue caused by missing support workspace/didChangeWatchedFiles?

hrsh7th commented 4 years ago

I think workspace/didChangeWatchedFiles does not relate to the problem.

hrsh7th commented 4 years ago

Because probably VSCode has supported the feature but the problem exists.

Shatur commented 4 years ago

@hrsh7th, anyway, thanks for the TouchDocument :)

Because probably VSCode has supported the feature but the problem exists.

Yes, you are right...

hrsh7th commented 4 years ago

I thinking we implement automatic document touch feature in vim-lamp-extension is nice (until the clangd's diagnostics will improved)

Shatur commented 4 years ago

It would be nice, I think that here is the best place for such things.