Skip to content

Commit

Permalink
feat: templated status bar text
Browse files Browse the repository at this point in the history
See new settings: statusText

Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Jun 11, 2024
1 parent f97ce75 commit 2823ab5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
2 changes: 2 additions & 0 deletions LSP-pyright.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"*": {
"*": [
"Jinja2",
"lsp_utils",
"markupsafe",
"more-itertools",
"sublime_lib",
"typing-extensions"
Expand Down
26 changes: 15 additions & 11 deletions plugin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Jinja2>=3,<4
more-itertools>=10,<11
typing-extensions>=4.12
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions sublime-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 2823ab5

Please sign in to comment.