From 0fbc2aafa3b4ff2d05e972044f04b0f3456e9d69 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 12 Mar 2023 14:21:09 +0000 Subject: [PATCH] fix help when in column zero --- jedi/api/__init__.py | 6 ++++++ test/test_api/test_documentation.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index 37802c04..23e92001 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -369,6 +369,12 @@ class Script: 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 ('(', ')', '[', ']'): diff --git a/test/test_api/test_documentation.py b/test/test_api/test_documentation.py index 4c09d612..58c40eae 100644 --- a/test/test_api/test_documentation.py +++ b/test/test_api/test_documentation.py @@ -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)