Skip to content

Commit e0f8b3d

Browse files
authored
Add document path to Jedi's sys_path (#879)
1 parent 5c002d4 commit e0f8b3d

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

pyls/workspace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def jedi_script(self, position=None):
258258
env_vars.pop('PYTHONPATH', None)
259259

260260
environment = self.get_enviroment(environment_path, env_vars=env_vars) if environment_path else None
261-
sys_path = self.sys_path(environment_path, env_vars=env_vars) + extra_paths
261+
sys_path = self.sys_path(environment_path, env_vars=env_vars) + extra_paths + [os.path.dirname(self.path)]
262262
project_path = self._workspace.root_path
263263

264264
kwargs = {

test/fixtures.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ def workspace(tmpdir):
4444
return ws
4545

4646

47+
@pytest.fixture
48+
def workspace_other_root_path(tmpdir):
49+
"""Return a workspace with a root_path other than tmpdir."""
50+
ws_path = str(tmpdir.mkdir('test123').mkdir('test456'))
51+
ws = Workspace(uris.from_fs_path(ws_path), Mock())
52+
ws._config = Config(ws.root_uri, {}, 0, {})
53+
return ws
54+
55+
4756
@pytest.fixture
4857
def config(workspace): # pylint: disable=redefined-outer-name
4958
"""Return a config object."""

test/plugins/test_completion.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,26 @@ def test_jedi_completion_environment(workspace):
334334
completions = pyls_jedi_completions(doc._config, doc, com_position)
335335
assert completions[0]['label'] == 'loghub'
336336
assert 'changelog generator' in completions[0]['documentation'].lower()
337+
338+
339+
def test_document_path_completions(tmpdir, workspace_other_root_path):
340+
# Create a dummy module out of the workspace's root_path and try to get
341+
# completions for it in another file placed next to it.
342+
module_content = '''
343+
def foo():
344+
pass
345+
'''
346+
347+
p = tmpdir.join("mymodule.py")
348+
p.write(module_content)
349+
350+
# Content of doc to test completion
351+
doc_content = """import mymodule
352+
mymodule.f"""
353+
doc_path = str(tmpdir) + os.path.sep + 'myfile.py'
354+
doc_uri = uris.from_fs_path(doc_path)
355+
doc = Document(doc_uri, workspace_other_root_path, doc_content)
356+
357+
com_position = {'line': 1, 'character': 10}
358+
completions = pyls_jedi_completions(doc._config, doc, com_position)
359+
assert completions[0]['label'] == 'foo()'

0 commit comments

Comments
 (0)