mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Make sure to get completions for backticks in docstrings work, see #860
This commit is contained in:
@@ -447,6 +447,7 @@ class Completion:
|
|||||||
|
|
||||||
- Having an indented block of code
|
- Having an indented block of code
|
||||||
- Having some doctest code that starts with `>>>`
|
- Having some doctest code that starts with `>>>`
|
||||||
|
- Having backticks that doesn't have whitespace inside it
|
||||||
"""
|
"""
|
||||||
def iter_relevant_lines(lines):
|
def iter_relevant_lines(lines):
|
||||||
include_next_line = False
|
include_next_line = False
|
||||||
@@ -460,30 +461,35 @@ class Completion:
|
|||||||
|
|
||||||
string = dedent(string)
|
string = dedent(string)
|
||||||
code_lines = split_lines(string, keepends=True)
|
code_lines = split_lines(string, keepends=True)
|
||||||
code_lines = list(iter_relevant_lines(code_lines))
|
relevant_code_lines = list(iter_relevant_lines(code_lines))
|
||||||
if code_lines[-1] is not None:
|
if relevant_code_lines[-1] is not None:
|
||||||
# Some code lines might be None, therefore get rid of that.
|
# 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)
|
||||||
module_node = self._inference_state.grammar.parse(''.join(code_lines))
|
match = re.search(r'`([^`\s]+)', code_lines[-1])
|
||||||
module_value = ModuleValue(
|
if match:
|
||||||
self._inference_state,
|
return self._complete_code_lines([match.group(1)])
|
||||||
module_node,
|
|
||||||
file_io=None,
|
|
||||||
string_names=None,
|
|
||||||
code_lines=code_lines,
|
|
||||||
)
|
|
||||||
module_value.parent_context = self._module_context
|
|
||||||
return Completion(
|
|
||||||
self._inference_state,
|
|
||||||
module_value.as_context(),
|
|
||||||
code_lines=code_lines,
|
|
||||||
position=module_node.end_pos,
|
|
||||||
signatures_callback=lambda *args, **kwargs: [],
|
|
||||||
fuzzy=self._fuzzy
|
|
||||||
).complete()
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def _complete_code_lines(self, code_lines):
|
||||||
|
module_node = self._inference_state.grammar.parse(''.join(code_lines))
|
||||||
|
module_value = ModuleValue(
|
||||||
|
self._inference_state,
|
||||||
|
module_node,
|
||||||
|
file_io=None,
|
||||||
|
string_names=None,
|
||||||
|
code_lines=code_lines,
|
||||||
|
)
|
||||||
|
module_value.parent_context = self._module_context
|
||||||
|
return Completion(
|
||||||
|
self._inference_state,
|
||||||
|
module_value.as_context(),
|
||||||
|
code_lines=code_lines,
|
||||||
|
position=module_node.end_pos,
|
||||||
|
signatures_callback=lambda *args, **kwargs: [],
|
||||||
|
fuzzy=self._fuzzy
|
||||||
|
).complete()
|
||||||
|
|
||||||
|
|
||||||
def _gather_nodes(stack):
|
def _gather_nodes(stack):
|
||||||
nodes = []
|
nodes = []
|
||||||
|
|||||||
@@ -284,6 +284,25 @@ def doctest_with_space():
|
|||||||
import_issu
|
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():
|
def doctest_without_ending():
|
||||||
"""
|
"""
|
||||||
#? []
|
#? []
|
||||||
|
|||||||
Reference in New Issue
Block a user