fix folding range on structs with doc comment on first field

This commit is contained in:
Techarix 2023-02-25 01:30:47 +01:00 committed by Lee Cannon
parent 5ede46f003
commit 97f7fd77c6
2 changed files with 16 additions and 1 deletions

View File

@ -232,7 +232,13 @@ pub fn generateFoldingRanges(allocator: std.mem.Allocator, tree: Ast, encoding:
const container_decl = tree.fullContainerDecl(&buffer, node).?;
if (container_decl.ast.members.len != 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);
try builder.add(null, start_tok, end_tok, .exclusive, .exclusive);
}

View File

@ -151,6 +151,15 @@ test "foldingRange - container decl" {
, &.{
.{ .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(
\\const Foo = packed struct(u32) {
\\ alpha: u16,