Skip to content

Commit

Permalink
fix: sublime.packages_path() can't be used before plugin loaded in ST 3
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Dec 3, 2023
1 parent b857bb3 commit d486590
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from sublime_lib import ResourcePath

ST_VERSION = int(sublime.version())
ST_PACKAGES_PATH = sublime.packages_path()

if ST_VERSION >= 4070:
from LSP.plugin import MarkdownLangMap
Expand Down Expand Up @@ -131,6 +130,8 @@ def patch_markdown_content(self, content: str) -> str:
return content

def detect_st_py_ver(self, dev_environment: str) -> Tuple[int, int]:
st_packages_path = sublime.packages_path()

default = (3, 3)

if dev_environment == "sublime_text_33":
Expand All @@ -145,7 +146,7 @@ def detect_st_py_ver(self, dev_environment: str) -> Tuple[int, int]:
workspace_folders = session.get_workspace_folders()
if not workspace_folders:
return default
if workspace_folders[0].path == os.path.join(ST_PACKAGES_PATH, "User"):
if workspace_folders[0].path == os.path.join(st_packages_path, "User"):
return (3, 8)
python_version_file = os.path.join(workspace_folders[0].path, ".python-version")
try:
Expand All @@ -162,6 +163,8 @@ def get_plugin_setting(cls, key: str, default: Any = None) -> Any:
return sublime.load_settings(cls.package_name + ".sublime-settings").get(key, default)

def find_package_dependency_dirs(self, py_ver: Tuple[int, int] = (3, 3)) -> List[str]:
st_packages_path = sublime.packages_path()

dep_dirs = sys.path.copy()

# replace paths for target Python version
Expand All @@ -172,8 +175,8 @@ def find_package_dependency_dirs(self, py_ver: Tuple[int, int] = (3, 3)) -> List

# move the "Packages/" to the last
# @see https://github.com/sublimelsp/LSP-pyright/pull/26#discussion_r520747708
dep_dirs.remove(ST_PACKAGES_PATH)
dep_dirs.append(ST_PACKAGES_PATH)
dep_dirs.remove(st_packages_path)
dep_dirs.append(st_packages_path)

if py_ver == (3, 3):
# sublime stubs - add as first
Expand Down

0 comments on commit d486590

Please sign in to comment.