-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
67 lines (50 loc) · 1.61 KB
/
server.py
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
import os
from functools import lru_cache
import sublime
from LSP.plugin.core.typing import Optional
from .const import (
ARCH,
PLATFORM,
PLATFORM_ARCH_TO_TARBALL,
PLUGIN_NAME,
SERVER_VERSION,
SETTINGS_FILENAME,
)
@lru_cache()
def get_plugin_storage_dir() -> str:
"""Gets this plugin's storage dir."""
return os.path.abspath(
os.path.join(sublime.cache_path(), "..", "Package Storage", PLUGIN_NAME)
)
@lru_cache()
def get_server_download_url(version: str, platform: str, arch: str) -> Optional[str]:
"""
Gets the LSP server download URL.
:param version: The LSP server version
:param platform: The platform ("osx", "linux" or "windows")
:param arch: The arch ("x32", "x64" or "arm64")
"""
settings = sublime.load_settings(SETTINGS_FILENAME)
url = settings.get("lsp_server_download_url", "") # type: str
tarball = PLATFORM_ARCH_TO_TARBALL.get("{}_{}".format(platform, arch), "")
if not (url and tarball):
return None
return url.format_map(
{
"version": version,
"version_without_v": version.lstrip("v"),
"tarball": tarball,
}
)
@lru_cache()
def get_server_dir() -> str:
"""Gets the server directory."""
server_dir = "{}-{}~{}".format(PLATFORM, ARCH, SERVER_VERSION)
return os.path.join(get_plugin_storage_dir(), server_dir)
@lru_cache()
def get_default_server_bin_path() -> str:
"""Gets the default LSP server binary path."""
return os.path.join(
get_server_dir(),
"texlab.exe" if PLATFORM == "windows" else "texlab",
)