Tolerate "processId":null that may be send by Emacs LSP client #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Emacs LSP client sends the "initialize" JSON request containing
null
in place of theprocessId
:(The full sample JSON send by Emacs client is in the attached test application.)
This causes JSON reading in
Initialize
to fail to read the following information, in particular it fails to read theRootUri
. More precisely, the loopends prematurely, before we've actually seeen all parameters. Briefly looking at
TJsonReader
implementation, I understand that the expectation is that one should callReader.Null
in case the value may benull
in JSON, to allowTJsonReader.Null
to doStackPop; Reduce;
.I'm attaching
test_json.lpr
, a simple JSON reader test (using onlyJSONStream
unit, nothing else). I used this to confirm the issue and test the solution. It contains hardcoded JSON requests I logged from Emacs and VS Code (for comparison) LSP clients. If you comment out theinside and run it, you will get:
So in case of Emacs JSON, the only
key
found inparams
wasprocessId
.Uncommenting the code doing
Reader.Null
, we get the desired result, androotUri
is correctly parsed for both VS Code client and Emacs client:test_json.lpr.txt
The lack of
RootUri
seems to have dire consequences for pasls: It reports then that it cannot find units from LCL, likeLaz_AVL_Tree
fromLazUtils
package, in my test on michaliskambi/elisp#1 . Despite the log showing it can find thelazutils.lpk
correctly. In effect, code completion in Emacs with this LSP server was failing for me when some LCL unit likeLaz_AVL_Tree
was used. I didn't analyze further (how lack ofRootUri
is causing this, despitelazutils.lpk
being found), but makingRootUri
correctly detected fixed everything :)Side investigation: Why does Emacs LSP client send
"processId":null
?I found it clearly done in the lsp-mode source code: They literally pass
:processId nil
in https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-mode.el#L7480 . There's no attempt to initializeprocessId
to anything non-nil, nor any comment why.Curiously, I run
git blame
on it, and found this commit: emacs-lsp/lsp-mode@e7c7abf that exactly changes it from valid Emacs PID to a hardcodednil
.It leads to sending nil pid emacs-lsp/lsp-mode#1408 which leads to Intermittent connection in typescript-language-server via Docker-tramp emacs-lsp/lsp-mode#1240 for reasoning. Looks like in some scenarios with Emacs+Docker, the PID would be invalid, as the LSP server would be in a container and LSP client (Emacs) PID would come from outside. The invalid PID would in turn cause some LSP servers to exit. So it's better to send a
nil
PID than to allow LSP servers to rely on it.