-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Description
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.75.1
- OS Version: MacOS 12.4
Steps to Reproduce:
- (Using the SuperCollider language server https://github.com/scztt/LanguageServer.quark)
- Open a file
- Option+Click a symbol / "Go To Definition" to open the file containing the definition of that symbol
- Modify the opened document
Result:
The language server receives an didChange event for the edit before it has received a didOpen (an explicit requirement of the LSP protocol). In some cases, I observe a mysterious didClose for the document at the place I would expect a didOpen (e.g. when it is opened in vscode). An example sequence of requests from vscode to the language server showing the problem:
LSP communication for "Go To Definition":
>>> {"jsonrpc":"2.0","id":6,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/chrysanth/Desktop/F%20O%20R%20E%20S%20T%20R%20Y/FELT/FELT-control.scd"},"position":{"line":10,"character":28}}}
<<< {"id": "6","result": [{"range": {"end": {"character": 0,"line": 39},"start": {"character": 0,"line": 39}},"uri": "file:///Users/Shared/_code/SuperCollider/cmake-build-RelWithDebInfo/Install/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/Spec.sc"}]}
// document was not opened, but already a foldingRange/codeLens request? This already seems suspicious - but maybe this is allowed?
>>> {"jsonrpc":"2.0","id":7,"method":"textDocument/foldingRange","params":{"textDocument":{"uri":"file:///Users/Shared/_code/SuperCollider/cmake-build-RelWithDebInfo/Install/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/Spec.sc"}}}
>>> {"jsonrpc":"2.0","id":8,"method":"textDocument/codeLens","params":{"textDocument":{"uri":"file:///Users/Shared/_code/SuperCollider/cmake-build-RelWithDebInfo/Install/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/Spec.sc"}}}
// perform edit on Spec.sc...
>>> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///Users/Shared/_code/SuperCollider/cmake-build-RelWithDebInfo/Install/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/Spec.sc","version":2},"contentChanges":[{"range":{"start":{"line":38,"character":0},"end":{"line":38,"character":0}},"rangeLength":0,"text":"\n"}]}}
LSP communication for Option+click:
>>> {"jsonrpc":"2.0","id":5,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/chrysanth/Desktop/F%20O%20R%20E%20S%20T%20R%20Y/FELT/FELT-control.scd"},"position":{"line":10,"character":26}}}
<<< {"id": "5","result": [{"range": {"end": {"character": 0,"line": 39},"start": {"character": 0,"line": 39}},"uri": "file:///Users/Shared/_code/SuperCollider/cmake-build-RelWithDebInfo/Install/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/Spec.sc"}]}
// This is strange, because we have no didOpen and no previous reference to this file since the server was started.
>>> {"jsonrpc":"2.0","method":"textDocument/didClose","params":{"textDocument":{"uri":"file:///Users/Shared/_code/SuperCollider/cmake-build-RelWithDebInfo/Install/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/Spec.sc"}}}
>>> {"jsonrpc":"2.0","id":6,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///Users/chrysanth/Desktop/F%20O%20R%20E%20S%20T%20R%20Y/FELT/FELT-control.scd"},"position":{"line":10,"character":26}}}
<<< {"id": "6","result": [{"range": {"end": {"character": 0,"line": 39},"start": {"character": 0,"line": 39}},"uri": "file:///Users/Shared/_code/SuperCollider/cmake-build-RelWithDebInfo/Install/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/Spec.sc"}]}
>>> {"jsonrpc":"2.0","id":7,"method":"textDocument/foldingRange","params":{"textDocument":{"uri":"file:///Users/Shared/_code/SuperCollider/cmake-build-RelWithDebInfo/Install/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/Spec.sc"}}}
>>> {"jsonrpc":"2.0","id":8,"method":"textDocument/codeLens","params":{"textDocument":{"uri":"file:///Users/Shared/_code/SuperCollider/cmake-build-RelWithDebInfo/Install/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/Spec.sc"}}}
// perform edit on Spec.sc...
>>> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///Users/Shared/_code/SuperCollider/cmake-build-RelWithDebInfo/Install/SuperCollider/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/Spec.sc","version":2},"contentChanges":[{"range":{"start":{"line":38,"character":0},"end":{"line":38,"character":0}},"rangeLength":0,"text":"\n"}]}}
Expected:
At minimum, the LSP spec specifies a textDocument/didOpen before a textDocument/didChange. I'm not clear on whether the spec requires a didOpen before other textDocument requests, but this would also make sense to me.
Notes:
didOpenmessages work normally for other kinds of file open operations, e.g. clicking in the Explorer tree.didClosemessages are issues for documents opened via "Go To Definition" when they are closed in VSCode.- In most repro cases, we are opening a file that is NOT in the current workspace (e.g. in the currently opened folder) (this is an artifact of the programming language, where compiled libraries for which symbols are indexed are generally apart from user code). For cases where the file containing the definition IS in the current workspace, I observe SOME cases where there is a correct
didOpenand some cases where there is still a missingdidOpen. I don't see any obvious differences between cases that work correctly vs don't.