-
-
Notifications
You must be signed in to change notification settings - Fork 898
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
json-parse-error \u0000 is not allowed without JSON_ALLOW_NUL #2681
Comments
I dont see that file. |
Ok, I found that there is LuaUtils.hpp, investigating... |
Can you share what version of emacs do you use and what server? I am unable to repro with emacs 27.1 and clangd. |
Happens with the ccls server (reproduced on versions |
I've seen this same error with some source files, with ccls. I haven't tried to determine if I can reproduce it with the same set of files, after restarting Emacs / clearing the ccls cache. There is, definitely, no actual nul character in the source files. I don't know if this is an error in the ccls server (or the llvm parser) or if it's on the Emacs side. I'm using Emacs 27.1 / lsp-mode 20210223 / ccls 0.20201025 |
I would expect this to be a |
@snyball can you tell what you did to cause that issue? I.e. where was your cursor? If this can be reproduced reliably, we could find out where in ccls this is caused using |
@nbfalcon I don't know exactly what I'm doing in particular to cause the bug other than opening the file, then I get the warning. I also get it every other second when moving around the file. You could try setting |
@snyball I have |
For reference, I use $ ccls --version
ccls version 0.20201219-2-ga2d2fd81
clang version 10.0.0-4ubuntu1 |
I am facing the same issue. If it would be useful, I could provide the repo containing the file that is triggering this same behaviour. |
@orlandini can you reliably reproduce this? I believe it would be insanely helpful if we could get an |
Yes, it does happen everytime I open this file in a buffer. Would you please tell me how to generate this log? I can do it right away. |
@orlandini type |
You will find the result in |
I don't think that it will show up here because we print the IO after deserializing it in order to pretty-print it. @orlandini you may try |
The alternative is to capture the input/output outside of emacs, something like this - #843 (comment) |
After
lsp-log: ccls:1952936:
When doing
This happens as soon as I open the file. |
AFAICS the problematic element is Meanwhile, the following snippet will fix the issue:
|
A minimal example that triggers this issue, either with template <class T> struct Q { T n; };
struct X {
template <class T> operator Q<T>() {}
}; The bug seems to be caused by template cast operators, and I suspect it is an issue with ccls' interning code. This is definitely a {
"jsonrpc": "2.0",
"id": 21242,
"result": [
{
"name": "Q",
"detail": "struct Q {}",
"kind": 23,
"range": {
"start": {
"line": 0,
"character": 19
},
"end": {
"line": 0,
"character": 36
}
},
"selectionRange": {
"start": {
"line": 0,
"character": 26
},
"end": {
"line": 0,
"character": 27
}
},
"children": [
{
"name": "n",
"detail": "T Q::n",
"kind": 8,
"range": {
"start": {
"line": 0,
"character": 30
},
"end": {
"line": 0,
"character": 33
}
},
"selectionRange": {
"start": {
"line": 0,
"character": 32
},
"end": {
"line": 0,
"character": 33
}
},
"children": []
}
]
},
{
"name": "X",
"detail": "struct X {}",
"kind": 23,
"range": {
"start": {
"line": 2,
"character": 0
},
"end": {
"line": 4,
"character": 1
}
},
"selectionRange": {
"start": {
"line": 2,
"character": 7
},
"end": {
"line": 2,
"character": 8
}
},
"children": [
{
"name": "operator Q<T>()\u0000struct Q {}\u0000T ",
"detail": "operator Q<T>()",
"kind": 6,
"range": {
"start": {
"line": 3,
"character": 21
},
"end": {
"line": 3,
"character": 39
}
},
"selectionRange": {
"start": {
"line": 3,
"character": 21
},
"end": {
"line": 3,
"character": 34
}
},
"children": []
}
]
}
]
} |
@nbfalcon thank you. Closing the bug. Please report it in ccls repo and/or use the solution from #2681 (comment) |
Just leaving this here in case anyone stumbles over it: (advice-add 'json-parse-buffer :around
(lambda (orig &rest rest)
(while (re-search-forward "\\u0000" nil t)
(replace-match ""))
(apply orig rest))) This worked around the issue for me on Emacs 28. According to @ktfleming in typescript-language-server/typescript-language-server#559, Emacs 29 should fix the issue, but I haven't confirmed that myself. Here's a complete workaround, though it might be somewhat inefficent. |
This is a common issue with LSP servers and patching this from inside Emacs (by advising parsing functions) is highly inefficient. See: - emacs-lsp/lsp-mode#2681 (comment) - typescript-language-server/typescript-language-server#559 (comment) - https://github.com/jadestrong/lsp-volar#hacks The patch is extracted from Emacs 29.
To add to @adimit 's solution, I had both to double escape the backslash, and add save-excursion (because 'json-parse-buffer fails if cursor is not at the start of the buffer): (advice-add 'json-parse-buffer :around
(lambda (orig &rest rest)
(save-excursion
(while (re-search-forward "\\\\u0000" nil t)
(replace-match "")))
(apply orig rest))) (Otherwise, it just removes u0000, but leaves the backslash symbol, still causing a json parse error). |
Describe the bug
Certain C++ files produce the following window popup warning message:
To Reproduce
Clone the https://github.com/snyball/Hawck master branch, and open the
src/LuaUtils.h
file.Expected behavior
Did not expect to get that warning.
Which Language Server did you use
ccls
OS
Linux.
The text was updated successfully, but these errors were encountered: