Skip to content

Commit 0e6b193

Browse files
committed
feat: extract server version from package.json
Signed-off-by: Jun-Fei Cherng <jfcherng@realtek.com> Signed-off-by: Jack Cherng <jfcherng@gmail.com>
1 parent adb1a23 commit 0e6b193

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

plugin/client.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import json
34
import os
45
import re
56
import shutil
@@ -38,6 +39,11 @@ class LspBasedpyrightPlugin(NpmClientHandler):
3839
server_directory = "language-server"
3940
server_binary_path = os.path.join(server_directory, "node_modules", "basedpyright", "langserver.index.js")
4041

42+
server_package_json_path = os.path.join("node_modules", "basedpyright", "package.json")
43+
"""The path to the `package.json` file of the language server."""
44+
server_version = ""
45+
"""The version of the language server."""
46+
4147
window_attrs: defaultdict[int, WindowAttr] = defaultdict(WindowAttr)
4248
"""Per-window attributes. I.e., per-session attributes. The key is the window ID."""
4349

@@ -74,6 +80,7 @@ def on_pre_start(
7480
) -> str | None:
7581
super().on_pre_start(window, initiating_view, workspace_folders, configuration)
7682

83+
cls.server_version = cls.parse_server_version()
7784
cls.update_venv_info(configuration.settings, workspace_folders, window=window)
7885
if venv_info := cls.window_attrs[window.id()].venv_info:
7986
log_info(f"Using python executable: {venv_info.python_executable}")
@@ -127,7 +134,7 @@ def update_status_bar_text(self) -> None:
127134
window_id = session.window.id()
128135

129136
variables: dict[str, Any] = {
130-
"server_version": "", # no way to get it?
137+
"server_version": self.server_version,
131138
"venv": {},
132139
}
133140

@@ -207,6 +214,13 @@ def find_package_dependency_dirs(self, py_ver: tuple[int, int] = (3, 3)) -> list
207214

208215
return list(filter(os.path.isdir, dep_dirs))
209216

217+
@classmethod
218+
def parse_server_version(cls) -> str:
219+
if server_dir := cls._server_directory_path():
220+
with open(Path(server_dir) / cls.server_package_json_path, "rb") as f:
221+
return json.load(f).get("version", "")
222+
return ""
223+
210224
@classmethod
211225
def update_venv_info(
212226
cls,

0 commit comments

Comments
 (0)