Added switch to declFromIndex, fixed occasional crash
This commit is contained in:
parent
a189fa171c
commit
34adb4e22f
@ -523,7 +523,7 @@ pub fn declsFromIndexInternal(decls: *std.ArrayList(*ast.Node), tree: *ast.Tree,
|
|||||||
|
|
||||||
const is_contained = nodeContainsSourceIndex(tree, child_node, source_index);
|
const is_contained = nodeContainsSourceIndex(tree, child_node, source_index);
|
||||||
// If the cursor is in a variable decls it will insert itself anyway, we don't need to take care of it.
|
// If the cursor is in a variable decls it will insert itself anyway, we don't need to take care of it.
|
||||||
if ((is_contained and child_node.id != .VarDecl) or !is_contained) try decls.append(child_node);
|
if ((is_contained and child_node.id != .VarDecl) or !is_contained) try decls.append(child_node);
|
||||||
if (is_contained) {
|
if (is_contained) {
|
||||||
try declsFromIndexInternal(decls, tree, child_node, source_index);
|
try declsFromIndexInternal(decls, tree, child_node, source_index);
|
||||||
}
|
}
|
||||||
@ -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...
|
// TODO: These convey no type information...
|
||||||
.Payload => try decls.append(node.cast(ast.Node.Payload).?.error_symbol),
|
.Payload => try decls.append(node.cast(ast.Node.Payload).?.error_symbol),
|
||||||
.PointerPayload => try decls.append(node.cast(ast.Node.PointerPayload).?.value_symbol),
|
.PointerPayload => try decls.append(node.cast(ast.Node.PointerPayload).?.value_symbol),
|
||||||
|
@ -293,10 +293,11 @@ fn identifierFromPosition(pos_index: usize, handle: DocumentStore.Handle) []cons
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
var end_idx = pos_index;
|
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)
|
(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];
|
return text[start_idx + 1 .. end_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user