You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Repository navigation
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
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.
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.
On Wed, Aug 16, 2017 at 8:38 AM Kris De Volder ***@***.***> wrote:
As a workaround I made our server keep a tally of 'open' calls. So when
multiple open are received the count is increment. 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.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#88 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAjPYgiifO_4KqSVvkHT2qrPegaasxpiks5sYw0CgaJpZM4O36aJ>
.
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.
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.
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.
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.
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.
On Mon, Sep 11, 2017 at 10:51 AM Kris De Volder ***@***.***> wrote:
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 <https://github.com/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.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#88 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHQp2QWRRqXcpvhhrNwzFZEoGya3xyuks5shXMMgaJpZM4O36aJ>
.
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.
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.
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.
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.
Activity
kdvolder commentedon Aug 16, 2017
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.
hansonw commentedon Aug 16, 2017
kdvolder commentedon Aug 16, 2017
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.
Do not close if file open in another editor, fixes #88
kdvolder commentedon Sep 11, 2017
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.
damieng commentedon Sep 11, 2017
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.
damieng commentedon Sep 11, 2017
(That's not to say we can't improve this in the near future, I just need this release nailed down)
kdvolder commentedon Sep 11, 2017
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.
kdvolder commentedon Sep 11, 2017
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.
damieng commentedon Sep 11, 2017
damieng commentedon Sep 11, 2017
Just created #102 which prevents multiple opens, renames and syncs.
kdvolder commentedon Sep 11, 2017
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.
kdvolder commentedon Sep 11, 2017
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.
damieng commentedon Sep 11, 2017
You should only be seeing events for the files you care about - that was changed a while ago.
kdvolder commentedon Sep 11, 2017
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.
damieng commentedon Sep 11, 2017
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.