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 7cd5c8c
Show file tree
Hide file tree
Showing 3 changed files with 22 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 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",
Expand Down
26 changes: 15 additions & 11 deletions plugin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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": "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.",
Expand Down

0 comments on commit 7cd5c8c

Please sign in to comment.