-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplugin.py
More file actions
63 lines (49 loc) · 1.81 KB
/
plugin.py
File metadata and controls
63 lines (49 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from __future__ import annotations
from lsp_utils import GenericClientHandler
from lsp_utils import UvVenvManager
from pathlib import Path
from typing import final
from typing_extensions import override
import sublime
class UvManagerNotInitializedError(Exception):
def __init__(self) -> None:
super().__init__('Expected UvVenvManager to be initialized')
@final
class Pylsp(GenericClientHandler):
package_name = str(__package__)
uv_venv_manager: UvVenvManager | None = None
# --- GenericClientHandler handlers --------------------------------------------------------------------------------
@classmethod
@override
def needs_update_or_installation(cls) -> bool:
if not cls.uv_venv_manager:
cls.uv_venv_manager = UvVenvManager(cls.package_name, 'server/pyproject.toml', Path(cls.storage_path()))
return cls.uv_venv_manager.needs_install_or_update()
@classmethod
@override
def install_or_update(cls) -> None:
if not cls.uv_venv_manager:
raise UvManagerNotInitializedError
cls.uv_venv_manager.install()
@classmethod
@override
def get_additional_variables(cls) -> dict[str, str]:
variables = super().get_additional_variables()
variables.update({
'sublime_py_files_dir': str(Path(sublime.__file__).parent),
})
if cls.uv_venv_manager:
variables.update({
'server_path': str(cls.uv_venv_manager.venv_bin_path / 'pylsp'),
})
return variables
@classmethod
@override
def get_additional_paths(cls) -> list[str]:
if uv_venv_manager := cls.uv_venv_manager:
return [str(uv_venv_manager.venv_bin_path)]
return []
def plugin_loaded() -> None:
Pylsp.setup()
def plugin_unloaded() -> None:
Pylsp.cleanup()