-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathhandle-struct-comments.ts
More file actions
39 lines (33 loc) · 1.02 KB
/
handle-struct-comments.ts
File metadata and controls
39 lines (33 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { util } from 'prettier';
import { locEnd } from '../../slang-utils/loc.js';
import addCollectionNodeFirstComment from './add-collection-node-first-comment.js';
import addCollectionNodeLastComment from './add-collection-node-last-comment.js';
import type { HandlerParams } from './types.d.ts';
export default function handleStructComments({
text,
precedingNode,
enclosingNode,
followingNode,
comment
}: HandlerParams): boolean {
if (enclosingNode?.kind !== NonterminalKind.StructDefinition) {
return false;
}
const nextCharacter = util.getNextNonSpaceNonCommentCharacter(
text,
locEnd(comment)
);
if (
precedingNode?.kind === NonterminalKind.StructMembers &&
nextCharacter === '}'
) {
addCollectionNodeLastComment(precedingNode, comment);
return true;
}
if (followingNode?.kind === NonterminalKind.StructMembers) {
addCollectionNodeFirstComment(followingNode, comment);
return true;
}
return false;
}