-
Notifications
You must be signed in to change notification settings - Fork 184
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 LspToggleInlayHintsCommand not initializing #2571
Conversation
plugin/inlay_hint.py
Outdated
@@ -21,7 +21,9 @@ class LspToggleInlayHintsCommand(LspWindowCommand): | |||
|
|||
def __init__(self, window: sublime.Window) -> None: | |||
super().__init__(window) | |||
window.settings().set('lsp_show_inlay_hints', userprefs().show_inlay_hints) | |||
settings = userprefs() | |||
default = settings.show_inlay_hints if settings is not None else False |
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.
Note that I put a literal False
here if userprefs()
is None, because I assume that we cannot use sublime.load_settings('LSP.sublime-settings')
before plugin_loaded()
.
This would only affect the very first window(s) which is/are open when Sublime Text starts.
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.
It's kinda not great to assume false when it might not be false.
Could we just not store anything on init
and only do so when the command is run?
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.
Yeah, actually that should work.
We could use window_settings.get('lsp_show_inlay_hints', userprefs().show_inlay_hints)
in run
and in is_checked
.
Though this would be a behavior change in the way that when you change the value in the LSP settings, that change would also propagate to all windows where it hasn't been explicitly toggled yet. So I'm not sure if this is expected / the right thing to do.
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.
We could also delay reading the default and setting the window setting via using a sublime.set_timeout
in __init__
.
But I'm not sure if it is allowed to use set_timeout
before plugin_loaded
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'm sure set_timeout is allowed but it doesn't sound very robust.
I don't feel like the case you've mentioned is something that we should need to avoid. It sounds fine to me to follow the global setting until explicitly changing the window setting.
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 think I would not quite like that, because it might appear very inconsistent to users. If you have multiple windows open and change the value in the settings, then it might be toggled in some of the windows but not in all. And since with my latest commit the window setting will be preserved when initializing, the manual toggle could have happened a long time ago and it would still have an effect here.
So I'd say the toggles should either be a global over all windows (I suggested that earlier when it was implemented, but we decided to not do this), or keep the current behavior and use the setting value only for newly created windows. The latter is also what is explained in the setting description:
Lines 176 to 178 in 8b7afad
// This is the default value used for new windows but can be overriden per-window | |
// using the `LSP: Toggle Inlay Hints` command from the Command Palette, Main Menu | |
// or a custom keybinding. |
Should fix #2569 I guess.