Skip to content

Documents opened using window.showTextDocument send a delayed didClose event to LSP #201294

Closed as not planned

Description

@EhabY

Version/OS information:

Version: 1.85.1 (system setup)
Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
Date: 2023-12-13T09:49:37.021Z
Electron: 25.9.7
ElectronBuildId: 25551756
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.22621

Steps to Reproduce:

  1. Setup an LSP for some language
  2. Create a file of said language
  3. Open the file using the window.showTextDocument -> This will (correctly) send a didOpen request
  4. Close the file -> Does not didClose for a while

Using the commands API (commands.executeCommand("vscode.open", resourceUri, options)) seems to work as expected (more interactive)

Related but the documentation for "vscode.open" seems to have been deleted: https://code.visualstudio.com/api/references/commands

Reopening the file does not resend a didOpen request and closing the tab does not send a didClose - so it must be that (for some reason) closing the file is delayed significantly. After waiting for 5 minutes, a didClose is actually emitted but it is very strange that using the commands API it is more predictable and interactive than the window API

Activity

  1. changed the title [-]Documents opened using `window.showTextDocument` do not emit `didClose` event to LSP[/-] [+]Documents opened using `window.showTextDocument` send a delayed `didClose` event to LSP[/+] on Dec 20, 2023
  2. added
    *question
    on Dec 20, 2023
  3. vscodenpa commented on Dec 20, 2023

    @vscodenpa

    We closed this issue because it is a question about using VS Code rather than an issue or feature request. Please search for help on StackOverflow, where the community has already answered thousands of similar questions. You may find their guide on asking a new question helpful if your question has not already been asked. See also our issue reporting guidelines.

    Happy Coding!

  4. jrieken commented on Dec 20, 2023

    @jrieken
    Contributor

    Close the file -> Does not didClose for a while

    This is as designed and documented. The editor decides when to close a document by its own rules. Note that document !== editor !== tab and if you wanna track tab changes you should use the corresponding APIs

  5. EhabY commented on Dec 20, 2023

    @EhabY
    ContributorAuthor

    The editor decides when to close a document by its own rules.

    I understand that but it seems there is inconsistency between using window.showTextDocument and commands.executeCommand("vscode.open"). For example, if you open a file from the explorer and close it, an event is emitted immediately which is the desired behavior and matches the documents opened using the commands API but not the window API. The docs do not cover such cases (https://code.visualstudio.com/api/references/commands)

  6. szarnekow commented on Dec 20, 2023

    @szarnekow

    Let me describe the user case:
    A language server performs more thorough validation for open documents vs files that are in the project. When using the command API, an editor is opened, the server reports a number of diagnostics and the user can perceive this as related to their own interaction with VS code. If they close the document, the regular validations are restored and the additional feedback diagnostics disappear - also perceived as a reaction to the user input.

    With the window API, it's not possible anymore for the user, to understand the changed number of diagnostics "a while after the user interaction" based on the editors "own rules". This is not related to tab handling or anything.

    Johannes Rieken (@jrieken) Do you understand the use case and if so, can you confirm that the UX is inferior with the window.showTextDocument behavior compared to exectureCommand?

  7. jrieken commented on Dec 20, 2023

    @jrieken
    Contributor

    Ehab Younes (@EhabY) Sebastian Zarnekow (@szarnekow) Why are you not using the tabs API (vscode.window.tabGroups) which was built specifically with diagnostics in mind

  8. szarnekow commented on Dec 20, 2023

    @szarnekow

    The language server is implemented for different front ends. I don't feel like replicating everything that's already handled by didOpen and didClose. What is the advantage of doing a client-specific implementation?

  9. jrieken commented on Dec 20, 2023

    @jrieken
    Contributor

    I don't feel like replicating everything that's already handled by didOpen and didClose.

    Well, isn't the whole point of this discussion that not every is handled via didOpen and didClose and that you are using the wrong tool for the job. There is more shortcomings with your approach

    • didOpen is fired when ctrl+hovering
    • didOpen is fired when an extension uses the openTextDocument (which is !== showTextDocument)
    • didOpen is usually fired for every file another time because for quick diff'ing an original version of the document is tracked
    • didOpen is not fired for tabs after restore/reload
    • didClose is fired based on ref-counting, timeout and memory pressure strategies
    • etc pp

    What is the advantage of doing a client-specific implementation?

    You have something that works better

  10. locked and limited conversation to collaborators on Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

*question

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions