Skip to content

Add options to only sync visible documents to the server #848

Closed

Description

@DanTup

This is slightly related to microsoft/vscode#15178. Right now there's no way for an editor to know when a document is either "open" or "visible" in a way that matches the users expectation:

Open in this sense means it is managed by the client. It doesn’t necessarily mean that its content is presented in an editor.

There are many situations where a server would like to know what files a user has open (or visible). For example:

  • The user wants to ignore lints/errors in certain files - for example files generated by tools
  • When the user opens the file in the editor, they want to see these errors/lints (eg. to debug something going wrong in them)
  • When the user closes the file, they expect the errors/lints to disappear (immediately, not after 3 minutes)

Even though VS Code doesn't have an API for "open editors", it does have an API for "visible editors". Even if VS Code plans to never support "open editors" it would be very useful for LSP to provide "visible editors". On the other hand, if VS Code does add support for "open editors", then that could be provided instead/as well. In either case, it seems like LSP needs some changes to support one or the other (or both).

(as a workaround, I'm considering implementing custom messages in the VS Code extension + LSP server to pass the "visible editors" over to the server.. it feels really hacky though).

Activity

  1. dbaeumer commented on Jun 24, 2020

    @dbaeumer
    Member

    I am very reluctant to sync UI state to the server. We really tried hard to not do this. I do see the problem with the diagnostics and the problem there is that it is a pure push model. So there are discussion to allow a pull model as well where this again would go back under the control of the editor. See microsoft/language-server-protocol#737

    And even using VS Code visible editor will not help since there is no API for the tab model (e.g. you don't want to see lint errors disappear for editors for which there is still an open tab).

    Any objection to fold this with microsoft/language-server-protocol#737

  2. DanTup commented on Jun 24, 2020

    @DanTup
    ContributorAuthor

    I am very reluctant to sync UI state to the server. We really tried hard to not do this.

    In Dart the server has a concept of "priority files". That means if there are multiple outstanding requests for multiple files, those that are marked priority are processed first. These are intended to be set to the visible (or at least open) files. Without allowing the server to know what files the user has open (or visible), this isn't possible (currently for non-LSP we use visible files and it works great - for LSP we have to use "open" files which is a bit wonky).

    I do see the problem with the diagnostics and the problem there is that it is a pure push model. So there are discussion to allow a pull model as well where this again would go back under the control of the editor. See microsoft/language-server-protocol#737

    This seems like it would increase server resources (especially if more things move to this model). Servers will have to start caching more data (or re-computing it frequently) if the client can ask for it at any time. The client is already caching it to show it in its UI - having the server able to tell the client when it changes feels like a better model to me.

    That said - I'm not sure how it solves this issue. How does the server know whether to include the "excluded" file when the client asks for all diagnostics? (I'm assuming the client would ask for all, and not individually for each open file - as that would just lead to a lot of complaints - see microsoft/vscode#13953).

    And even using VS Code visible editor will not help since there is no API for the tab model (e.g. you don't want to see lint errors disappear for editors for which there is still an open tab).

    Errors disappearing (for excluded files) when you tab to another file is a lot more understandable than randomly vanishing up to 3 minutes later (and perhaps even appearing when you don't have the file open, since didOpen makes no guarantees the user actually opened the file) :-)

  3. dbaeumer commented on Jul 2, 2020

    @dbaeumer
    Member

    To avoid caching on the server side we are looking into the concept of batch requests (see microsoft/language-server-protocol#988).

    The current concept in LSP is that it is under the clients control what data is visible and what data therefore need to be priorities.

    And the concept of an open editor is not enough. A tool could for example show the outline inline in the file explorer and therefore the outline needs to be priorities. So if we let the server decide this then we need to let servers know about what is visible in the UI and what not in terms of LSP requests.

  4. DanTup commented on Jul 2, 2020

    @DanTup
    ContributorAuthor

    A tool could for example show the outline inline in the file explorer and therefore the outline needs to be priorities. So if we let the server decide this then we need to let servers know about what is visible in the UI and what not in terms of LSP requests.

    That's true, but I was thinking about things that are pushed from the server (like errors) - if a user opens a project of 5000 files, the server needs to parse/lint them all, and doing the open files first is most useful.

    I don't think batching helps the case I had in mind, which is the client asking the server for some data multiple times even if it hasn't changed. For example if the client asks the server for errors multiple times, the server has to either keep a cache of them, or re-compute them. Batching requests seems like it could prevent parsing the file multiple times for different requests, but I don't think it prevents requiring the server to keep copies of the data or re-compute them.

    I also don't think this addresses the original need though - which is wanting to show errors for some files only when they're open. Even if the errors were pulled from the server, they would still persist when the file was closed unless there was some mechanism to tell the client only to show them while the file is open.

  5. dbaeumer commented on Jul 2, 2020

    @dbaeumer
    Member

    That's true, but I was thinking about things that are pushed from the server (like errors)

    I agree with that case but it is the ONLY case in LSP where the server pushes. Everything else is pull. So instead of having a UI model sync for errors I would prefer having a pull model for errors.

    And errors are not only presented in the editor. There are problem views and decorations in the file explorer.

  6. DanTup commented on Jul 2, 2020

    @DanTup
    ContributorAuthor

    I agree with that case but it is the ONLY case in LSP where the server pushes. Everything else is pull. So instead of having a UI model sync for errors I would prefer having a pull model for errors.

    But doesn't pull mean the server has to invalidate everything on every change? If a user is typing inside a comment - with a push model, the server doesn't need to send any new errors, outline, code fixes, etc. - but if the client is pulling, it's going to keep asking for these and forcing the server to compute them (or keep a cache of them). And when the extension host is remote (Codespaces, etc.) it seems like the extra latency/slow round trips would make this worse?

    That aside - I still don't think any of that addresses this need. Even in a pull model, it doesn't allow us to show errors for ignored files only while they're open.

  7. DanTup commented on Nov 3, 2020

    @DanTup
    ContributorAuthor

    #683 is a related issue. VS Code fires did-open events whenever a file is opened (which includes things like extensions opening them, or the hover preview when holding Ctrl/Cmd), which ends up at the LSP server and causes it to start analyzing files that have never been opened.

  8. dbaeumer commented on Nov 1, 2021

    @dbaeumer
    Member

    Danny Tuppeny (@DanTup) did you have any chance to look at the new pull model. I would like to close this issue since I really don't want to sync UI state.

  9. DanTup commented on Nov 1, 2021

    @DanTup
    ContributorAuthor

    Dirk Bäumer (@dbaeumer) I've not looked at this yet - last time I looked I couldn't find the related info (I just had a quick search of the specs and still can't see anything obviously related to pulling diagnostics?), and also this same issue affects us in many other ways that are not all related to diagnostics so I was hoping for a more general fix.

    For example, our server likes to prioritize and cache parsed results for files that are "open" but not for every file in the workspace.

  10. dbaeumer commented on Nov 4, 2021

    @dbaeumer
    Member

    The proposed implementation and spec is here:

    #### <a href="#pull_diagnostic" name="pull_diagnostic" class="anchor">Pull Diagnostics</a>
    and
    /* --------------------------------------------------------------------------------------------

  11. dbaeumer commented on Nov 4, 2021

    @dbaeumer
    Member

    For the more general fix. When VS Code has a proper tab model I will add support to the LSP libs to configure if open should be send for invisible files or not. But this will be an implementation detail in the extension / libs.

  12. DanTup commented on Nov 8, 2021

    @DanTup
    ContributorAuthor

    Thanks - I'll have a dig through that and see whether it would be useful.

    this will be an implementation detail in the extension / libs.

    I still think there could be value in discussing this in the spec (for benefit of other servers/editors), but I don't know that any other editors using our server are doing what VS Code is, so solving it there probably solves the issue entirely (at least for me) anyway.

    Feel free to move this to the LSP lib repo, or I can do it if you want to close this one. Thanks!

  13. changed the title [-]Support notifying the server of which documents are visible in the client[/-] [+]Add options to only sync visible documents to the server[/+] on Nov 9, 2021
  14. 30 remaining items

  15. DanTup commented on Jul 3, 2024

    @DanTup
    ContributorAuthor

    That sounds good to me, thank you! :)

    Will these releases be tied to the next version of LSP? (it's not clear to me what the release schedule is for LSP, I think it's been a while since the last release and I haven't tried to use a client for the new version yet).

  16. mhuisi commented on Jul 3, 2024

    @mhuisi

    I looked into it and here is what I think would make sense to implement to not make things overly complicated:

    * if a document is opened and it is NOT visible in a editor the open event will be delayed
    
    * if the editor opens or any other request / notification is trigger (except a close of the delayed document) the open notification will be forwarded to the server.
    

    This behavior will go behind a flag in the client options.

    First cut of the code is in dbaeumer/bottom-eagle-chocolate

    If you think that this would help for your scenarios I will make next releases so that you can give it a try.

    Thanks, sounds good! :-)

  17. dbaeumer commented on Jul 5, 2024

    @dbaeumer
    Member

    The new client version 10.0.0-next.9 has the mention support. LanguageClientOptions#textSynchronization.delayOpenNotifications is the flag to control the behavior.

    Please note that the way how the client and server exports their API has changed. It is now based on the exports property in the package.json to allow further move to new features. See the Readme for details.

  18. DanTup commented on Jul 8, 2024

    @DanTup
    ContributorAuthor

    Dirk Bäumer (@dbaeumer) I tested this out and it seems to work as described. If I hold ctrl and hover over a bunch of symbols without clicking, it prevents the open/closed events (which also avoids the Dart server doing some analysis and producing some notifications we normally want for open files). Thanks!

    Out of interest, do you have some approx target for when this client/next LSP will ship? (I'm not in any rush, it's just useful for my planning).

  19. dbaeumer commented on Jul 8, 2024

    @dbaeumer
    Member

    After summer vacation :-) (August or September)

  20. DanTup commented on Jul 8, 2024

    @DanTup
    ContributorAuthor

    Great, thanks! :-)

  21. DanTup commented on Nov 26, 2024

    @DanTup
    ContributorAuthor

    Dirk Bäumer (@dbaeumer) I presume this version was delayed - do you have any new approximate ETA for it? (I won't hold you to it, it'll just help me plan/prioritise things if I know when it might be coming :-))

  22. dbaeumer commented on Nov 27, 2024

    @dbaeumer
    Member

    Danny Tuppeny (@DanTup) sorry about that. Will definitely be next year. Need to focus on something else the last couple of month.

  23. DanTup commented on Nov 27, 2024

    @DanTup
    ContributorAuthor

    Dirk Bäumer (@dbaeumer) no problem, thanks for the update!

  24. DanTup commented on Feb 11, 2025

    @DanTup
    ContributorAuthor

    Dirk Bäumer (@dbaeumer) I saw a new next version of the client was published last week - does this mean a release is close or are there other things you're planning to do first? There are no open issues in the Next milestone here, but two in the LSP one - however they both just look like spec clarifications and not new work.

    FWIW I did some testing of both this change and the CompletionItem.defaults.data merging with the latest next against the Dart server, and both are working great 🙂

    Thanks!

  25. modified the milestones: Next, on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions