fix folding range on structs with doc comment on first field
This commit is contained in:
parent
5ede46f003
commit
97f7fd77c6
@ -232,7 +232,13 @@ pub fn generateFoldingRanges(allocator: std.mem.Allocator, tree: Ast, encoding:
|
|||||||
const container_decl = tree.fullContainerDecl(&buffer, node).?;
|
const container_decl = tree.fullContainerDecl(&buffer, node).?;
|
||||||
if (container_decl.ast.members.len != 0) {
|
if (container_decl.ast.members.len != 0) {
|
||||||
const first_member = container_decl.ast.members[0];
|
const first_member = container_decl.ast.members[0];
|
||||||
const start_tok = tree.firstToken(first_member) -| 1;
|
var start_tok = tree.firstToken(first_member) -| 1;
|
||||||
|
while (start_tok != 0 and
|
||||||
|
(token_tags[start_tok] == .doc_comment or
|
||||||
|
token_tags[start_tok] == .container_doc_comment))
|
||||||
|
{
|
||||||
|
start_tok -= 1;
|
||||||
|
}
|
||||||
const end_tok = ast.lastToken(tree, node);
|
const end_tok = ast.lastToken(tree, node);
|
||||||
try builder.add(null, start_tok, end_tok, .exclusive, .exclusive);
|
try builder.add(null, start_tok, end_tok, .exclusive, .exclusive);
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,15 @@ test "foldingRange - container decl" {
|
|||||||
, &.{
|
, &.{
|
||||||
.{ .startLine = 0, .startCharacter = 20, .endLine = 3, .endCharacter = 0 },
|
.{ .startLine = 0, .startCharacter = 20, .endLine = 3, .endCharacter = 0 },
|
||||||
});
|
});
|
||||||
|
try testFoldingRange(
|
||||||
|
\\const Foo = struct {
|
||||||
|
\\ /// doc comment
|
||||||
|
\\ alpha: u32,
|
||||||
|
\\ beta: []const u8,
|
||||||
|
\\};
|
||||||
|
, &.{
|
||||||
|
.{ .startLine = 0, .startCharacter = 20, .endLine = 4, .endCharacter = 0 },
|
||||||
|
});
|
||||||
try testFoldingRange(
|
try testFoldingRange(
|
||||||
\\const Foo = packed struct(u32) {
|
\\const Foo = packed struct(u32) {
|
||||||
\\ alpha: u16,
|
\\ alpha: u16,
|
||||||
|
Loading…
Reference in New Issue
Block a user