-
Notifications
You must be signed in to change notification settings - Fork 183
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
Ensure didChange notification is never sent after didClose #2438
Ensure didChange notification is never sent after didClose #2438
Conversation
This fixes for example the Pyright warning LSP-pyright: Received change text document command for closed file <URI> when a file is saved and closed immediately after changes were applied.
The described bug can be observed on the main branch using a key binding like {
"keys": ["f1"],
"command": "chain",
"args": {
"commands": [
["insert", {"characters": "TEST"}],
["save", {"async": false}],
["close", {}]
]
}
}, It doesn't seem to happen always, but most of the time. And keep another file open so the server doesn't shutdown afterwards. I don't know why the test on Linux fails; the change from a previous |
I am on Linux and I can't reproduce the error in pyright with the above keybinding. When I add the keybinding, I'm also not sure if this PR is the correct way to address the issue. It would make sense to asset and make sure that didChange is always send before didClose |
I can reproduce it quite easily on Windows and the log looks like this:
It also makes sense to me that this bug can be observed, because Line 300 in 550d591
but there is no such debouncing for The request suppression is not directly related to this fix, it is just a further optimization. I just didn't want to create another extra PR for that. The fix is that now |
According to failing CI in #2439, https://github.com/sublimelsp/LSP/actions/runs/8493731798/job/23268129591?pr=2439
|
view.change_count() returns 0 if the view isn't valid anymore (closed), so we can simply use short-circuit evaluation for this and don't need the is_valid() API call.
Ok i think the CI tests are flaky. And all the test pass on Linux locally.
|
This reverts commit 4dd2e91.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will wait a bit, to see if others will take a look, before I merge this.
So I decided to test this once more. On Linux when I use the following keybinding:
The order notifications is the following: I expected
I also tested with other servers.
Note this is Linux. Will test on a Mac tonight. I also get the same order of notifications in Windows: |
Are you sure that you are on the correct branch? |
Yes, can confirm that I am on the correct branch |
I tried to test a few more times,
So I dig into it. If I have two files hello.py and hello2.py
...but not always. If i focus the
|
Interesting... but I have no explanation for that, nor can I reproduce it on my PC :D I've tried the same a few times (open file with Ctrl+P, then immediately press the key binding), but I always get the same result:
Another difference is that I never see the Actually it is not good that it doesn't always work correctly when the open and closing happen fast, because this was exactly the use case with the autosaving & close when applying workspace edits, from the other PR. But I can't see where the code could possibly go wrong. |
I merged it into the other PR, but I would prefer to merge this one seperately first. I don't know if we can find the cause for the strange and different behaviors and remaining bugs, but even if not, I think this should still be an improvement to the current behavior on the And thanks for the debugging help 😄 |
This should fix for example the Pyright warning
when a file is saved and closed immediately after changes were applied. This bug wasn't noticed yet, because there is no automatic saving and closing of files implemented yet, and it's unlikely to happen within the debounce time if done manually.
I cherry picked from #2433 because it can be its own PR and to check whether this is the cause for a dubious test failure on Linux.