Make highlight names work with recent Jedi versions,
@@ -42,14 +42,39 @@ def get_statement_of_position(node, pos):
try:
# jedi 0.11
# pylint: disable=redefined-outer-name
- from jedi.parser_utils import get_statement_of_position
+ import jedi.parser_utils
- return get_statement_of_position(node, pos)
+ func = getattr(
+ jedi.parser_utils, "get_statement_of_position", _copy_of_get_statement_of_position
+ )
+ return func(node, pos)
except ImportError:
# Older versions
return node.get_statement_for_position(pos)
+def _copy_of_get_statement_of_position(node, pos):
+ # https://github.com/davidhalter/jedi/commit/9f3a2f93c48eda24e2dcc25e54eb7cc10aa73848
+ from parso.python import tree
+
+ for c in node.children:
+ if c.start_pos <= pos <= c.end_pos:
+ if c.type not in (
+ "decorated",
+ "simple_stmt",
+ "suite",
+ "async_stmt",
+ "async_funcdef",
+ ) and not isinstance(c, (tree.Flow, tree.ClassOrFunc)):
+ return c
+ else:
+ try:
+ return _copy_of_get_statement_of_position(c, pos)
+ except AttributeError:
+ pass # Must be a non-scope
+ return None
+
+
def get_module_node(script):
if hasattr(script, "_module_node"): # Jedi 0.12
return script._module_node
