forked from VimPlug/jedi
Fix some more problems with the fast parser.
This commit is contained in:
@@ -22,7 +22,22 @@ def sorted_definitions(defs):
|
|||||||
|
|
||||||
def get_on_completion_name(module, position):
|
def get_on_completion_name(module, position):
|
||||||
leaf = module.get_leaf_for_position(position)
|
leaf = module.get_leaf_for_position(position)
|
||||||
if leaf is None or leaf.type not in ('name', 'keyword'):
|
if leaf is None:
|
||||||
|
return ''
|
||||||
|
elif leaf.type == 'string':
|
||||||
|
# Completions inside strings are a bit special, we need to parse the
|
||||||
|
# string.
|
||||||
|
lines = leaf.value.splitlines()
|
||||||
|
start_pos = leaf.start_pos
|
||||||
|
difference = position[0] - start_pos[0]
|
||||||
|
if difference == 0:
|
||||||
|
indent = start_pos[1]
|
||||||
|
else:
|
||||||
|
indent = 0
|
||||||
|
line = lines[difference][:position[1] - indent]
|
||||||
|
# The first step of completions is to get the name
|
||||||
|
return re.search(r'(?!\d)\w+$|$', line).group(0)
|
||||||
|
elif leaf.type not in ('name', 'keyword'):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return leaf.value[:position[1] - leaf.start_pos[1]]
|
return leaf.value[:position[1] - leaf.start_pos[1]]
|
||||||
|
|||||||
@@ -120,6 +120,10 @@ class ParserNode(object):
|
|||||||
self.source = source
|
self.source = source
|
||||||
self.hash = hash(source)
|
self.hash = hash(source)
|
||||||
self.parser = parser
|
self.parser = parser
|
||||||
|
if source:
|
||||||
|
self._end_pos = parser.module.end_pos
|
||||||
|
else:
|
||||||
|
self._end_pos = 1, 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# With fast_parser we have either 1 subscope or only statements.
|
# With fast_parser we have either 1 subscope or only statements.
|
||||||
@@ -162,6 +166,10 @@ class ParserNode(object):
|
|||||||
# There's no module yet.
|
# There's no module yet.
|
||||||
return '<%s: empty>' % type(self).__name__
|
return '<%s: empty>' % type(self).__name__
|
||||||
|
|
||||||
|
@property
|
||||||
|
def end_pos(self):
|
||||||
|
return self._end_pos[0] + self.parser.position_modifier.line, self._end_pos[1]
|
||||||
|
|
||||||
def reset_node(self):
|
def reset_node(self):
|
||||||
"""
|
"""
|
||||||
Removes changes that were applied in this class.
|
Removes changes that were applied in this class.
|
||||||
@@ -188,6 +196,10 @@ class ParserNode(object):
|
|||||||
# Need to insert the own node as well.
|
# Need to insert the own node as well.
|
||||||
dcts.insert(0, self._content_scope.names_dict)
|
dcts.insert(0, self._content_scope.names_dict)
|
||||||
self._content_scope.names_dict = MergedNamesDict(dcts)
|
self._content_scope.names_dict = MergedNamesDict(dcts)
|
||||||
|
endmarker = self.parser.get_parsed_node().children[-1]
|
||||||
|
assert endmarker.type == 'endmarker'
|
||||||
|
last_parser = self._node_children[-1].parser
|
||||||
|
endmarker.start_pos = last_parser.get_parsed_node().end_pos
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _indent(self):
|
def _indent(self):
|
||||||
@@ -414,7 +426,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
# called - just ignore it.
|
# called - just ignore it.
|
||||||
src = ''.join(self._lines[code_part_end_line - 1:])
|
src = ''.join(self._lines[code_part_end_line - 1:])
|
||||||
self._parse_part(code_part, src, code_part_end_line, nodes)
|
self._parse_part(code_part, src, code_part_end_line, nodes)
|
||||||
last_end_line = self.current_node.parser.module.end_pos[0]
|
last_end_line = self.current_node.end_pos[0]
|
||||||
debug.dbg("While parsing %s, starting with line %s wasn't included in split.",
|
debug.dbg("While parsing %s, starting with line %s wasn't included in split.",
|
||||||
self.module_path, code_part_end_line)
|
self.module_path, code_part_end_line)
|
||||||
#assert code_part_end_line > last_end_line
|
#assert code_part_end_line > last_end_line
|
||||||
@@ -426,7 +438,7 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
code_part_end_line = next_code_part_end_line
|
code_part_end_line = next_code_part_end_line
|
||||||
start += len(code_part)
|
start += len(code_part)
|
||||||
|
|
||||||
last_end_line = self.current_node.parser.module.end_pos[0]
|
last_end_line = self.current_node.end_pos[0]
|
||||||
|
|
||||||
if added_newline:
|
if added_newline:
|
||||||
self.current_node.remove_last_newline()
|
self.current_node.remove_last_newline()
|
||||||
|
|||||||
Reference in New Issue
Block a user