Skip to content

Commit 91ff0b3

Browse files
authored
Implement storage path as global constant (#2614)
This commit implements a global constant ST_STORAGE_PATH instead of evaluating the rather prominent path constant each time it is required.
1 parent b9102b8 commit 91ff0b3

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

plugin/core/constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .protocol import DocumentHighlightKind
66
from .protocol import SymbolKind
77
from .typing import StrEnum
8+
from os.path import dirname, join
89
from typing import Tuple
910
import sublime
1011

@@ -17,6 +18,16 @@
1718
ST_PACKAGES_PATH = sublime.packages_path()
1819
ST_PLATFORM = sublime.platform()
1920
ST_VERSION = int(sublime.version())
21+
ST_STORAGE_PATH = join(dirname(ST_CACHE_PATH), "Package Storage")
22+
"""
23+
The "Package Storage" is a way to store server data without influencing the
24+
behavior of Sublime Text's "catalog". Its path is '$DATA/Package Storage',
25+
where $DATA means:
26+
27+
- on macOS: ~/Library/Application Support/Sublime Text
28+
- on Windows: %LocalAppData%/Sublime Text
29+
- on Linux: ~/.cache/sublime-text
30+
"""
2031

2132

2233
class RegionKey(StrEnum):

plugin/core/sessions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22
from .collections import DottedDict
33
from .constants import SEMANTIC_TOKENS_MAP
4+
from .constants import ST_STORAGE_PATH
45
from .diagnostics_storage import DiagnosticsStorage
56
from .edit import apply_text_edits
67
from .edit import parse_workspace_edit
@@ -104,7 +105,6 @@
104105
from .url import unparse_uri
105106
from .version import __version__
106107
from .views import extract_variables
107-
from .views import get_storage_path
108108
from .views import get_uri_and_range_from_location
109109
from .views import MarkdownLangMap
110110
from .workspace import is_subpath_of
@@ -892,7 +892,7 @@ def basedir(cls) -> str:
892892
return os.path.join(cls.storage_path(), cls.name())
893893
```
894894
"""
895-
return get_storage_path()
895+
return ST_STORAGE_PATH
896896

897897
@classmethod
898898
def needs_update_or_installation(cls) -> bool:

plugin/core/views.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22
from .constants import CODE_ACTION_KINDS
33
from .constants import ST_CACHE_PATH
4+
from .constants import ST_STORAGE_PATH
45
from .constants import SUBLIME_KIND_SCOPES
56
from .constants import SublimeKind
67
from .css import css as lsp_css
@@ -107,21 +108,9 @@ def get_line(window: sublime.Window, file_name: str, row: int, strip: bool = Tru
107108
return line.strip() if strip else line
108109

109110

110-
def get_storage_path() -> str:
111-
"""
112-
The "Package Storage" is a way to store server data without influencing the behavior of Sublime Text's "catalog".
113-
Its path is '$DATA/Package Storage', where $DATA means:
114-
115-
- on macOS: ~/Library/Application Support/Sublime Text
116-
- on Windows: %LocalAppData%/Sublime Text
117-
- on Linux: ~/.cache/sublime-text
118-
"""
119-
return os.path.abspath(os.path.join(ST_CACHE_PATH, "..", "Package Storage"))
120-
121-
122111
def extract_variables(window: sublime.Window) -> dict[str, str]:
123112
variables = window.extract_variables()
124-
variables["storage_path"] = get_storage_path()
113+
variables["storage_path"] = ST_STORAGE_PATH
125114
variables["cache_path"] = ST_CACHE_PATH
126115
variables["temp_dir"] = tempfile.gettempdir()
127116
variables["home"] = os.path.expanduser('~')

0 commit comments

Comments
 (0)