Handle unsaved files in main language server client #2124
Merged
+20
−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.
Motivation
With the changes in #2101, we regressed with an interesting bug. Because of the narrower document selector, we were simply ignoring unsaved files.
Theoretically, that shouldn't case any issues since we're just ignoring them. However, received reports of #1897 (comment) happening again and indeed it's easy to reproduce on main.
That issue only happens when we receive an unexpected request for a document before a
textDocument/didOpen
notification gets sent for it (which should never happen).The reason it's happening is the bug we identified microsoft/vscode-languageserver-node#1487, where the LSP package is sending unexpected semantic token requests without respecting the document selector.
So, the order of the events were:
textDocument/didOpen
notification for it, because we were accidentally ignoring it in the document selectorQuite an interesting interaction of different issues.
Implementation
For unsaved files, it's not possible to know to which workspace they belong to. That information only exists after the user chooses where to save the file.
What we need to do is have the main language client (the first one) handle all files while they are unsaved. If the user decides to save the file in a workspace that does not belong to that main client, that is completely fine. VS Code will actually send
didClose
notifications for theuntitled:Untitled-1
uri and then send adidOpen
notification for the file that was just saved to the correct language client.The implementation is not the prettiest, but I don't know how else we could go about it.