Skip to content

Commit

Permalink
feat: extract server version from package.json
Browse files Browse the repository at this point in the history
Signed-off-by: Jun-Fei Cherng <[email protected]>
  • Loading branch information
jfcherng committed Jun 17, 2024
1 parent adb1a23 commit ed04fcd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion plugin/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
import os
import re
import shutil
Expand Down Expand Up @@ -38,6 +39,11 @@ class LspBasedpyrightPlugin(NpmClientHandler):
server_directory = "language-server"
server_binary_path = os.path.join(server_directory, "node_modules", "basedpyright", "langserver.index.js")

server_package_json_path = os.path.join(server_directory, "node_modules", "basedpyright", "package.json")
"""The path to the `package.json` file of the language server."""
server_version = ""
"""The version of the language server."""

window_attrs: defaultdict[int, WindowAttr] = defaultdict(WindowAttr)
"""Per-window attributes. I.e., per-session attributes. The key is the window ID."""

Expand Down Expand Up @@ -127,7 +133,7 @@ def update_status_bar_text(self) -> None:
window_id = session.window.id()

variables: dict[str, Any] = {
"server_version": "", # no way to get it?
"server_version": self.server_version,
"venv": {},
}

Expand Down Expand Up @@ -207,6 +213,13 @@ def find_package_dependency_dirs(self, py_ver: tuple[int, int] = (3, 3)) -> list

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

@classmethod
def parse_server_version(cls) -> str:
if server_dir := cls._server_directory_path():
with open(Path(server_dir) / cls.server_package_json_path, "rb") as f:
return json.load(f).get("version", "")
return ""

@classmethod
def update_venv_info(
cls,
Expand Down

0 comments on commit ed04fcd

Please sign in to comment.