From 60ba623b069812e5d337270707a30180ec747cc2 Mon Sep 17 00:00:00 2001 From: tkrabel-db <91616041+tkrabel-db@users.noreply.github.com> Date: Sat, 14 Oct 2023 00:25:06 +0200 Subject: [PATCH] Load `rope_autoimport` cache on `workspace/didChangeConfiguration` (#461) --- pylsp/hookspecs.py | 5 +++++ pylsp/plugins/rope_autoimport.py | 12 ++++++++++++ pylsp/python_lsp.py | 1 + 3 files changed, 18 insertions(+) diff --git a/pylsp/hookspecs.py b/pylsp/hookspecs.py index d1a2458e..d732b1d0 100644 --- a/pylsp/hookspecs.py +++ b/pylsp/hookspecs.py @@ -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 diff --git a/pylsp/plugins/rope_autoimport.py b/pylsp/plugins/rope_autoimport.py index be40fe41..c13907a4 100644 --- a/pylsp/plugins/rope_autoimport.py +++ b/pylsp/plugins/rope_autoimport.py @@ -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) diff --git a/pylsp/python_lsp.py b/pylsp/python_lsp.py index e2b541d5..4c3ea0d2 100644 --- a/pylsp/python_lsp.py +++ b/pylsp/python_lsp.py @@ -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)