From 7cd5c8c54c4b13eaa463e74f6403c55f1386d74d Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Wed, 12 Jun 2024 02:15:24 +0800 Subject: [PATCH] feat: templated status bar text See new settings: statusText Signed-off-by: Jack Cherng --- LSP-pyright.sublime-settings | 2 ++ plugin/client.py | 26 +++++++++++++++----------- sublime-package.json | 5 +++++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/LSP-pyright.sublime-settings b/LSP-pyright.sublime-settings index 7a2c09b..45c2d04 100644 --- a/LSP-pyright.sublime-settings +++ b/LSP-pyright.sublime-settings @@ -8,6 +8,8 @@ // @see https://github.com/microsoft/pyright/blob/main/docs/settings.md // @see https://github.com/microsoft/pyright/blob/main/packages/vscode-pyright/package.json "settings": { + // The template of the status bar text which is inside the parentheses `(...)`. + "statusText": "venv: ${venv_prompt}; py: ${python_version}; by: ${by_venv_strategy}", // The strategies used to find a virtual environment in order. "venvStrategies": [ "local_dot_venv", diff --git a/plugin/client.py b/plugin/client.py index c04ea77..2a2dad0 100644 --- a/plugin/client.py +++ b/plugin/client.py @@ -121,22 +121,26 @@ def on_server_response_async(self, method: str, response: Response) -> None: # -------------- # def update_status_bar_text(self) -> None: - status_parts: list[str] = [] - if not (session := self.weaksession()): return window_id = session.window.id() - # @todo make this into a configurable template + if not (template := str(session.config.settings.get("statusText") or "")): + return + + variables = { + "by_venv_strategy": "", + "python_version": "", + "server_version": "", # no way to get it? + "venv_prompt": "", + } + if venv_info := self.window_attrs[window_id].venv_info: - if venv_info.prompt: - status_parts.append(f"venv: {venv_info.prompt}") - if venv_info.python_version: - status_parts.append(f"py: {venv_info.python_version}") - if venv_info.meta.finder_name: - status_parts.append(f"by: {venv_info.meta.finder_name}") - - session.set_config_status_async("; ".join(status_parts)) + variables["by_venv_strategy"] = venv_info.meta.finder_name + variables["python_version"] = venv_info.python_version + variables["venv_prompt"] = venv_info.prompt + + session.set_config_status_async(sublime.expand_variables(template, variables)) def patch_markdown_content(self, content: str) -> str: # add another linebreak before horizontal rule following fenced code block diff --git a/sublime-package.json b/sublime-package.json index 55bc2f7..8497ab0 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -21,6 +21,11 @@ "settings": { "additionalProperties": false, "properties": { + "statusText": { + "default": "venv: ${venv_prompt}; py: ${python_version}; by: ${by_venv_strategy}", + "markdownDescription": "The template of the status bar text which is inside the parentheses `(...)`.", + "type": "string" + }, "venvStrategies": { "default": [], "description": "The strategies used to find a virtual environment in order.",