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 LspToggleInlayHintsCommand not initializing #2571

Merged
merged 5 commits into from
Dec 9, 2024
Merged

Conversation

jwortmann
Copy link
Member

Should fix #2569 I guess.

@@ -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
Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

@jwortmann jwortmann Dec 6, 2024

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.

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

@jwortmann jwortmann Dec 7, 2024

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:

LSP/LSP.sublime-settings

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.

plugin/inlay_hint.py Outdated Show resolved Hide resolved
plugin/inlay_hint.py Outdated Show resolved Hide resolved
@rchl rchl merged commit c64ac00 into main Dec 9, 2024
8 checks passed
@rchl rchl deleted the fix-command-init-error branch December 9, 2024 09:51
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.

LSP.plugin.inlay_hint.LspToggleInlayHintsCommand init failure
2 participants