-
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 "disable server globally" command for LSP packages #1907
Fix "disable server globally" command for LSP packages #1907
Conversation
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.
The downside of that is that we clean up the
Package Storage
folder.
While I agree with the fix, this should no longer be true. The storage should only be removed on uninstalling the package now.
The only thing is that my fix doesn't work, because of this import error:
Looks like a recursive import loop.
Not that trivial to fix. Might require some refactoring.
i saw boot.py
I fixed the import loop, But currently all settings keys are inserted. Which is not what I want. Kapture.2021-11-28.at.17.08.12.mp4 |
When I call plugin_settings, plugin_settings_name = plugin.configuration()
settings_basename = os.path.basename(plugin_settings_name)
plugin_settings.set("enabled", is_enabled)
sublime.save_settings(settings_basename) ST will save create a key in the setting file for each set field. (example It turns out that |
Your need to manually load the user overrides file (and create if missing). |
I took a different approach. I overwrote the: class ClientHandler(AbstractPlugin, ClientHandlerInterface):
"""
The base class for creating an LSP plugin.
"""
# --- AbstractPlugin handlers -------------------------------------------------------------------------------------
@classmethod
def name(cls) -> str:
return cls.get_displayed_name()
@classmethod
def configuration(cls) -> Tuple[sublime.Settings, str]:
+ name = cls.name()
+ basename = "{}.sublime-settings".format(name)
+ filepath = "Packages/{}/{}".format(name, basename)
+ return sublime.load_settings(basename), filepath
- @classmethod
- def configuration(cls) -> Tuple[sublime.Settings, str]:
- return cls.read_settings() and that fixed the issue. Kapture.2021-11-28.at.17.36.46.mp4 |
Can you tell me how to read the settings and override it? I tried with:
but that approach doesn't work as it will give the same result as in the video above. So I am not sure on to manually load the user overrides file. Are you suggesting |
Manually read the file like in Line 668 in c608b43
But since the issue is more or less caused by lsp_utils, maybe it should be fixed there (though can't immediately tell how). |
Searching github for all uses of |
Because you know lsp_utils more than I do, I still will try to give my assumptions to this: (but keep in mind that I might be very wrong). To me the main cause to me seems to be @classmethod
def read_settings(cls) -> Tuple[sublime.Settings, str]:
...
for key in cls.get_default_settings_schema().keys():
loaded_settings.set(key, settings_copy[key]) # mutates the settings object here, without saving
filepath = "Packages/{}/{}".format(cls.package_name, filename)
return (loaded_settings, filepath)
While I think that we can fix it in class ClientHandler(AbstractPlugin, ClientHandlerInterface):
@classmethod
def configuration(cls) -> Tuple[sublime.Settings, str]:
+ name = cls.name()
+ basename = "{}.sublime-settings".format(name)
+ filepath = "Packages/{}/{}".format(name, basename)
+ return sublime.load_settings(basename), filepath
- @classmethod
- def configuration(cls) -> Tuple[sublime.Settings, str]:
- return cls.read_settings() I am not sure how to fix it for
As I think it is used for ST 3 only. Which would mean that this wont be fixed for ST3 users. |
As far as I can see, the problem is not so much with it not saving the settings (since that would trigger the same problem that you have, just earlier), but the fact that it mutates the settings. We can't just skip that part, as you did with your change, as we need to extend I think that a proper solution would require some new API to be able to modify the config without actually modifying the Settings object. So basically modifying the ClientConfig rather than Settings. We'd need to make sure then that the changes are also applied when original settings are reloaded. I guess I will try to come up with some solution for that. |
Instead of mutating the actual sublime settings, modify the client configuration from "can_start". Fixes sublimelsp/LSP#1907 (comment)
Instead of mutating the actual sublime settings, modify the client configuration from "can_start". Fixes sublimelsp/LSP#1907 (comment)
The PR probably fixed on the lsp_utils side, If I have a LSP-json.sublime-settings file:
when I run the disable language server command and select LSP-json. I expect the LSP-json.sublime-settings to be:
but this gets "languages" key gets inserted as well. (and note that the
EDIT: found the responsible code :) @classmethod
def on_settings_read_internal(cls, settings: sublime.Settings) -> None:
languages = settings.get('languages', None) # type: Optional[List[LanguagesDict]]
if languages:
settings.set('languages', cls._upgrade_languages_list(languages)) # here it is :) |
I believe that PC still has the issue where it doesn't update dependencies regularly. Even when the fix is merged to lsp_utils, Or wait a month before we merge this, just to make sure that users do not run into this issue |
I think that the time makes no difference here. I haven't verified but I believe the dependencies are only updated when the package that uses given dependency gets updated. |
Anything stopping this PR from being merged? I just ran into this issue and saw that here is already a PR to fix it. The solution looks good to me and it worked without any problems on my side. The release for lsp_utils with the corresponding fix was already two months ago. |
Looks good to me. |
This should fix
LSP: Enable / Disable Language Server Globally
for LSP-* plugins.Previously we suggeted users to disable
LSP-*
withPackage Control: Disable package
.The downside of that is that we clean up the
Package Storage
folder.And when we run
Package Control: Enable package
, we have to download the servers bins from the internet again.Which is ok, unless the user do not have access to the internet at the moment he ran
Package Control: Enable package
, then we wont be able to download what is necessary.But if we use
LSP: Enable / Disable Language Server Globally
,we will just switch the
enabled
bool setting,which wont delete anything inside the
Package Storage
folder.The only thing is that my fix doesn't work, because of this import error:
related issue -> #1880