Open rlivings39 opened 4 years ago
Can you point me to lsp-sample.el ?
It should be under vscode-extension-samples/lsp-sample/
in the repo you cloned git@github.com:rlivings39/vscode-extension-samples.git
https://github.com/rlivings39/vscode-extension-samples/blob/master/lsp-sample/lsp-sample.el
Thank you. There seem to be two issues:
(json-serialize ["�"]) ;; fails
(json-encode ["�"]) ;; works fine
The first one fails and the second does not.
@eli-zaretskii can you comment whether this is something that has to be fixed in json-serialize?
@rlivings39 can you change the definition of lsp--json-serialize and verify that the scenario works fine when using clangd(note that this is a macro and you have to evaluate the whole lsp-mode buffer).
(defmacro lsp--json-serialize (params)
`(let ((json-false :json-false))
(json-encode ,params)))
(json-serialize ["�"]) ;; fails
Do you mean the wrong-type-argument error? AFAIU, that's expected, because #x3fff85 is not a Unicode codepoint. The author of json.c had very strong views regarding signaling an error in these cases, and you see that in action.
How did that character end up in JSON data?
Btw, we have the capability to automatically convert such invalid characters to U+FFFD, which I believe is TRT in these cases anyway, since the underlying JSON library will be unable to handle any non-Unicode characters anyway. But I need the agreement of json.c author to make such a change, so if you think this is desired, please report an Emacs bug, and we will discuss this with the json.c author.
we have the capability to automatically convert such invalid characters to U+FFFD
Alternatively, we can skip them. It's all a matter of a decision.
What do other similar processors do with such characters?
@yyoncho clangd seems to work with that change. I still see the issue with lsp-sample
we have the capability to automatically convert such invalid characters to U+FFFD
Alternatively, we can skip them. It's all a matter of a decision.
What do other similar processors do with such characters?
@MaskRay can you advise? I don't have expertise on the matter.
@yyoncho I had an exchange on the node language server library repo regarding the same issue:
https://github.com/microsoft/vscode-languageserver-node/issues/643
in case any of that information may help here.
Describe the bug When a document contains the character with codepoint
#x3fff85
the LSP server receives invalid JSON or errors occur in Emacs.Note that using the same C++ file with clangd in VSCode doesn't encounter any issues.
To Reproduce with clangd Make a small test C++ file in the lsp-docker docker:
Then start lsp:
M-x lsp
with clangd as the language server (it's part of the docker image). Notice that you can get completions:shows completions brought in by
#include <vector>
. Now move your cursor right after the:
in the comment on the first line and do:M-x insert-char RET #x3fff85 RET
to insert the character we happened to have in our files.Then try to save the cpp file. When doing so I see errors like:
in the
*Messages*
buffer.To Reproduce with lsp-sample LSP server When using an LSP server derived from the Microsoft LSP framework, this results in a JSON parse error:
To reproduce that:
Edit
lsp-sample.el
to point toserver/out/server.js
in your clone. ThenM-x load-file /path/to/lsp-sample.el
.txt
file, insert the bad character as aboveM-x insert-char RET #x3fff85 RET
, and startlsp-mode
*lsp-sample::stderr*
Expected behavior No errors with strange characters.
Which Language Server did you use clangd with C++
OS Debian 9
Error callstack
lsp-log.txt lsp-log-clangd.txt lsp-log-clangd-stderr.txt