Skip to content

Commit ff1a6c2

Browse files
committed
Read plugins.jedi.extra_paths configuration also from files
Before this commit, plugins.jedi.extra_paths can be configured only via Language Server Protocol didChangeConfiguration method. This is inconvenient, if: - it is difficult to issue LSP didChangeConfiguration method with per-workspace configuration - such configuration should be persisted inside workspace This commit reads plugins.jedi.extra_paths configuration also from project-level configuration "setup.cfg" and "tox.ini".
1 parent 8094a09 commit ff1a6c2

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

pyls/config/pyls_conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010

1111
OPTIONS = [
1212
('source_roots', 'source_roots', list),
13+
14+
# inter-plugins configurations
15+
('plugins.jedi.extra_paths', 'plugins.jedi.extra_paths', list),
1316
]
1417

1518
# list of (config_path, inside_only) tuples for path normalization
1619
NORMALIZED_CONFIGS = [
1720
('source_roots', True),
21+
('plugins.jedi.extra_paths', False),
1822
]
1923

2024

test/test_workspace.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,62 @@ def test_pyls_config_readin(tmpdir, metafile):
251251
for raw_path in source_roots:
252252
full_path = os.path.normcase(os.path.join(root_path, raw_path))
253253
assert os.path.normpath(full_path) in sys_path
254+
255+
256+
@pytest.mark.parametrize('metafile', [
257+
'setup.cfg',
258+
'tox.ini',
259+
'service/foo/setup.cfg',
260+
'service/foo/tox.ini',
261+
None,
262+
])
263+
def test_jedi_extra_paths_config(tmpdir, metafile):
264+
"""Examine that plugins.jedi.extra_paths config is intentionaly read in.
265+
266+
This test also examines below for entries in plugins.jedi.extra_paths:
267+
268+
* relative path is:
269+
- treated as relative to config file location, and
270+
- normalized into absolute one
271+
"""
272+
root_path = str(tmpdir)
273+
274+
extra_paths = ['extra/foo', 'extra/bar', '/absolute/root', '../baz']
275+
doc_root = 'service/foo'
276+
277+
if metafile:
278+
dirname = os.path.dirname(metafile)
279+
if dirname:
280+
os.makedirs(os.path.join(root_path, dirname))
281+
282+
# configured by metafile at pyls startup
283+
with open(os.path.join(root_path, metafile), 'w+') as f:
284+
f.write('[pyls]\nplugins.jedi.extra_paths=\n %s\n' %
285+
',\n '.join(_make_paths_dir_relative(extra_paths, dirname)))
286+
287+
pyls = PythonLanguageServer(StringIO, StringIO)
288+
pyls.m_initialize(
289+
processId=1,
290+
rootUri=uris.from_fs_path(root_path),
291+
initializationOptions={}
292+
)
293+
294+
if not metafile:
295+
# configured by client via LSP after pyls startup
296+
pyls.m_workspace__did_change_configuration({
297+
'pyls': {'plugins': {'jedi': {'extra_paths': extra_paths}}},
298+
})
299+
300+
# put new document under ROOT/service/foo
301+
test_uri = uris.from_fs_path(os.path.join(root_path, doc_root, 'hello/test.py'))
302+
pyls.workspace.put_document(test_uri, 'assert true')
303+
test_doc = pyls.workspace.get_document(test_uri)
304+
305+
# apply os.path.normcase() on paths below, because case-sensitive
306+
# comparison on Windows causes unintentional failure for case
307+
# instability around drive letter
308+
309+
sys_path = [os.path.normcase(p) for p in test_doc.sys_path()]
310+
for raw_path in extra_paths:
311+
full_path = os.path.normcase(os.path.join(root_path, raw_path))
312+
assert os.path.normpath(full_path) in sys_path

0 commit comments

Comments
 (0)