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

Load rope_autoimport cache on workspace/didChangeConfiguration #461

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pylsp/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ def pylsp_settings(config):
@hookspec(firstresult=True)
def pylsp_signature_help(config, workspace, document, position):
pass


@hookspec
def pylsp_workspace_configuration_changed(config, workspace):
pass
12 changes: 12 additions & 0 deletions pylsp/plugins/rope_autoimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,15 @@ def pylsp_document_did_open(config: Config, workspace: Workspace):
def pylsp_document_did_save(config: Config, workspace: Workspace, document: Document):
"""Update the names associated with this document."""
_reload_cache(config, workspace, [document])


@hookimpl
def pylsp_workspace_configuration_chaged(config: Config, workspace: Workspace):
"""
Initialize autoimport if it has been enabled through a
workspace/didChangeConfiguration message from the frontend.
Generates the cache for local and global items.
"""
if config.plugin_settings("rope_autoimport").get("enabled", False):
_reload_cache(config, workspace)
Comment on lines +245 to +252
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could keep the last enabled state and only reload cache on setting actually changing. Otherwise it can trigger wasteful reloads on any other setting changing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good very idea, thanks @rchl!

@tkrabel-db, what do you think? We could use a global variable to track the plugin's enabled state and only reload the cache when changing from ENABLED = False to True.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do that!

1 change: 1 addition & 0 deletions pylsp/python_lsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ def m_workspace__did_change_configuration(self, settings=None):
self.config.update((settings or {}).get("pylsp", {}))
for workspace in self.workspaces.values():
workspace.update_config(settings)
self._hook("pylsp_workspace_configuration_changed")
for doc_uri in workspace.documents:
self.lint(doc_uri, is_saved=False)

Expand Down
Loading