8000 Fix completions for properties (#477) · lcheylus/python-lsp-server@a0bec01 · GitHub
[go: up one dir, main page]

Skip to content

Commit a0bec01

Browse files
authored
Fix completions for properties (python-lsp#477)
1 parent db16c23 commit a0bec01

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

pyls/plugins/jedi_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def pyls_completions(document, position):
1919

2020

2121
def _label(definition):
22-
if definition.type in ('function', 'method'):
22+
if definition.type in ('function', 'method') and hasattr(definition, 'params'):
2323
params = ', '.join(param.name for param in definition.params)
2424
return '{}({})'.format(definition.name, params)
2525

test/plugins/test_completion.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ def hello():
2020
def _a_hello():
2121
pass
2222
23+
class Hello():
24+
25+
@property
26+
def world(self):
27+
return None
28+
29+
print Hello().world
2330
"""
2431

2532

@@ -64,3 +71,15 @@ def test_jedi_completion_ordering():
6471

6572
# And that 'hidden' functions come after unhidden ones
6673
assert items['hello()'] < items['_a_hello()']
74+
75+
76+
def test_jedi_property_completion():
77+
# Over the 'w' in 'print Hello().world'
78+
com_position = {'line': 15, 'character': 15}
79+
doc = Document(DOC_URI, DOC)
80+
completions = pyls_jedi_completions(doc, com_position)
81+
82+
items = {c['label']: c['sortText'] for c in completions}
83+
84+
# Ensure we can complete the 'world' property
85+
assert 'world' in items

tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ exclude = test/plugins/.ropeproject,test/.ropeproject
1313

1414
[pytest]
1515
testpaths = test
16-
addopts =
17-
--cov-report html --cov-report term --junitxml=pytest.xml
18-
--cov pyls --cov test
16+
#addopts =
17+
# --cov-report html --cov-report term --junitxml=pytest.xml
18+
# --cov pyls --cov test
1919

2020
[testenv]
2121
commands =

0 commit comments

Comments
 (0)
0