-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.py
More file actions
85 lines (69 loc) · 2.43 KB
/
client.py
File metadata and controls
85 lines (69 loc) · 2.43 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from __future__ import annotations
from .constants import PACKAGE_NAME
from .log import log_warning
from .template import load_string_template
from .version_manager import version_manager
from LSP.plugin import AbstractPlugin
from LSP.plugin import ClientConfig
from LSP.plugin import DottedDict
from typing import Any
from typing_extensions import override
import sublime
class LspTyPlugin(AbstractPlugin):
@override
@classmethod
def name(cls) -> str:
return PACKAGE_NAME
@override
@classmethod
def configuration(cls) -> tuple[sublime.Settings, str]:
basename = f"{cls.name()}.sublime-settings"
filepath = f"Packages/{cls.name()}/{basename}"
return sublime.load_settings(basename), filepath
@override
@classmethod
def additional_variables(cls) -> dict[str, str] | None:
return {
"server_path": str(version_manager.server_path),
}
@override
@classmethod
def needs_update_or_installation(cls) -> bool:
return not version_manager.is_installed
@override
@classmethod
def install_or_update(cls) -> None:
version_manager.install_server()
@override
@classmethod
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")
)
# ----- #
# hooks #
# ----- #
@override
def on_settings_changed(self, settings: DottedDict) -> None:
super().on_settings_changed(settings)
self.update_status_bar_text()
# -------------- #
# custom methods #
# -------------- #
def update_status_bar_text(self, extra_variables: dict[str, Any] | None = None) -> None:
if not (session := self.weaksession()):
return
variables: dict[str, Any] = {
"server_version": version_manager.server_version,
}
if extra_variables:
variables.update(extra_variables)
rendered_text = ""
if template_text := str(session.config.settings.get("statusText") or ""):
try:
rendered_text = load_string_template(template_text).render(variables)
except Exception as e:
log_warning(f'Invalid "statusText" template: {e}')
session.set_config_status_async(rendered_text)