Skip to content

Commit

Permalink
fix: only support py33 plugin dev env for ST 3 plugins
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 68cb53b commit 25622c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 41 deletions.
8 changes: 2 additions & 6 deletions LSP-pyright.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
"settings": {
// Use a predefined setup from this plugin, valid values are:
// - "": An empty string does nothing.
// - "sublime_text": Suitable for people who are developing ST Python plugins.
// The Python version which the developed plugin runs on will be used.
// `sys.path` from plugin_host will be added into "python.analysis.extraPaths"
// so ST package dependecies can be resolved by the LSP server.
// - "sublime_text_33": Similar to "sublime_text" but Python 3.3 forced.
// - "sublime_text_38": Similar to "sublime_text" but Python 3.8 forced.
// - "sublime_text": Suitable for people who are developing ST python 3.3 plugins. `sys.path` from the plugin_host will be added into "python.analysis.extraPaths" so that ST package dependencies can be resolved by the LSP server.
// - "sublime_text_33": The same with using "sublime_text".
"pyright.dev_environment": "",
// Offer auto-import completions.
"python.analysis.autoImportCompletions": true,
Expand Down
32 changes: 2 additions & 30 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def on_settings_changed(self, settings: DottedDict) -> None:
dev_environment = settings.get("pyright.dev_environment")
extraPaths = settings.get("python.analysis.extraPaths") or [] # type: List[str]

if dev_environment in {"sublime_text", "sublime_text_33", "sublime_text_38"}:
py_ver = self.detect_st_py_ver(dev_environment)
if dev_environment in {"sublime_text", "sublime_text_33"}:
py_ver = (3, 3) # there is only py33 on ST 3
# add package dependencies into "python.analysis.extraPaths"
extraPaths.extend(self.find_package_dependency_dirs(py_ver))

Expand Down Expand Up @@ -129,34 +129,6 @@ def patch_markdown_content(self, content: str) -> str:
content = re.sub(r"\n:deprecated:", r"\n⚠️ __Deprecated:__", content)
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":
return (3, 3)
if dev_environment == "sublime_text_38":
return (3, 8)

if dev_environment == "sublime_text":
session = self.weaksession()
if not session:
return default
workspace_folders = session.get_workspace_folders()
if not workspace_folders:
return default
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:
with open(python_version_file, "r") as file:
if file.read().strip() == "3.8":
return (3, 8)
except Exception:
pass

return default

@classmethod
def get_plugin_setting(cls, key: str, default: Any = None) -> Any:
return sublime.load_settings(cls.package_name + ".sublime-settings").get(key, default)
Expand Down
8 changes: 3 additions & 5 deletions sublime-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
"enum": [
"",
"sublime_text",
"sublime_text_33",
"sublime_text_38"
"sublime_text_33"
],
"markdownEnumDescriptions": [
"No modifications applied.",
"Suitable for people who are developing ST python plugins. The Python version which the developed plugin runs on will be used. - `sys.path` from the plugin_host will be added into \"python.analysis.extraPaths\" so that ST package dependencies can be resolved by the LSP server.",
"Similar to \"sublime_text\" but Python 3.3 forced.",
"Similar to \"sublime_text\" but Python 3.8 forced."
"Suitable for people who are developing ST python plugins. `sys.path` from the plugin_host will be added into \"python.analysis.extraPaths\" so that ST package dependencies can be resolved by the LSP server.",
"The same with using \"sublime_text\".",
]
},
// pyright
Expand Down

0 comments on commit 25622c8

Please sign in to comment.