Skip to content

Commit 32b1894

Browse files
committed
use sys_path method
1 parent d08af94 commit 32b1894

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pylsp/workspace.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,8 @@ def jedi_script(self, position=None, use_document_path=False):
548548

549549
environment = self.get_enviroment(environment_path, env_vars=env_vars)
550550

551-
sys_path = list(self._extra_sys_path) + environment.get_sys_path()
552-
if prioritize:
553-
sys_path += extra_paths + sys_path
554-
else:
555-
sys_path += sys_path + extra_paths
551+
sys_path = self.sys_path(environment_path, env_vars, prioritize, extra_paths)
552+
556553
project_path = self._workspace.root_path
557554

558555
# Extend sys_path with document's path if requested
@@ -587,14 +584,18 @@ def get_enviroment(self, environment_path=None, env_vars=None):
587584

588585
return environment
589586

590-
def sys_path(self, environment_path=None, env_vars=None):
591-
# TODO: when safe to break API, remove this method.
587+
def sys_path(self, environment_path=None, env_vars=None, prioritize=False, extra_paths=[]):
592588
# Copy our extra sys path
593589
path = list(self._extra_sys_path)
594590
environment = self.get_enviroment(
595591
environment_path=environment_path, env_vars=env_vars
596592
)
597593
path.extend(environment.get_sys_path())
594+
if prioritize:
595+
path += extra_paths + path
596+
else:
597+
path += path + extra_paths
598+
598599
return path
599600

600601

test/test_workspace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_non_root_project(pylsp, metafiles) -> None:
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) -> None:
@@ -79,7 +79,7 @@ def test_root_project_with_no_setup_py(pylsp) -> None:
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) -> None:

0 commit comments

Comments
 (0)