diff --git a/jedi/api/helpers.py b/jedi/api/helpers.py index 84f9df33..80f9695e 100644 --- a/jedi/api/helpers.py +++ b/jedi/api/helpers.py @@ -53,28 +53,11 @@ class OnErrorLeaf(Exception): return self.args[0] -def _is_on_comment(leaf, position): - comment_lines = split_lines(leaf.prefix) - difference = leaf.start_pos[0] - position[0] - prefix_start_pos = leaf.get_start_pos_of_prefix() - if difference == 0: - indent = leaf.start_pos[1] - elif position[0] == prefix_start_pos[0]: - indent = prefix_start_pos[1] - else: - indent = 0 - line = comment_lines[-difference - 1][:position[1] - indent] - return '#' in line - - def _get_code_for_stack(code_lines, module_node, position): leaf = module_node.get_leaf_for_position(position, include_prefixes=True) # It might happen that we're on whitespace or on a comment. This means # that we would not get the right leaf. if leaf.start_pos >= position: - if _is_on_comment(leaf, position): - return u('') - # If we're not on a comment simply get the previous leaf and proceed. leaf = leaf.get_previous_leaf() if leaf is None: @@ -125,6 +108,9 @@ def get_stack_at_position(grammar, code_lines, module_node, pos): for token_ in tokens: if token_.string == safeword: raise EndMarkerReached() + elif token_.prefix.endswith(safeword): + # This happens with comments. + raise EndMarkerReached() else: yield token_ diff --git a/test/test_api/test_completion.py b/test/test_api/test_completion.py index 2f547813..7084a4a2 100644 --- a/test/test_api/test_completion.py +++ b/test/test_api/test_completion.py @@ -113,3 +113,8 @@ def test_generator(Script): " yield 1\n" \ "abc()." assert Script(s).completions() + + +def test_in_comment(Script): + assert Script(" # Comment").completions() + assert Script("max_attr_value = int(2) # Cast to int for spe").completions()