-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.py
More file actions
71 lines (58 loc) · 2.11 KB
/
Copy pathplugin.py
File metadata and controls
71 lines (58 loc) · 2.11 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
from __future__ import annotations
from LSP.plugin import AbstractPlugin
from LSP.plugin import register_plugin
from LSP.plugin import unregister_plugin
from urllib.request import urlretrieve
from zipfile import ZipFile
import os
import shutil
import sublime
VERSION = "v0.45.15"
URL = "https://github.com/Azure/bicep/releases/download/{0}/bicep-langserver.zip"
class Bicep(AbstractPlugin):
@classmethod
def name(cls) -> str:
return cls.__name__
@classmethod
def additional_variables(cls) -> dict[str, str] | None:
filename = "LSP-{}.sublime-settings".format(cls.name())
settings = sublime.load_settings(filename)
dotnet_executable = settings.get("dotnet_executable")
if not dotnet_executable:
dotnet_executable = "dotnet"
return {"dotnet_executable": dotnet_executable}
@classmethod
def installed_version_str(cls) -> str:
filename = os.path.join(cls.basedir(), "VERSION")
with open(filename, "r") as f:
return f.readline().strip()
@classmethod
def basedir(cls) -> str:
return os.path.join(cls.storage_path(), "LSP-{}".format(cls.name()))
@classmethod
def needs_update_or_installation(cls) -> bool:
try:
if VERSION == cls.installed_version_str():
return False
except Exception:
pass
return True
@classmethod
def install_or_update(cls) -> None:
shutil.rmtree(cls.basedir(), ignore_errors=True)
os.makedirs(cls.basedir(), exist_ok=True)
zipfile = os.path.join(cls.basedir(), "biceplangserver.zip")
try:
urlretrieve(URL.format(VERSION), zipfile)
with ZipFile(zipfile, "r") as f:
f.extractall(cls.basedir())
os.unlink(zipfile)
with open(os.path.join(cls.basedir(), "VERSION"), "w") as fp:
fp.write(VERSION)
except Exception:
shutil.rmtree(cls.basedir(), ignore_errors=True)
raise
def plugin_loaded() -> None:
register_plugin(Bicep)
def plugin_unloaded() -> None:
unregister_plugin(Bicep)