Skip to content

Commit 12aafe6

Browse files
committed
use sys_path method
1 parent e713972 commit 12aafe6

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Diff for: pylsp/workspace.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -534,11 +534,8 @@ def jedi_script(self, position=None, use_document_path=False):
534534

535535
environment = self.get_enviroment(environment_path, env_vars=env_vars)
536536

537-
sys_path = list(self._extra_sys_path) + environment.get_sys_path()
538-
if prioritize:
539-
sys_path += extra_paths + sys_path
540-
else:
541-
sys_path += sys_path + extra_paths
537+
sys_path = self.sys_path(environment_path, env_vars, prioritize, extra_paths)
538+
542539
project_path = self._workspace.root_path
543540

544541
# Extend sys_path with document's path if requested
@@ -573,14 +570,18 @@ def get_enviroment(self, environment_path=None, env_vars=None):
573570

574571
return environment
575572

576-
def sys_path(self, environment_path=None, env_vars=None):
577-
# TODO: when safe to break API, remove this method.
573+
def sys_path(self, environment_path=None, env_vars=None, prioritize=False, extra_paths=[]):
578574
# Copy our extra sys path
579575
path = list(self._extra_sys_path)
580576
environment = self.get_enviroment(
581577
environment_path=environment_path, env_vars=env_vars
582578
)
583579
path.extend(environment.get_sys_path())
580+
if prioritize:
581+
path += extra_paths + path
582+
else:
583+
path += path + extra_paths
584+
584585
return path
585586

586587

Diff for: test/test_workspace.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_non_root_project(pylsp, metafiles):
7070
test_uri = uris.from_fs_path(os.path.join(project_root, "hello/test.py"))
7171
pylsp.workspace.put_document(test_uri, "assert True")
7272
test_doc = pylsp.workspace.get_document(test_uri)
73-
assert project_root in test_doc.get_enviroment().get_sys_path()
73+
assert project_root in test_doc.sys_path()
7474

7575

7676
def test_root_project_with_no_setup_py(pylsp):
@@ -79,7 +79,7 @@ def test_root_project_with_no_setup_py(pylsp):
7979
test_uri = uris.from_fs_path(os.path.join(workspace_root, "hello/test.py"))
8080
pylsp.workspace.put_document(test_uri, "assert True")
8181
test_doc = pylsp.workspace.get_document(test_uri)
82-
assert workspace_root in test_doc.get_enviroment().get_sys_path()
82+
assert workspace_root in test_doc.sys_path()
8383

8484

8585
def test_multiple_workspaces_from_initialize(pylsp_w_workspace_folders):

0 commit comments

Comments
 (0)