Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Open a file twice, then closing it once, disconnects it from the language server #88

Closed

Description

@kdvolder

In atom you can open a single file more than once, for example, one time in the left-pane and then another copy side-by-side in the right pane.

Both editors will be synced and share the same state. I.e. you make changes on the left, the right editor contents also changes and vice-versa.

When I do this with our language-server it works well, right until the time I close one of the editors. This results in a textDocument/didClose event.

This causes the language server to stop tracking the editor buffer contents. Which in turn means content-assist and linting stops working for that file, even though it is still open in the other editor.

By my reading of the LSP spec, the intention of the didClose event is to signal to the server the point in time when there are no more open editor buffers.

The document close notification is sent from the client to the server when the document got closed in the client. The document's truth now exists where the document's uri points to (e.g. if the document's uri is a file uri the truth now exists on disk).

The language server does and should not care how many editors are opened, it only cares whether or not there is any editor open on a file. So it should only be sent close/open events when the last editor is closed, or the first editor is opened.

Activity

  1. kdvolder commented on Aug 16, 2017

    @kdvolder
    Author

    As a workaround I made our server keep a tally of 'open' calls. So when multiple open are received the count is incremented. When close is received it is decremented. When the tally reaches 0 only then the buffer is considered 'closed'.

    This workaround feels a bit iffy, but it makes our server work correctly with both vscode and atom. Vscode the tally never has a value other than 1 or 0.

  2. hansonw commented on Aug 16, 2017

    @hansonw
    Contributor
  3. kdvolder commented on Aug 16, 2017

    @kdvolder
    Author

    we should probably be observing text buffers rather than text editors.

    Word of caution. It may not be so simple as that. It seems like atom associates language-id to editors not buffers. And since changing a language-id can make the editor contents go out of (or in to) scope this can result in the need to send a close (or open) event.

    I would agree with the 'we should observe buffers' statement, but only if you also then associate language-id with buffers instead of editors.

  4. added a commit that references this issue on Sep 11, 2017
    2b35883
  5. kdvolder commented on Sep 11, 2017

    @kdvolder
    Author

    I looked at the commit that fixes this, it only seems to apply an extra check on close. So am I right to assume, that with this fix, I will still get spurious open events, but only one close event?

    Maybe that's not a great idea, because, workaround I implemented to handle atoms prior behavior actuallt counts open and close events to see if they are balanced. So this fix will actually break our server.

    Granted, it wouldn't break our server had I not implemented a workaround to deal with atom's spurious close events in the first place. (Original implementation of our server would simply ignore spurious open events).

    However, I think, if you buy into the interpretation that close signals the point where 'no more buffers are open'. Then you should also apply the same logic to open events as well and only send an open event at the first time when 'an editor is opened' but not when subsequent editors are opened.

  6. damieng commented on Sep 11, 2017

    @damieng
    Contributor

    I haven't seen any issues with additional open events being sent anywhere during testing. Given that the open event basically says "start tracking this file as we're going to make changes and request operations against it" I find it hard to see what problem extra open events would cause.

  7. damieng commented on Sep 11, 2017

    @damieng
    Contributor

    (That's not to say we can't improve this in the near future, I just need this release nailed down)

  8. kdvolder commented on Sep 11, 2017

    @kdvolder
    Author

    I find it hard to see what problem extra open events would cause.

    The problem it causes is that, because we were accomodating Atom's earlier behavior, we are counting them... so now a single close will not work anymore.

    Its not a big problem, but it means we have to revert our workaround and go back to ignoring spurious opens instead of counting them, and it means our server will work properly on some versions of atoms and break on others. We can't make it work on both older and newer version of atom at the same time.

    So It may be better not to fix this if you don't fix both ends of this, as, in some sense, the 'half assed' fix creates a situation that is worse than the bug.

  9. kdvolder commented on Sep 11, 2017

    @kdvolder
    Author

    BTW: Another little nitpick, I'm not sure its a problem (don't know enough on how Atom's implementation works to be sure). But I am wondering if the 'fixed' version deals properly with considering when you open/close a file and change language id (i.e by clicking in the lower-right status-bar in atom on the language and changing it).

    So for example, let's say I open a file twice with a 'plain' yml editor. Then changed one of the editors to a different language id supported by a language server. Then... close the one with the changed-id. Will I receive a close event or not? (I should, even though the editor is still open, because the still open editor is not considered 'in scope' for my language server).

    Right now, with our workaround, because we count open and close, and because @BoykoAlex submitted a patch to deal with changing language-id. This works fine for us now, despite Atom not following the letter of the spec.

  10. damieng commented on Sep 11, 2017

    @damieng
    Contributor
  11. damieng commented on Sep 11, 2017

    @damieng
    Contributor

    Just created #102 which prevents multiple opens, renames and syncs.

  12. kdvolder commented on Sep 11, 2017

    @kdvolder
    Author

    Which part of the spec refers to the changing of language-id ?

    Don't think its spelled out anywhere how that's supposed to work. But in vscode, open event correspond to when the editor contents becomes 'important' to the server. And close event when its 'no longer important'.

    So, for example you will not get open / close events for .java files if you are a language server that only cares about '.pl' files (or whatever).

    The somewhat 'strange' case is that if a file is already open as some other 'type' and you then change the type, while its open, it suddenly becomes 'important' and you get a open event. Similarly when the type becomes something you don't care about, you get a close.

  13. kdvolder commented on Sep 11, 2017

    @kdvolder
    Author

    Just to illustrate why it might matter, for us is the extensions '.yml' but many 'language-id' can go by that extension. Which means its not uncommon for the 'auto-detection' to get it wrong, and then a user has to manually change the language-id to enable the language server for their specific yml format.

  14. damieng commented on Sep 11, 2017

    @damieng
    Contributor

    You should only be seeing events for the files you care about - that was changed a while ago.

  15. kdvolder commented on Sep 11, 2017

    @kdvolder
    Author

    Correct, and that works fine. And I think Alex submitted a PR that also ensures that changing language-id on open editors causes open/close events as well.

    My concern here was whether the interaction with that 'scoping' mechanic was also taken into account in this fix. Maybe it is, I just couldn't easily tell from the changes, but that may just be because I don't fully understand how it all works.

  16. damieng commented on Sep 11, 2017

    @damieng
    Contributor

    That should be handled fine - it spins up or shuts down the appropriate adapters as the grammars change.

    The problem with this fix wasn't just in fact the open event but also multiple rename events and most troublesome was multiple sync events. In the case of the sync events if the sync was change-based it would get very confused. All that is fixed in the new PR I linked.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions