mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Make nested dict completions possible.
See also https://github.com/ipython/ipython/issues/13866
This commit is contained in:
@@ -36,8 +36,11 @@ def complete_dict(module_context, code_lines, leaf, position, string, fuzzy):
|
|||||||
string = cut_value_at_position(leaf, position)
|
string = cut_value_at_position(leaf, position)
|
||||||
|
|
||||||
context = module_context.create_context(bracket_leaf)
|
context = module_context.create_context(bracket_leaf)
|
||||||
before_bracket_leaf = bracket_leaf.get_previous_leaf()
|
|
||||||
if before_bracket_leaf.type in ('atom', 'trailer', 'name'):
|
before_node = before_bracket_leaf = bracket_leaf.get_previous_leaf()
|
||||||
|
if before_node in (')', ']', '}'):
|
||||||
|
before_node = before_node.parent
|
||||||
|
if before_node.type in ('atom', 'trailer', 'name'):
|
||||||
values = infer_call_of_leaf(context, before_bracket_leaf)
|
values = infer_call_of_leaf(context, before_bracket_leaf)
|
||||||
return list(_completions_for_dicts(
|
return list(_completions_for_dicts(
|
||||||
module_context.inference_state,
|
module_context.inference_state,
|
||||||
|
|||||||
@@ -830,3 +830,11 @@ def test_try_to_use_return_annotation_for_property(class_is_findable):
|
|||||||
# This is a fallback, if the annotations don't help
|
# This is a fallback, if the annotations don't help
|
||||||
_assert_interpreter_complete('p.with_annotation_garbage1.its', namespace, ['its_me'])
|
_assert_interpreter_complete('p.with_annotation_garbage1.its', namespace, ['its_me'])
|
||||||
_assert_interpreter_complete('p.with_annotation_garbage2.its', namespace, ['its_me'])
|
_assert_interpreter_complete('p.with_annotation_garbage2.its', namespace, ['its_me'])
|
||||||
|
|
||||||
|
|
||||||
|
def test_nested__getitem__():
|
||||||
|
d = {'foo': {'bar': 1}}
|
||||||
|
_assert_interpreter_complete('d["fo', locals(), ['"foo"'])
|
||||||
|
_assert_interpreter_complete('d["foo"]["ba', locals(), ['"bar"'])
|
||||||
|
_assert_interpreter_complete('(d["foo"])["ba', locals(), ['"bar"'])
|
||||||
|
_assert_interpreter_complete('((d["foo"]))["ba', locals(), ['"bar"'])
|
||||||
|
|||||||
Reference in New Issue
Block a user