Skip to content

Commit 05c7b70

Browse files
committed
Added pyls.extraSysPath. Fixes #381
1 parent d294fe1 commit 05c7b70

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ order to respect flake8 configuration instead.
6666
Overall configuration is computed first from user configuration (in home directory), overridden by configuration
6767
passed in by the language client, and then overriden by configuration discovered in the workspace.
6868

69+
Additional extra python paths can be passed by adding a them as a list in the `pyls.extraSysPath` setting.
70+
6971
Language Server Features
7072
------------------------
7173

pyls/python_ls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ def m_initialize(self, processId=None, rootUri=None, rootPath=None, initializati
147147
if rootUri is None:
148148
rootUri = uris.from_fs_path(rootPath) if rootPath is not None else ''
149149

150-
self.workspace = Workspace(rootUri, self._endpoint)
151150
self.config = config.Config(rootUri, initializationOptions or {})
151+
self.workspace = Workspace(rootUri, self._endpoint, self.config)
152152
self._dispatchers = self._hook('pyls_dispatchers')
153153
self._hook('pyls_initialize')
154154

pyls/workspace.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ class Workspace(object):
2121
M_APPLY_EDIT = 'workspace/applyEdit'
2222
M_SHOW_MESSAGE = 'window/showMessage'
2323

24-
def __init__(self, root_uri, endpoint):
24+
def __init__(self, root_uri, endpoint, config):
2525
self._root_uri = root_uri
2626
self._endpoint = endpoint
27+
self._config = config
2728
self._root_uri_scheme = uris.urlparse(self._root_uri)[0]
2829
self._root_path = uris.to_fs_path(self._root_uri)
2930
self._docs = {}
@@ -93,9 +94,12 @@ def source_roots(self, document_path):
9394

9495
def _create_document(self, doc_uri, source=None, version=None):
9596
path = uris.to_fs_path(doc_uri)
97+
extra_sys_path = self.source_roots(path)
98+
settings = self._config.settings(doc_uri)
99+
extra_sys_path.extend(settings.get('extraSysPath', []))
96100
return Document(
97101
doc_uri, source=source, version=version,
98-
extra_sys_path=self.source_roots(path),
102+
extra_sys_path=extra_sys_path,
99103
rope_project_builder=self._rope_project_builder,
100104
)
101105

test/fixtures.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def pyls(tmpdir):
3838
@pytest.fixture
3939
def workspace(tmpdir):
4040
"""Return a workspace."""
41-
return Workspace(uris.from_fs_path(str(tmpdir)), Mock())
41+
rootUri = uris.from_fs_path(str(tmpdir))
42+
config = Config(rootUri, {})
43+
return Workspace(rootUri, Mock(), config)
4244

4345

4446
@pytest.fixture

vscode-client/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
},
3131
"uniqueItems": true
3232
},
33+
"pyls.extraSysPath": {
34+
"type": "array",
35+
"default": [],
36+
"description": "List of extra paths to use to find packages.",
37+
"items": {
38+
"type": "string"
39+
},
40+
"uniqueItems": true
41+
},
3342
"pyls.plugins.jedi_completion.enabled": {
3443
"type": "boolean",
3544
"default": true,

0 commit comments

Comments
 (0)