From 186f113ce030f4a453f9f33c74e8ab1db1365e0c Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Sun, 11 Oct 2020 16:54:29 +0200 Subject: [PATCH 1/3] Introduce the storage_path --- plugin/core/sessions.py | 27 +++++++++++++++++++++++++++ plugin/core/views.py | 9 +++++++++ 2 files changed, 36 insertions(+) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index 1bc2cdbc6..1d4f37df3 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -26,6 +26,7 @@ from .views import COMPLETION_KINDS from .views import did_change_configuration from .views import extract_variables +from .views import get_storage_path from .views import SYMBOL_KINDS from .workspace import is_subpath_of from abc import ABCMeta @@ -362,6 +363,7 @@ def configuration(cls) -> Tuple[sublime.Settings, str]: These are just the values from window.extract_variables(). Additionally, + $storage_path The path to the package storage (see AbstractPlugin.storage_path) $cache_path sublime.cache_path() $temp_dir tempfile.gettempdir() $home os.path.expanduser('~') @@ -386,6 +388,31 @@ def additional_variables(cls) -> Optional[Dict[str, str]]: """ return None + @classmethod + def storage_path(cls) -> str: + """ + The storage path. Use this as your base directory to install server files. Its path is '$DATA/Package Storage'. + You should have an additional subdirectory preferrably the same name as your plugin. For instance: + + ```python + from LSP.plugin import AbstractPlugin + import os + + + class MyPlugin(AbstractPlugin): + + @classmethod + def name(cls) -> str: + return "my-plugin" + + @classmethod + def basedir(cls) -> str: + # Do everything relative to this directory + return os.path.joim(cls.storage_path(), cls.name()) + ``` + """ + return get_storage_path() + @classmethod def needs_update_or_installation(cls) -> bool: """ diff --git a/plugin/core/views.py b/plugin/core/views.py index 661cb9813..95c10f6fd 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -108,8 +108,17 @@ def get_line(window: Optional[sublime.Window], file_name: str, row: int) -> str: return linecache.getline(file_name, row + 1).strip() +def get_storage_path() -> str: + """ + The "Package Storage" is a way to store server data without influencing the behavior of Sublime Text's "catalog". + Its path is '$DATA/Package Storage'. + """ + return os.path.abspath(os.path.join(sublime.cache_path(), "..", "Package Storage")) + + def extract_variables(window: sublime.Window) -> Dict[str, str]: variables = window.extract_variables() + variables["storage_path"] = get_storage_path() variables["cache_path"] = sublime.cache_path() variables["temp_dir"] = tempfile.gettempdir() variables["home"] = os.path.expanduser('~') From a864ea6ee4f99c67c418551ae64e9e55377bf4c5 Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Fri, 16 Oct 2020 20:20:46 +0200 Subject: [PATCH 2/3] Clarify what we mean by $DATA --- plugin/core/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin/core/views.py b/plugin/core/views.py index 95c10f6fd..af1a4400f 100644 --- a/plugin/core/views.py +++ b/plugin/core/views.py @@ -111,7 +111,11 @@ def get_line(window: Optional[sublime.Window], file_name: str, row: int) -> str: def get_storage_path() -> str: """ The "Package Storage" is a way to store server data without influencing the behavior of Sublime Text's "catalog". - Its path is '$DATA/Package Storage'. + Its path is '$DATA/Package Storage', where $DATA means: + + - on macOS: ~/Library/Application Support/Sublime Text + - on Windows: %AppData%/Sublime Text/Roaming + - on Linux: $XDG_CONFIG_DIR/sublime-text """ return os.path.abspath(os.path.join(sublime.cache_path(), "..", "Package Storage")) From 52e2d6b9368cf7bbb4c597b5c2091a83df40ffda Mon Sep 17 00:00:00 2001 From: Raoul Wols Date: Fri, 16 Oct 2020 20:21:05 +0200 Subject: [PATCH 3/3] Fix typo --- plugin/core/sessions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index 631608004..30982bd4d 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -408,7 +408,7 @@ def name(cls) -> str: @classmethod def basedir(cls) -> str: # Do everything relative to this directory - return os.path.joim(cls.storage_path(), cls.name()) + return os.path.join(cls.storage_path(), cls.name()) ``` """ return get_storage_path()