forked from VimPlug/jedi
Don't display unnecessary help, fixes #1557
This commit is contained in:
@@ -473,8 +473,19 @@ class Script(object):
|
|||||||
return definitions
|
return definitions
|
||||||
leaf = self._module_node.get_leaf_for_position((line, column))
|
leaf = self._module_node.get_leaf_for_position((line, column))
|
||||||
if leaf is not None and leaf.type in ('keyword', 'operator', 'error_leaf'):
|
if leaf is not None and leaf.type in ('keyword', 'operator', 'error_leaf'):
|
||||||
reserved = self._inference_state.grammar._pgen_grammar.reserved_syntax_strings.keys()
|
def need_pydoc():
|
||||||
if leaf.value in reserved:
|
if leaf.value in ('(', ')', '[', ']'):
|
||||||
|
if leaf.parent.type == 'trailer':
|
||||||
|
return False
|
||||||
|
if leaf.parent.type == 'atom':
|
||||||
|
return False
|
||||||
|
grammar = self._inference_state.grammar
|
||||||
|
# This parso stuff is not public, but since I control it, this
|
||||||
|
# is fine :-) ~dave
|
||||||
|
reserved = grammar._pgen_grammar.reserved_syntax_strings.keys()
|
||||||
|
return leaf.value in reserved
|
||||||
|
|
||||||
|
if need_pydoc():
|
||||||
name = KeywordName(self._inference_state, leaf.value)
|
name = KeywordName(self._inference_state, leaf.value)
|
||||||
return [classes.Name(self._inference_state, name)]
|
return [classes.Name(self._inference_state, name)]
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -120,3 +120,13 @@ def test_docstring_decorator(goto_or_help_or_infer, skip_python2):
|
|||||||
@pytest.mark.parametrize('code', ['', '\n', ' '])
|
@pytest.mark.parametrize('code', ['', '\n', ' '])
|
||||||
def test_empty(Script, code):
|
def test_empty(Script, code):
|
||||||
assert not Script(code).help(1, 0)
|
assert not Script(code).help(1, 0)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('code', ['f()', '(bar or baz)', 'f[3]'])
|
||||||
|
def test_no_help_for_operator(Script, code):
|
||||||
|
assert not Script(code).help()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('code', ['()', '(1,)', '[]', '[1]', 'f[]'])
|
||||||
|
def test_help_for_operator(Script, code):
|
||||||
|
assert Script(code).help()
|
||||||
|
|||||||
Reference in New Issue
Block a user