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: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Jun 17, 2024
1 parent 210572c commit ba2831e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 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 LspPyrightPlugin(NpmClientHandler):
server_directory = "language-server"
server_binary_path = os.path.join(server_directory, "node_modules", "pyright", "langserver.index.js")

server_package_json_path = os.path.join(server_directory, "node_modules", "pyright", "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 @@ -74,6 +80,7 @@ def on_pre_start(
) -> str | None:
super().on_pre_start(window, initiating_view, workspace_folders, configuration)

cls.server_version = cls.parse_server_version()
cls.update_venv_info(configuration.settings, workspace_folders, window=window)
if venv_info := cls.window_attrs[window.id()].venv_info:
log_info(f"Using python executable: {venv_info.python_executable}")
Expand Down Expand Up @@ -127,7 +134,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 +214,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 ba2831e

Please sign in to comment.