Repository navigation
fix ClientConfig equality check - #2936
Conversation
|
|
||
| def __eq__(self, other: object) -> bool: | ||
| if not isinstance(other, ClientConfig): | ||
| if not isinstance(other, ClientConfig) or self.name != other.name or self._all_settings != other._all_settings: |
There was a problem hiding this comment.
The first part name of this addition seems redundant if it's also checked below, and the the second part _all_settings feels wrong if we want to define __eq__ as a "dynamic equality". I'd say we should either decide for "dynamic" equality, i.e. later changes to the fields are considered (the change from this PR), or for "static" equality, which considers only the config from the JSON (sublime-settings) file. But with this change, ClientConfigs are only equal if they satisfy both conditions, which doesn't feel right to me.
There was a problem hiding this comment.
Removed redundant name check.
As for _all_settings it's really intended to only contain properties that are not already explicitly exposed on ClientConfig.
There was a problem hiding this comment.
I admit that it's a bit confusing now how it works - the _all_settings contains the original settings but those can drift out of sync with explicitly exposed ClientConfig properties that have the same name. The getter implementation ensured that those shadowed properties can't be accessed on _all_settings but since I've transitioned to root_settings, that's no longer the case.
I'm not sure what would be the best way forward. Current way works only that it can be confusing when it comes to the value of those shadowed keys. Perhaps we should explicitly remove those from _all_settings at least?
There was a problem hiding this comment.
_all_settings contains entire JSON dict from the settings file, except for the "settings" key:
Line 971 in de4034e
Lines 859 to 862 in de4034e
So it compares static "command" / "initialization_options", etc. from the settings file too. So IMO that check should be removed, if we also want to compare the same things with dynamic values.
Btw, that last 2 lines (and comment) aren't necessary anymore after removing that check.
There was a problem hiding this comment.
An alternative would be to keep that check, but remove all known keys from _all_settings. Then config would still be restarted when custom settings change.
There was a problem hiding this comment.
Yes, that was my thinking too.
Though we don't really have programmatically defined list of root properties of sublime-settings config. For example ClientConfig has name property but it should still be allow on all_settings because it's not treated in any special way in sublime-settings.
There was a problem hiding this comment.
I didn't see your previous comment until page reload. Ok, I would probably at least remove command and initialization_options from _all_settings.
I think the two lines I used above could be simplified to self._all_settings.pop('settings', None).
There was a problem hiding this comment.
And now you also didn't see my change before posting. :) We are too fast.
|
By the way, is there any good use case for allowing to modify |
There are good reasons to mutate For example LSP-typescript enables plugins dynamically based on plugins it finds in the plugin host. If LSP-jdtls does something weird then its up to it to do better. |
| 'auto_complete_selector', | ||
| 'command', | ||
| 'diagnostics_mode', | ||
| 'disabled_capabilities', | ||
| 'enabled', | ||
| 'env', | ||
| 'experimental_capabilities', | ||
| 'file_watcher', | ||
| 'initialization_options', | ||
| 'markdown_language_map', | ||
| 'priority_selector', | ||
| 'semantic_tokens', |
There was a problem hiding this comment.
Missed those 3 because those are not documented in https://lsp.sublimetext.io/client_configuration/
|
I think we have broke the |
|
Will look. Do you understand why? |
|
I see, because it's |
|
Yes, so we either need to keep it in |
|
#2940 - decided to use CONFIG_KEYS as a source of truth (and exclude |
In a3bd1df the ClientConfig equality check was simplified to checking
_all_settingsbut that's not correct in case someone changesconfig.initialization_options(or any other explicitly exposed property) after config was created because_all_settingswouldn't get updated in that case.In practice this was maybe not a problem (or not always a problem) because before checking for equality the new config would be re-created from latest sublime settings so both
_all_settingsandinitialization_optionswould change in sync.