diff --git a/README.rst b/README.rst index 5ffbec4c..84390dce 100644 --- a/README.rst +++ b/README.rst @@ -66,6 +66,8 @@ order to respect flake8 configuration instead. Overall configuration is computed first from user configuration (in home directory), overridden by configuration passed in by the language client, and then overriden by configuration discovered in the workspace. +Additional extra python paths can be passed by adding a them as a list in the `pyls.extraSysPath` setting. + Language Server Features ------------------------ diff --git a/pyls/python_ls.py b/pyls/python_ls.py index c9ff1e85..13fdba82 100644 --- a/pyls/python_ls.py +++ b/pyls/python_ls.py @@ -147,8 +147,8 @@ def m_initialize(self, processId=None, rootUri=None, rootPath=None, initializati if rootUri is None: rootUri = uris.from_fs_path(rootPath) if rootPath is not None else '' - self.workspace = Workspace(rootUri, self._endpoint) self.config = config.Config(rootUri, initializationOptions or {}) + self.workspace = Workspace(rootUri, self._endpoint, self.config) self._dispatchers = self._hook('pyls_dispatchers') self._hook('pyls_initialize') diff --git a/pyls/workspace.py b/pyls/workspace.py index c731f670..0f8b360a 100644 --- a/pyls/workspace.py +++ b/pyls/workspace.py @@ -21,9 +21,10 @@ class Workspace(object): M_APPLY_EDIT = 'workspace/applyEdit' M_SHOW_MESSAGE = 'window/showMessage' - def __init__(self, root_uri, endpoint): + def __init__(self, root_uri, endpoint, config): self._root_uri = root_uri self._endpoint = endpoint + self._config = config self._root_uri_scheme = uris.urlparse(self._root_uri)[0] self._root_path = uris.to_fs_path(self._root_uri) self._docs = {} @@ -93,9 +94,12 @@ def source_roots(self, document_path): def _create_document(self, doc_uri, source=None, version=None): path = uris.to_fs_path(doc_uri) + extra_sys_path = self.source_roots(path) + settings = self._config.settings(doc_uri) + extra_sys_path.extend(settings.get('extraSysPath', [])) return Document( doc_uri, source=source, version=version, - extra_sys_path=self.source_roots(path), + extra_sys_path=extra_sys_path, rope_project_builder=self._rope_project_builder, ) diff --git a/test/fixtures.py b/test/fixtures.py index d4b53d3c..ec0a28a0 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -38,7 +38,9 @@ def pyls(tmpdir): @pytest.fixture def workspace(tmpdir): """Return a workspace.""" - return Workspace(uris.from_fs_path(str(tmpdir)), Mock()) + rootUri = uris.from_fs_path(str(tmpdir)) + config = Config(rootUri, {}) + return Workspace(rootUri, Mock(), config) @pytest.fixture diff --git a/vscode-client/package.json b/vscode-client/package.json index dc00fecf..e512e022 100644 --- a/vscode-client/package.json +++ b/vscode-client/package.json @@ -30,6 +30,15 @@ }, "uniqueItems": true }, + "pyls.extraSysPath": { + "type": "array", + "default": [], + "description": "List of extra paths to use to find packages.", + "items": { + "type": "string" + }, + "uniqueItems": true + }, "pyls.plugins.jedi_completion.enabled": { "type": "boolean", "default": true,