Skip to content

Added pyls.extraSysPath. Fixes #381 #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------

Expand Down
2 changes: 1 addition & 1 deletion pyls/python_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
8 changes: 6 additions & 2 deletions pyls/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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', []))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extend? Or prepend? I wonder if an explicit config override should be put at the front of the sys path

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,
)

Expand Down
4 changes: 3 additions & 1 deletion test/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions vscode-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down