mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-24 17:28:36 +08:00
Simplify the indent calculation in the fast parser.
This commit is contained in:
+6
-21
@@ -6,7 +6,7 @@ finished (and still not working as I want), I won't document it any further.
|
|||||||
import re
|
import re
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from jedi._compatibility import use_metaclass, unicode
|
from jedi._compatibility import use_metaclass
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.parser import Parser
|
from jedi.parser import Parser
|
||||||
from jedi.parser import tree as pr
|
from jedi.parser import tree as pr
|
||||||
@@ -67,7 +67,6 @@ class FastModule(pr.Module):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MergedNamesDict(object):
|
class MergedNamesDict(object):
|
||||||
def __init__(self, dicts):
|
def __init__(self, dicts):
|
||||||
self.dicts = dicts
|
self.dicts = dicts
|
||||||
@@ -174,31 +173,17 @@ class ParserNode(object):
|
|||||||
self._content_scope.names_dict = MergedNamesDict(dcts)
|
self._content_scope.names_dict = MergedNamesDict(dcts)
|
||||||
|
|
||||||
def parent_until_indent(self, indent=None):
|
def parent_until_indent(self, indent=None):
|
||||||
if indent is None or self._indent >= indent and self.parent:
|
if (indent is None or self._indent >= indent) and self.parent is not None:
|
||||||
if self.parent is not None:
|
self.close()
|
||||||
self.close()
|
return self.parent.parent_until_indent(indent)
|
||||||
return self.parent.parent_until_indent(indent)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _indent(self):
|
def _indent(self):
|
||||||
if not self.parent:
|
if not self.parent:
|
||||||
return 0
|
return 0
|
||||||
module = self.parser.module
|
|
||||||
try:
|
return self.parser.module.children[0].start_pos[1]
|
||||||
el = module.subscopes[0]
|
|
||||||
except IndexError:
|
|
||||||
try:
|
|
||||||
el = module.statements[0]
|
|
||||||
except IndexError:
|
|
||||||
try:
|
|
||||||
el = module.imports[0]
|
|
||||||
except IndexError:
|
|
||||||
try:
|
|
||||||
el = [r for r in module.returns if r is not None][0]
|
|
||||||
except IndexError:
|
|
||||||
el = module.children[0]
|
|
||||||
return el.start_pos[1]
|
|
||||||
|
|
||||||
def add_node(self, node, line_offset):
|
def add_node(self, node, line_offset):
|
||||||
"""Adding a node means adding a node that was already added earlier"""
|
"""Adding a node means adding a node that was already added earlier"""
|
||||||
|
|||||||
Reference in New Issue
Block a user