Added switch to declFromIndex, fixed occasional crash

This commit is contained in:
Alexandros Naskos 2020-05-23 02:33:42 +03:00
parent a189fa171c
commit 34adb4e22f
2 changed files with 16 additions and 2 deletions

View File

@ -610,6 +610,19 @@ pub fn declsFromIndexInternal(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree,
}
}
},
.Switch => {
const switch_node = node.cast(ast.Node.Switch).?;
var case_it = switch_node.cases.iterator(0);
while (case_it.next()) |case| {
const case_node = case.*.cast(ast.Node.SwitchCase).?;
if (nodeContainsSourceIndex(tree, case_node.expr, source_index)) {
if (case_node.payload) |payload| {
try declsFromIndexInternal(decls, tree, payload, source_index);
}
return try declsFromIndexInternal(decls, tree, case_node.expr, source_index);
}
}
},
// TODO: These convey no type information...
.Payload => try decls.append(node.cast(ast.Node.Payload).?.error_symbol),
.PointerPayload => try decls.append(node.cast(ast.Node.PointerPayload).?.value_symbol),

View File

@ -293,10 +293,11 @@ fn identifierFromPosition(pos_index: usize, handle: DocumentStore.Handle) []cons
{}
var end_idx = pos_index;
while (end_idx < handle.document.text.len - 1 and
while (end_idx < handle.document.text.len and
(std.ascii.isAlNum(text[end_idx]) or text[end_idx] == '_')) : (end_idx += 1)
{}
if (end_idx <= start_idx) return &[0]u8{};
return text[start_idx + 1 .. end_idx];
}