Make sure to get completions for backticks in docstrings work, see #860

This commit is contained in:
Dave Halter
2020-01-01 01:53:55 +01:00
parent cea7a12908
commit 818577f423
2 changed files with 46 additions and 21 deletions

View File

@@ -447,6 +447,7 @@ class Completion:
- Having an indented block of code
- Having some doctest code that starts with `>>>`
- Having backticks that doesn't have whitespace inside it
"""
def iter_relevant_lines(lines):
include_next_line = False
@@ -460,11 +461,17 @@ class Completion:
string = dedent(string)
code_lines = split_lines(string, keepends=True)
code_lines = list(iter_relevant_lines(code_lines))
if code_lines[-1] is not None:
relevant_code_lines = list(iter_relevant_lines(code_lines))
if relevant_code_lines[-1] is not None:
# Some code lines might be None, therefore get rid of that.
code_lines = [c or '\n' for c in code_lines]
relevant_code_lines = [c or '\n' for c in relevant_code_lines]
return self._complete_code_lines(relevant_code_lines)
match = re.search(r'`([^`\s]+)', code_lines[-1])
if match:
return self._complete_code_lines([match.group(1)])
return []
def _complete_code_lines(self, code_lines):
module_node = self._inference_state.grammar.parse(''.join(code_lines))
module_value = ModuleValue(
self._inference_state,
@@ -482,7 +489,6 @@ class Completion:
signatures_callback=lambda *args, **kwargs: [],
fuzzy=self._fuzzy
).complete()
return []
def _gather_nodes(stack):

View File

@@ -284,6 +284,25 @@ def doctest_with_space():
import_issu
"""
def docstring_rst_identifiers():
"""
#? 30 ['import_issues']
hello I'm here `import_iss` blabla
#? ['import_issues']
hello I'm here `import_iss
#? []
hello I'm here import_iss
#? []
hello I'm here ` import_iss
#? ['upper']
hello I'm here `str.upp
"""
def doctest_without_ending():
"""
#? []