languageserver icon indicating copy to clipboard operation
languageserver copied to clipboard

Cannot parse document with incomplete codes

Open zhenhua-wang opened this issue 2 years ago • 5 comments

When having an incomplete statement (e.g. a <- ), rlanguageserver cannot parse the document, i.e. languageserver:::parse_document(file, readLines(file)) returns NULL.

This happens because some editors (e.g. emacs with imenu) inspect the code outline as I type. The editor then freezes when I reach to a <- because of the timeout error.

I also tried this using python language server. It seems that they ignore incomplete codes when parsing the document. Is it also possible for rlanguageserver to ignore incomplete codes when parsing the document?

zhenhua-wang avatar Jun 21 '22 19:06 zhenhua-wang

It is unfortunate due to the limitation of the current parser. We are using a parser which could only parse syntactically correct documents. There is tree-sitter-r, but I don't have any experiences with it.

Regarding the freeze, I think there may be a bug in https://github.com/REditorSupport/languageserver/blob/7398fea984792864433a901ee18d3d6f719468e2/R/symbol.R#L53-L58 @renkun-ken, I think we should either return an error of empty reply, not NULL.

randy3k avatar Jun 21 '22 19:06 randy3k

I spoke too soon, it should actually return NULL. We have a mechanism to retry parsing the document at https://github.com/REditorSupport/languageserver/blob/05e7e673f426f73c9a40d8377872f594e2443a5a/R/handlers-langfeatures.R#L113 Perhaps we should put a timeout there?

randy3k avatar Jun 21 '22 19:06 randy3k

@zhenhua-wang I think it is also partially an issue of the editor plugin that you are using. The plugin should be inspecting the outline (document symbols) asynchronously to avoid blocking the user.

randy3k avatar Jun 21 '22 19:06 randy3k

@randy3k Thank you for the quick response. That's good point about inspecting asynchronously, but it unfortunately might be a historical issue for Emacs... Both lsp-mode and eglot would wait for a response from the server. Until then the entire emacs is freeze.

I guess having a timeout might helps, but at the meantime lsp-mode (or eglot) is still expecting some response from the server. Maybe we can return the last response if there is any? (Sorry I am not very sure about how the server works ...)

zhenhua-wang avatar Jun 21 '22 20:06 zhenhua-wang

I'm seeing this problem with the built-in LSP features from neovim too.

jolars avatar Jul 09 '22 17:07 jolars