File tree Expand file tree Collapse file tree
src/slang-comments/handlers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { NonterminalKind } from '@nomicfoundation/slang/cst' ;
2+ import { util } from 'prettier' ;
3+ import { locEnd } from '../../slang-utils/loc.js' ;
4+ import addCollectionNodeFirstComment from './add-collection-node-first-comment.js' ;
5+ import addCollectionNodeLastComment from './add-collection-node-last-comment.js' ;
6+
7+ import type { HandlerParams } from './types.d.ts' ;
8+
9+ export default function handleStructComments ( {
10+ text,
11+ precedingNode,
12+ enclosingNode,
13+ followingNode,
14+ comment
15+ } : HandlerParams ) : boolean {
16+ if ( enclosingNode ?. kind !== NonterminalKind . StructDefinition ) {
17+ return false ;
18+ }
19+
20+ const nextCharacter = util . getNextNonSpaceNonCommentCharacter (
21+ text ,
22+ locEnd ( comment )
23+ ) ;
24+
25+ if (
26+ precedingNode ?. kind === NonterminalKind . StructMembers &&
27+ nextCharacter === '}'
28+ ) {
29+ addCollectionNodeLastComment ( precedingNode , comment ) ;
30+ return true ;
31+ }
32+
33+ if ( followingNode ?. kind === NonterminalKind . StructMembers ) {
34+ addCollectionNodeFirstComment ( followingNode , comment ) ;
35+ return true ;
36+ }
37+
38+ return false ;
39+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import handleModifierInvocationComments from './handle-modifier-invocation-comme
99import handleParametersDeclarationComments from './handle-parameters-declaration-comments.js' ;
1010import handlePositionalArgumentsDeclarationComments from './handle-positional-arguments-declaration-comments.js' ;
1111import handleStorageLayoutSpecifierComments from './handle-storage-layout-specifier-comments.js' ;
12+ import handleStructComments from './handle-struct-comments.js' ;
1213import handleWhileStatementComments from './handle-while-statement-comments.js' ;
1314import handleYulBlockComments from './handle-yul-block-comments.js' ;
1415
@@ -24,6 +25,7 @@ export default [
2425 handleParametersDeclarationComments ,
2526 handlePositionalArgumentsDeclarationComments ,
2627 handleStorageLayoutSpecifierComments ,
28+ handleStructComments ,
2729 handleWhileStatementComments ,
2830 handleYulBlockComments
2931] ;
Original file line number Diff line number Diff line change @@ -392,12 +392,13 @@ contract Comments13 {
392392}
393393
394394contract Comments14 {
395- struct AssetStore { // use 0 for non-EVM chains
395+ struct AssetStore {
396+ // use 0 for non-EVM chains
396397 uint chainId;
397398 uint assetStoreIndex;
398399 string assetStoreAddress; // we assume all addresses are strings and the front-end will cast correctly
400+ // string shortName; // usually an asset shortName \`eth:\` or \`st:\` for a stealth address
399401 }
400- // string shortName; // usually an asset shortName \`eth:\` or \`st:\` for a stealth address
401402}
402403
403404================================================================================
You can’t perform that action at this time.
0 commit comments