Align expr fix
This commit is contained in:
parent
d4e6ddd780
commit
e59e1f08e5
@ -754,6 +754,16 @@ pub fn resolveTypeOfNodeInternal(
|
|||||||
return innermostContainer(handle, handle.tree.token_locs[builtin_call.firstToken()].start);
|
return innermostContainer(handle, handle.tree.token_locs[builtin_call.firstToken()].start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (std.mem.eql(u8, call_name, "@cImport")) {
|
||||||
|
// @TODO
|
||||||
|
if (builtin_call.params_len != 1) return null;
|
||||||
|
|
||||||
|
// 1 - Get innermost container scope.
|
||||||
|
if (builtin_call.paramsConst()[0].cast(ast.Node.Block)) |block| {
|
||||||
|
std.debug.warn("cImport block: {}\n", .{block});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const cast_map = std.ComptimeStringMap(void, .{
|
const cast_map = std.ComptimeStringMap(void, .{
|
||||||
.{"@as"},
|
.{"@as"},
|
||||||
.{"@bitCast"},
|
.{"@bitCast"},
|
||||||
|
@ -3,6 +3,8 @@ const DocumentStore = @import("document_store.zig");
|
|||||||
const analysis = @import("analysis.zig");
|
const analysis = @import("analysis.zig");
|
||||||
const ast = std.zig.ast;
|
const ast = std.zig.ast;
|
||||||
|
|
||||||
|
// TODO Some align expressions break the highlighting
|
||||||
|
|
||||||
const TokenType = enum(u32) {
|
const TokenType = enum(u32) {
|
||||||
type,
|
type,
|
||||||
@"struct",
|
@"struct",
|
||||||
@ -99,6 +101,7 @@ fn writeDocComments(builder: *Builder, tree: *ast.Tree, doc: *ast.Node.DocCommen
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fieldTokenType(container_decl: *ast.Node.ContainerDecl, handle: *DocumentStore.Handle) ?TokenType {
|
fn fieldTokenType(container_decl: *ast.Node.ContainerDecl, handle: *DocumentStore.Handle) ?TokenType {
|
||||||
|
if (container_decl.kind_token > handle.tree.token_ids.len) return null;
|
||||||
return @as(?TokenType, switch (handle.tree.token_ids[container_decl.kind_token]) {
|
return @as(?TokenType, switch (handle.tree.token_ids[container_decl.kind_token]) {
|
||||||
.Keyword_struct => .field,
|
.Keyword_struct => .field,
|
||||||
.Keyword_union, .Keyword_enum => .tagField,
|
.Keyword_union, .Keyword_enum => .tagField,
|
||||||
@ -188,16 +191,19 @@ fn writeContainerField(
|
|||||||
if (container_field.doc_comments) |docs| try writeDocComments(builder, builder.handle.tree, docs);
|
if (container_field.doc_comments) |docs| try writeDocComments(builder, builder.handle.tree, docs);
|
||||||
try writeToken(builder, container_field.comptime_token, .keyword);
|
try writeToken(builder, container_field.comptime_token, .keyword);
|
||||||
if (field_token_type) |tok_type| try writeToken(builder, container_field.name_token, tok_type);
|
if (field_token_type) |tok_type| try writeToken(builder, container_field.name_token, tok_type);
|
||||||
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, container_field.align_expr);
|
|
||||||
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, container_field.type_expr);
|
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, container_field.type_expr);
|
||||||
|
if (container_field.align_expr) |n| {
|
||||||
|
try writeToken(builder, n.firstToken() - 2, .keyword);
|
||||||
|
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, n);
|
||||||
|
}
|
||||||
|
|
||||||
if (container_field.value_expr) |value_expr| {
|
if (container_field.value_expr) |value_expr| block: {
|
||||||
const eq_tok: ast.TokenIndex = if (container_field.type_expr) |type_expr|
|
const eq_tok: ast.TokenIndex = if (container_field.type_expr) |type_expr|
|
||||||
type_expr.lastToken() + 1
|
type_expr.lastToken() + 1
|
||||||
else if (container_field.align_expr) |align_expr|
|
else if (container_field.align_expr) |align_expr|
|
||||||
align_expr.lastToken() + 1
|
align_expr.lastToken() + 1
|
||||||
else
|
else
|
||||||
unreachable; // Check this, I believe it is correct.
|
break :block; // Check this, I believe it is correct.
|
||||||
|
|
||||||
try writeToken(builder, eq_tok, .operator);
|
try writeToken(builder, eq_tok, .operator);
|
||||||
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, value_expr);
|
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, value_expr);
|
||||||
@ -535,10 +541,11 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D
|
|||||||
.SliceType, .PtrType => |info| {
|
.SliceType, .PtrType => |info| {
|
||||||
if (prefix_op.op == .PtrType) try writeToken(builder, prefix_op.op_token, tok_type);
|
if (prefix_op.op == .PtrType) try writeToken(builder, prefix_op.op_token, tok_type);
|
||||||
|
|
||||||
if (info.align_info) |align_info| {
|
// TODO Fix align info
|
||||||
try writeToken(builder, align_info.node.firstToken() - 2, .keyword);
|
// if (info.align_info) |align_info| {
|
||||||
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, align_info.node);
|
// try writeToken(builder, align_info.node.firstToken() - 2, .keyword);
|
||||||
}
|
// try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, align_info.node);
|
||||||
|
// }
|
||||||
try writeToken(builder, info.const_token, .keyword);
|
try writeToken(builder, info.const_token, .keyword);
|
||||||
try writeToken(builder, info.volatile_token, .keyword);
|
try writeToken(builder, info.volatile_token, .keyword);
|
||||||
try writeToken(builder, info.allowzero_token, .keyword);
|
try writeToken(builder, info.allowzero_token, .keyword);
|
||||||
@ -568,7 +575,9 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D
|
|||||||
else => null,
|
else => null,
|
||||||
} else null;
|
} else null;
|
||||||
|
|
||||||
|
var gap_highlighter = GapHighlighter.init(builder, struct_initializer.lhs.lastToken() + 1);
|
||||||
for (struct_initializer.listConst()) |field_init_node| {
|
for (struct_initializer.listConst()) |field_init_node| {
|
||||||
|
try gap_highlighter.next(field_init_node);
|
||||||
std.debug.assert(field_init_node.id == .FieldInitializer);
|
std.debug.assert(field_init_node.id == .FieldInitializer);
|
||||||
const field_init = field_init_node.cast(ast.Node.FieldInitializer).?;
|
const field_init = field_init_node.cast(ast.Node.FieldInitializer).?;
|
||||||
if (field_token_type) |tok_type| {
|
if (field_token_type) |tok_type| {
|
||||||
@ -578,15 +587,20 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D
|
|||||||
try writeToken(builder, field_init.name_token + 1, .operator);
|
try writeToken(builder, field_init.name_token + 1, .operator);
|
||||||
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, field_init.expr);
|
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, field_init.expr);
|
||||||
}
|
}
|
||||||
|
try gap_highlighter.end(struct_initializer.rtoken);
|
||||||
},
|
},
|
||||||
.StructInitializerDot => {
|
.StructInitializerDot => {
|
||||||
const struct_initializer = node.cast(ast.Node.StructInitializerDot).?;
|
const struct_initializer = node.cast(ast.Node.StructInitializerDot).?;
|
||||||
|
|
||||||
|
var gap_highlighter = GapHighlighter.init(builder, struct_initializer.dot + 1);
|
||||||
for (struct_initializer.listConst()) |field_init_node| {
|
for (struct_initializer.listConst()) |field_init_node| {
|
||||||
|
try gap_highlighter.next(field_init_node);
|
||||||
std.debug.assert(field_init_node.id == .FieldInitializer);
|
std.debug.assert(field_init_node.id == .FieldInitializer);
|
||||||
const field_init = field_init_node.cast(ast.Node.FieldInitializer).?;
|
const field_init = field_init_node.cast(ast.Node.FieldInitializer).?;
|
||||||
try writeToken(builder, field_init.name_token + 1, .operator);
|
try writeToken(builder, field_init.name_token + 1, .operator);
|
||||||
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, field_init.expr);
|
try await @asyncCall(child_frame, {}, writeNodeTokens, builder, arena, store, field_init.expr);
|
||||||
}
|
}
|
||||||
|
try gap_highlighter.end(struct_initializer.rtoken);
|
||||||
},
|
},
|
||||||
.Call => {
|
.Call => {
|
||||||
const call = node.cast(ast.Node.Call).?;
|
const call = node.cast(ast.Node.Call).?;
|
||||||
|
Loading…
Reference in New Issue
Block a user