forked from VimPlug/jedi
Make completion of pytest fixtures possible
This commit is contained in:
+16
-1
@@ -18,6 +18,7 @@ from jedi.inference.context import get_global_filters
|
|||||||
from jedi.inference.value import TreeInstance
|
from jedi.inference.value import TreeInstance
|
||||||
from jedi.inference.gradual.conversion import convert_values
|
from jedi.inference.gradual.conversion import convert_values
|
||||||
from jedi.parser_utils import cut_value_at_position
|
from jedi.parser_utils import cut_value_at_position
|
||||||
|
from jedi.plugins import plugin_manager
|
||||||
|
|
||||||
|
|
||||||
def get_signature_param_names(signatures):
|
def get_signature_param_names(signatures):
|
||||||
@@ -74,6 +75,13 @@ def get_flow_scope_node(module_node, position):
|
|||||||
return node
|
return node
|
||||||
|
|
||||||
|
|
||||||
|
@plugin_manager.decorate()
|
||||||
|
def complete_param_names(context, function_name):
|
||||||
|
# Basically there's no way to do param completion. The plugins are
|
||||||
|
# responsible for this.
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
class Completion:
|
class Completion:
|
||||||
def __init__(self, inference_state, module_context, code_lines, position,
|
def __init__(self, inference_state, module_context, code_lines, position,
|
||||||
signatures_callback, fuzzy=False):
|
signatures_callback, fuzzy=False):
|
||||||
@@ -217,7 +225,14 @@ class Completion:
|
|||||||
dot = self._module_node.get_leaf_for_position(self._position)
|
dot = self._module_node.get_leaf_for_position(self._position)
|
||||||
completion_names += self._complete_trailer(dot.get_previous_leaf())
|
completion_names += self._complete_trailer(dot.get_previous_leaf())
|
||||||
elif self._is_parameter_completion():
|
elif self._is_parameter_completion():
|
||||||
pass
|
stack_node = self.stack[-2]
|
||||||
|
if stack_node.nonterminal == 'parameters':
|
||||||
|
stack_node = self.stack[-3]
|
||||||
|
if stack_node.nonterminal == 'funcdef':
|
||||||
|
context = get_user_context(self._module_context, self._position)
|
||||||
|
function_name = stack_node.nodes[1]
|
||||||
|
|
||||||
|
completion_names += complete_param_names(context, function_name)
|
||||||
else:
|
else:
|
||||||
completion_names += self._complete_global_scope()
|
completion_names += self._complete_global_scope()
|
||||||
completion_names += self._complete_inherited(is_function=False)
|
completion_names += self._complete_inherited(is_function=False)
|
||||||
|
|||||||
@@ -53,6 +53,18 @@ def goto_anonymous_param(func):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def complete_param_names(func):
|
||||||
|
def wrapper(context, func_name):
|
||||||
|
module_context = context.get_root_context()
|
||||||
|
names = []
|
||||||
|
for module_context in _iter_pytest_modules(module_context):
|
||||||
|
names += FixtureFilter(module_context).values()
|
||||||
|
if names:
|
||||||
|
return names
|
||||||
|
return func(context, func_name)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def _goto_pytest_fixture(module_context, name):
|
def _goto_pytest_fixture(module_context, name):
|
||||||
for module_context in _iter_pytest_modules(module_context):
|
for module_context in _iter_pytest_modules(module_context):
|
||||||
names = FixtureFilter(module_context).get(name)
|
names = FixtureFilter(module_context).get(name)
|
||||||
|
|||||||
@@ -54,9 +54,21 @@ def test_x(MyClassFixture):
|
|||||||
#? 34 ['my_fixture']
|
#? 34 ['my_fixture']
|
||||||
def test_x(my_simple_fixture, my_fixture):
|
def test_x(my_simple_fixture, my_fixture):
|
||||||
return
|
return
|
||||||
|
#? 34 ['my_fixture']
|
||||||
|
def test_x(my_simple_fixture, my_fixture):
|
||||||
|
return
|
||||||
|
#? ['my_fixture']
|
||||||
|
def test_x(my_simple_fixture, my_f
|
||||||
|
return
|
||||||
#? 18 ['my_simple_fixture']
|
#? 18 ['my_simple_fixture']
|
||||||
def test_x(my_simple_fixture):
|
def test_x(my_simple_fixture):
|
||||||
return
|
return
|
||||||
|
#? ['my_simple_fixture']
|
||||||
|
def test_x(my_simp
|
||||||
|
return
|
||||||
|
#? ['my_conftest_fixture']
|
||||||
|
def test_x(my_con
|
||||||
|
return
|
||||||
#? 18 ['my_conftest_fixture']
|
#? 18 ['my_conftest_fixture']
|
||||||
def test_x(my_conftest_fixture):
|
def test_x(my_conftest_fixture):
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user