Merge pull request #1262 from FnControlOption/block-type
Resolve type of simple labeled block
This commit is contained in:
commit
7487308948
@ -1140,6 +1140,33 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e
|
|||||||
.handle = handle,
|
.handle = handle,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
.block,
|
||||||
|
.block_semicolon,
|
||||||
|
.block_two,
|
||||||
|
.block_two_semicolon,
|
||||||
|
=> {
|
||||||
|
const first_token = tree.firstToken(node);
|
||||||
|
if (token_tags[first_token] != .identifier) return null;
|
||||||
|
|
||||||
|
const block_label = tree.tokenSlice(first_token);
|
||||||
|
|
||||||
|
var buffer: [2]Ast.Node.Index = undefined;
|
||||||
|
const statements = ast.blockStatements(tree, node, &buffer).?;
|
||||||
|
|
||||||
|
for (statements) |child_idx| {
|
||||||
|
// TODO: Recursively find matching `break :label` (e.g. inside `if`)
|
||||||
|
if (node_tags[child_idx] == .@"break") {
|
||||||
|
if (datas[child_idx].lhs == 0) continue;
|
||||||
|
if (datas[child_idx].rhs == 0) continue;
|
||||||
|
|
||||||
|
const break_label = tree.tokenSlice(datas[child_idx].lhs);
|
||||||
|
if (!std.mem.eql(u8, block_label, break_label)) continue;
|
||||||
|
|
||||||
|
const operand = .{ .node = datas[child_idx].rhs, .handle = handle };
|
||||||
|
return try analyser.resolveTypeOfNodeInternal(operand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -509,6 +509,17 @@ test "completion - block" {
|
|||||||
, &.{
|
, &.{
|
||||||
.{ .label = "blk", .kind = .Text }, // idk what kind this should be
|
.{ .label = "blk", .kind = .Text }, // idk what kind this should be
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try testCompletion(
|
||||||
|
\\const S = struct { alpha: u32 };
|
||||||
|
\\const foo: S = undefined;
|
||||||
|
\\const bar = blk: {
|
||||||
|
\\ break :blk foo;
|
||||||
|
\\};
|
||||||
|
\\const baz = bar.<cursor>
|
||||||
|
, &.{
|
||||||
|
.{ .label = "alpha", .kind = .Field, .detail = "alpha: u32" },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn testCompletion(source: []const u8, expected_completions: []const Completion) !void {
|
fn testCompletion(source: []const u8, expected_completions: []const Completion) !void {
|
||||||
|
Loading…
Reference in New Issue
Block a user