From 5f13b767dea8a6c4b308d49674220169d3cc0a15 Mon Sep 17 00:00:00 2001 From: Tobias Krabel Date: Fri, 13 Oct 2023 22:13:55 +0200 Subject: [PATCH 1/3] Load rope_autoimport cache on workspace/didChangeConfiguration --- pylsp/hookspecs.py | 5 +++++ pylsp/plugins/rope_autoimport.py | 10 ++++++++++ pylsp/python_lsp.py | 1 + 3 files changed, 16 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..b319f9d7 100644 --- a/pylsp/plugins/rope_autoimport.py +++ b/pylsp/plugins/rope_autoimport.py @@ -238,3 +238,13 @@ 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) From aa74b81cf018b5f6804a657fd293cfccb358786a Mon Sep 17 00:00:00 2001 From: Tobias Krabel Date: Fri, 13 Oct 2023 22:33:05 +0200 Subject: [PATCH 2/3] break line --- pylsp/plugins/rope_autoimport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pylsp/plugins/rope_autoimport.py b/pylsp/plugins/rope_autoimport.py index b319f9d7..f9a15d97 100644 --- a/pylsp/plugins/rope_autoimport.py +++ b/pylsp/plugins/rope_autoimport.py @@ -242,7 +242,8 @@ def pylsp_document_did_save(config: Config, workspace: Workspace, document: Docu @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. + """Initialize AutoImport if it has been enabled through a + workspace/didChangeConfiguration message from the frontend. Generates the cache for local and global items. """ From 931a2115b02253c599b752de930c19d7b28f5fb9 Mon Sep 17 00:00:00 2001 From: tkrabel-db <91616041+tkrabel-db@users.noreply.github.com> Date: Fri, 13 Oct 2023 22:46:03 +0200 Subject: [PATCH 3/3] Update pylsp/plugins/rope_autoimport.py Co-authored-by: Carlos Cordoba --- pylsp/plugins/rope_autoimport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pylsp/plugins/rope_autoimport.py b/pylsp/plugins/rope_autoimport.py index f9a15d97..c13907a4 100644 --- a/pylsp/plugins/rope_autoimport.py +++ b/pylsp/plugins/rope_autoimport.py @@ -242,7 +242,8 @@ def pylsp_document_did_save(config: Config, workspace: Workspace, document: Docu @hookimpl def pylsp_workspace_configuration_chaged(config: Config, workspace: Workspace): - """Initialize AutoImport if it has been enabled through a + """ + Initialize autoimport if it has been enabled through a workspace/didChangeConfiguration message from the frontend. Generates the cache for local and global items.