Skip to content

Commit

Permalink
Merge pull request #1923 from dimbleby/help-after-newline
Browse files Browse the repository at this point in the history
fix help when in column zero
  • Loading branch information
davidhalter authored Mar 13, 2023
2 parents b814ca2 + 0fbc2aa commit 6ee33bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions jedi/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ def help(self, line=None, column=None):
if definitions:
return definitions
leaf = self._module_node.get_leaf_for_position((line, column))

if leaf is not None and leaf.end_pos == (line, column) and leaf.type == 'newline':
next_ = leaf.get_next_leaf()
if next_ is not None and next_.start_pos == leaf.end_pos:
leaf = next_

if leaf is not None and leaf.type in ('keyword', 'operator', 'error_leaf'):
def need_pydoc():
if leaf.value in ('(', ')', '[', ']'):
Expand Down
5 changes: 5 additions & 0 deletions test/test_api/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def test_import_keyword(Script):
# unrelated to #44


def test_import_keyword_after_newline(Script):
d, = Script("import x\nimport y").help(line=2, column=0)
assert d.docstring().startswith('The "import" statement')


def test_import_keyword_with_gotos(goto_or_infer):
assert not goto_or_infer("import x", column=0)

Expand Down

0 comments on commit 6ee33bd

Please sign in to comment.