-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathplugin.py
More file actions
56 lines (45 loc) · 1.6 KB
/
plugin.py
File metadata and controls
56 lines (45 loc) · 1.6 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
from __future__ import annotations
from LSP.plugin import ClientConfig
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
@final
class RuffLsp(GenericClientHandler):
package_name = str(__package__)
uv_venv_manager: UvVenvManager | None = None
@classmethod
@override
def is_applicable(cls, view: sublime.View, config: ClientConfig) -> bool:
return bool(
super().is_applicable(view, config)
# REPL views (https://github.com/sublimelsp/LSP-pyright/issues/343)
and not view.settings().get("repl")
)
@classmethod
@override
def needs_update_or_installation(cls) -> bool:
if not cls.uv_venv_manager:
cls.uv_venv_manager = UvVenvManager(cls.package_name, '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 Exception('Expected UvVenvManager to be initialized')
cls.uv_venv_manager.install()
@classmethod
@override
def get_additional_variables(cls) -> dict[str, str]:
variables = super().get_additional_variables()
if cls.uv_venv_manager:
variables.update({
'server_path': str(cls.uv_venv_manager.venv_bin_path / 'ruff')
})
return variables
def plugin_loaded() -> None:
RuffLsp.setup()
def plugin_unloaded() -> None:
RuffLsp.cleanup()