Skip to content

Commit e7dc1cb

Browse files
committed
fix document symbols on invalid top level container field
1 parent 25e5663 commit e7dc1cb

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/features/document_symbol.zig

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,18 @@ fn callback(ctx: *Context, tree: Ast, node: Ast.Node.Index) error{OutOfMemory}!v
112112
.container_field_align,
113113
.container_field,
114114
=> blk: {
115-
const container_kind = tree.tokenTag(tree.nodeMainToken(ctx.parent_container));
116-
const is_struct = container_kind == .keyword_struct;
117-
118-
const kind: types.SymbolKind = switch (tree.nodeTag(ctx.parent_container)) {
119-
.root => .Field,
115+
const kind: types.SymbolKind, const is_struct = switch (tree.nodeTag(ctx.parent_container)) {
116+
.root => .{ .Field, true },
120117
.container_decl,
121118
.container_decl_trailing,
122119
.container_decl_arg,
123120
.container_decl_arg_trailing,
124121
.container_decl_two,
125122
.container_decl_two_trailing,
126-
=> switch (container_kind) {
127-
.keyword_struct => .Field,
128-
.keyword_union => .Field,
129-
.keyword_enum => .EnumMember,
123+
=> switch (tree.tokenTag(tree.nodeMainToken(ctx.parent_container))) {
124+
.keyword_struct => .{ .Field, true },
125+
.keyword_union => .{ .Field, false },
126+
.keyword_enum => .{ .EnumMember, false },
130127
.keyword_opaque => break :blk null,
131128
else => unreachable,
132129
},
@@ -136,7 +133,7 @@ fn callback(ctx: *Context, tree: Ast, node: Ast.Node.Index) error{OutOfMemory}!v
136133
.tagged_union_enum_tag_trailing,
137134
.tagged_union_two,
138135
.tagged_union_two_trailing,
139-
=> .Field,
136+
=> .{ .Field, false },
140137
else => unreachable,
141138
};
142139

tests/lsp_features/document_symbol.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ test "test decl" {
6363
);
6464
}
6565

66+
test "root container field" {
67+
try testDocumentSymbol(
68+
\\foo: u32,
69+
,
70+
\\Field foo
71+
);
72+
}
73+
6674
// https://github.com/zigtools/zls/issues/1583
6775
test "builtin" {
6876
try testDocumentSymbol(
@@ -93,6 +101,14 @@ test "nested struct with self" {
93101
);
94102
}
95103

104+
test "invalid top level enum literal" {
105+
try testDocumentSymbol(
106+
\\.foo: u32,
107+
,
108+
\\
109+
);
110+
}
111+
96112
test "decl names that are empty or contain whitespace return non-empty document symbol" {
97113
try testDocumentSymbol(
98114
\\test "" {}

0 commit comments

Comments
 (0)