Skip to content
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

fix KeyError exception triggered on closing a window #2401

Merged
merged 1 commit into from
Jan 26, 2024

Conversation

rchl
Copy link
Member

@rchl rchl commented Jan 25, 2024

wm.destroy is called in two cases:

  • from EventListener.on_pre_close_window, before the window is closed
  • from plugin_unloaded hook when LSP package is unloaded

The changed line is triggered in the former case.

As the comment in WindowManager.destroy() says, we should (have to!) call it from the main thread when the plugin is unloaded. But afaics, we don't need to call it from the main thread when closing a window so change the code to not do that.

Calling it from the main thread on window closing triggers a KeyError exception due to DocumentListener.on_close being triggered first and DocumentListener.on_session_shutdown_async later. The latter removes session view from the main thread first and the former tries to remove it again from scheduled execution on the async thread.

Fixes #2399

@predragnikolic
Copy link
Member

predragnikolic commented Jan 25, 2024

Not that related to the PR,
but I have a question,

If you have multiple ST windows, and invoke WindowRegistry.disable, that will nuke all WindowManagers from all ST windows?
If you have multiple ST windows, and invoke WindowRegistry.discard, that will discard only the WindowManager for one ST window?

... I am trying to figure out the difference and consequence of disable and discard.

@rchl
Copy link
Member Author

rchl commented Jan 25, 2024

Yeah, as you said. The discard function takes a window argument while disable doesn't.

@samirbajaj
Copy link

Thank you @rchl for fixing this issue -- much appreciated!

Reviewers -- please approve and merge. Thank you.

@predragnikolic
Copy link
Member

I was only able to reproduce it in safe mode.

I cannot reproduce the exception with this PR.

@predragnikolic predragnikolic merged commit e3a03bc into main Jan 26, 2024
4 checks passed
@predragnikolic predragnikolic deleted the fix/shutdown-error branch January 26, 2024 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KeyError in LSP plugin when trying to open Preferences
3 participants