Skip to content

Commit

Permalink
Merge pull request #340 from immerrr/ignore-all-errors-when-getting-c…
Browse files Browse the repository at this point in the history
…ompletion-docstrings

Ignore all errors when getting completion docstrings
  • Loading branch information
immerrr authored Oct 7, 2019
2 parents 22aecb4 + 0998562 commit 3ccc7a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
19 changes: 12 additions & 7 deletions jediepcserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,25 @@ def jedi_script(self, source, line, column, source_path):
)

def complete(self, *args):
reply = []
for comp in self.jedi_script(*args).completions():
def _wrap_completion_result(comp):
try:
docstr = comp.docstring()
except KeyError:
except Exception:
logger.warning(
"Cannot get docstring for completion %s", comp, exc_info=1
)
docstr = ""

reply.append(dict(
return dict(
word=comp.name,
doc=docstr,
description=candidates_description(comp),
symbol=candidate_symbol(comp),
))
return reply
)

return [
_wrap_completion_result(comp)
for comp in self.jedi_script(*args).completions()
]

def get_in_function_call(self, *args):
sig = self.jedi_script(*args).call_signatures()
Expand Down
29 changes: 29 additions & 0 deletions test_jediepcserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,32 @@ def foo(bar, baz, *qux, **quux):
'index': 0,
'call_name': 'foo',
}


def test_completion_docstring_raises(monkeypatch):
"""Test "complete" handler does not fail if "comp.docstring" raises
Ref. #339
"""
def raise_exception(*args, **kwargs):
raise Exception('hello, world')

monkeypatch.setattr(
'jedi.api.classes.Completion.docstring', raise_exception
)

params = _get_jedi_script_params("""
import os
os.chd
""")
handler = jep.JediEPCHandler()
result = handler.complete(*params)
assert result == [
{
'word': 'chdir',
'doc': '',
'description': 'def chdir',
'symbol': 'f',
},
]

0 comments on commit 3ccc7a5

Please sign in to comment.