Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the storage_path #1372

Merged
merged 4 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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('~')
Expand All @@ -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'.
rwols marked this conversation as resolved.
Show resolved Hide resolved
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())
rwols marked this conversation as resolved.
Show resolved Hide resolved
```
"""
return get_storage_path()

@classmethod
def needs_update_or_installation(cls) -> bool:
"""
Expand Down
9 changes: 9 additions & 0 deletions plugin/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
rchl marked this conversation as resolved.
Show resolved Hide resolved


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('~')
Expand Down