diff --git a/LSP-pyright.sublime-settings b/LSP-pyright.sublime-settings index 7a2c09b..6cf1bb3 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 (Jinja2) template of the status bar text which is inside the parentheses `(...)`. + "statusText": "{% if venv %}venv: {{ venv.venv_prompt }}; py: {{ venv.python_version }}; by: {{ venv.finder_name }}{% endif %}", // The strategies used to find a virtual environment in order. "venvStrategies": [ "local_dot_venv", diff --git a/dependencies.json b/dependencies.json index 9526366..c698a22 100644 --- a/dependencies.json +++ b/dependencies.json @@ -1,7 +1,9 @@ { "*": { "*": [ + "Jinja2", "lsp_utils", + "markupsafe", "more-itertools", "sublime_lib", "typing-extensions" diff --git a/plugin/client.py b/plugin/client.py index c04ea77..c274036 100644 --- a/plugin/client.py +++ b/plugin/client.py @@ -9,6 +9,7 @@ from pathlib import Path from typing import cast +import jinja2 import sublime from LSP.plugin import ClientConfig, DottedDict, MarkdownLangMap, Response, WorkspaceFolder from LSP.plugin.core.protocol import CompletionItem, Hover, SignatureHelp @@ -121,22 +122,25 @@ 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 + variables = { + "server_version": "", # no way to get it? + "venv": {}, + } + 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["venv"].update( # type: ignore + finder_name=venv_info.meta.finder_name, + python_version=venv_info.python_version, + venv_prompt=venv_info.prompt, + ) + + template_text = str(session.config.settings.get("statusText") or "") + template_obj = jinja2.Environment().from_string(template_text) + session.set_config_status_async(template_obj.render(variables)) def patch_markdown_content(self, content: str) -> str: # add another linebreak before horizontal rule following fenced code block diff --git a/requirements-dev.txt b/requirements-dev.txt index 8efdee0..ac252b1 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,9 @@ # This file was autogenerated by uv via the following command: # uv pip compile requirements-dev.in -o requirements-dev.txt +jinja2==3.1.4 + # via -r requirements.in +markupsafe==2.1.5 + # via jinja2 more-itertools==10.3.0 # via -r requirements.in mypy==1.10.0 diff --git a/requirements.in b/requirements.in index e2f0ea2..d7d01b5 100644 --- a/requirements.in +++ b/requirements.in @@ -1,2 +1,3 @@ +Jinja2>=3,<4 more-itertools>=10,<11 typing-extensions>=4.12 diff --git a/requirements.txt b/requirements.txt index d289507..2532fb3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,9 @@ # This file was autogenerated by uv via the following command: # uv pip compile requirements.in -o requirements.txt +jinja2==3.1.4 + # via -r requirements.in +markupsafe==2.1.5 + # via jinja2 more-itertools==10.3.0 # via -r requirements.in typing-extensions==4.12.2 diff --git a/sublime-package.json b/sublime-package.json index 55bc2f7..cb923a3 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -21,6 +21,11 @@ "settings": { "additionalProperties": false, "properties": { + "statusText": { + "default": "{% if venv %}venv: {{ venv.venv_prompt }}; py: {{ venv.python_version }}; by: {{ venv.finder_name }}{% endif %}", + "markdownDescription": "The (Jinja2) 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.",