-
Notifications
You must be signed in to change notification settings - Fork 328
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
Spec says "diagnostics are cleared by the server when the file is closed" but didOpen/didClose may not match what the user sees #684
Comments
I'm running into this too. In addition when our server gets the |
Actually this has nothing to do with the spec. It is more an implementation problem in VS Code and the VS Code LSP libs. I am moving the issue. |
@kjeremy if you leave the version empty it will clear the errors for the current version of the file known on the client side. To implement this correctly in VS Code (in terms what is visible to the user) we would need API from VS Code to get access to the tab model. Then by default we can filter non visual opens and allow clients in the middleware to override that default behavior. |
But right now the spec suggests the close event is not tied to the user closing the document (see quotes at the top of this issue). Based on the spec, even if VS Code gets a tab model, it's still valid for it not to send a Close event until minutes after the user closes the editor. So I think the spec still needs updating. Either it should say that open/close do match what the user sees, or there should be other events. Otherwise this seems like it still will not work as expected. |
The open/close events (although named open /close) are ownership events no visual events. They say that an open transfers the ownership of the document to the client and a close back to the server. I see the point that in systems that have single file validation the current model is not sufficient. But IMO the solution can't be to tweak these ownership events. I also think that even a tab model might not help. An editor could decide to show content of a file in something different than a tab (e.g. an editable outline where you can rearrange methods using D&D). The reason why I think a simple sentence in the spec will not help is: it doesn't fix the problem. This is why I am reluctant to write something. IMO we first need to understand what a better solution would be. The best I could come up with so far is a pull model for diagnostics since it will allow the client to pull depending on what it presents. I will write a sentence in the spec that the open / close events do not necessarily reflect what the user sees in the UI. |
Added that sentence:
|
@dbaeumer I agree with everything you said, though is the new note on the open/close event or in PublishDiagnostics? I guess the issue is that the text under PublishDiagnostics that says "diagnostics are cleared by the server when the file is closed" is a little misleading and maybe should also call it out and/or link to that new note:
|
The test I added is under PublishDiagnostics Notification |
Ah yes, I see it now. Much clearer - thanks! |
My understanding from this text:
and similar comments is that servers cannot assume that the
textDocument/onDidClose
means a document was just closed. Nor can it assume thatonDidOpen
actually relates to a document being open.However, the spec also says this:
This two things appear to conflict. If a server is never able to tell when a file is (in the users opinion) opened or closed, it seems like the single-file mode cannot be implemented (or at least, the experience may result in errors appearing for files the user has not opened, and not disappearing after they close them).
Interestingly - I reviewed the TypeScript code because it seems to be clearing errors when I close files - and found that it's actually using the VS Code close event as a signal to hide the errors:
https://github.com/microsoft/vscode/blob/e41c19505142614f706ad853bd5c4c2ad0f74e89/extensions/typescript-language-features/src/features/bufferSyncSupport.ts#L500-L502
https://github.com/microsoft/vscode/blob/3841f78377fc02ab5ef514cbd0fa760ed4ac6f0d/extensions/typescript-language-features/src/typescriptServiceClient.ts#L159
It's not clear what should be done here. In Dart we're trying to provide some errors only when files are open (which the LSP spec describes, and the VS Code TS extension does), but it's been suggested (multiple times) that we should not assume this behaviour.
Is it possibly to clarify how the "single file mode" described above is intended to be implemented (if indeed, it should)? Thanks!
The text was updated successfully, but these errors were encountered: