Skip to content

Commit

Permalink
refactor: the way to get server version
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Jul 19, 2024
1 parent a57ec07 commit ca4b50f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"*": {
"*": [
"Jinja2",
"jmespath",
"lsp_utils",
"markupsafe",
"more-itertools",
Expand Down
16 changes: 9 additions & 7 deletions plugin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pathlib import Path
from typing import Any, cast

import jmespath
import sublime
from LSP.plugin import ClientConfig, DottedDict, MarkdownLangMap, Response, WorkspaceFolder
from LSP.plugin.core.protocol import CompletionItem, Hover, SignatureHelp
Expand Down Expand Up @@ -40,8 +41,6 @@ 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("node_modules", "pyright", "package.json")
"""The path to the `package.json` file of the language server."""
server_version = ""
"""The version of the language server."""

Expand All @@ -65,6 +64,12 @@ def should_ignore(cls, view: sublime.View) -> bool:
or view.substr(sublime.Region(0, 20)).startswith("# SYNTAX TEST ")
)

@classmethod
def setup(cls) -> None:
super().setup()

cls.server_version = cls.parse_server_version()

@classmethod
def can_start(
cls,
Expand Down Expand Up @@ -104,7 +109,6 @@ 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].venv_info:
log_info(f"Using python executable: {venv_info.python_executable}")
Expand Down Expand Up @@ -251,10 +255,8 @@ def find_package_dependency_dirs(self, py_ver: tuple[int, int] = (3, 3)) -> list

@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 ""
lock_file_content = sublime.load_resource(f"Packages/{PACKAGE_NAME}/language-server/package-lock.json")
return jmespath.search("dependencies.pyright.version", json.loads(lock_file_content)) or ""

@classmethod
def update_venv_info(
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

mypy
ruff>=0.5

types-jmespath
8 changes: 6 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
# uv pip compile requirements-dev.in -o requirements-dev.txt
jinja2==3.1.4
# via -r requirements.in
jmespath==1.0.1
# via -r requirements.in
markupsafe==2.1.5
# via jinja2
more-itertools==10.3.0
# via -r requirements.in
mypy==1.10.1
mypy==1.11.0
# via -r requirements-dev.in
mypy-extensions==1.0.0
# via mypy
ruff==0.5.1
ruff==0.5.3
# via -r requirements-dev.in
types-jmespath==1.0.2.20240106
# via -r requirements-dev.in
typing-extensions==4.12.2
# via
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Jinja2>=3,<4
jmespath>=1,<2
more-itertools>=10,<11
typing-extensions>=4.12
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# uv pip compile requirements.in -o requirements.txt
jinja2==3.1.4
# via -r requirements.in
jmespath==1.0.1
# via -r requirements.in
markupsafe==2.1.5
# via jinja2
more-itertools==10.3.0
Expand Down

0 comments on commit ca4b50f

Please sign in to comment.