Skip to content

Commit

Permalink
add support for documentation of global variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Vsevo1od committed Dec 2, 2021
1 parent ef47ca5 commit 33ef1fc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/solc-output-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class SolcOutputBuilder implements SolcOutput {
nodeType: 'VariableDeclaration',
visibility: 'public',
name: variableName,
documentation: null,
constant: false,
typeName: {
nodeType: 'ElementaryTypeName',
Expand Down
1 change: 1 addition & 0 deletions src/solc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export namespace ast {
nodeType: 'VariableDeclaration';
visibility: 'internal' | 'public' | 'private';
name: string;
documentation: string | null;
constant: boolean;
typeName: TypeName;
}
Expand Down
18 changes: 11 additions & 7 deletions src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,13 @@ class SourceStateVariable implements Linkable {
return `${this.type} ${this.name}`;
}

get natspec(): {} {
warnStateVariableNatspec();
return {}
@memoize
get natspec(): NatSpec {
if (this.astNode.documentation === null || this.astNode.documentation === undefined) {
return {};
}

return parseNatSpec(this.astNode.documentation, this);
}
}

Expand Down Expand Up @@ -452,7 +456,7 @@ class SourceStruct extends SourceContractItem {
}

get natspec(): {} {
warnStateVariableNatspec();
warnNatSpecIsNotAvailable();
return {}
}
}
Expand All @@ -471,7 +475,7 @@ class SourceEnum extends SourceContractItem {
}

get natspec(): {} {
warnStateVariableNatspec();
warnNatSpecIsNotAvailable();
return {}
}
}
Expand Down Expand Up @@ -554,7 +558,7 @@ interface NatSpec {
};
}

function parseNatSpec(doc: string, context: SourceFunctionLike | SourceContract): NatSpec {
function parseNatSpec(doc: string, context: SourceFunctionLike | SourceContract | SourceStateVariable): NatSpec {
const res: NatSpec = {};

const tagMatches = execall(/^(?:@(\w+|custom:[a-z][a-z-]*) )?((?:(?!^@(?:\w+|custom:[a-z][a-z-]*) )[^])*)/m, doc);
Expand Down Expand Up @@ -675,4 +679,4 @@ function oneTimeLogger(msg: string): () => void {
};
}

const warnStateVariableNatspec = oneTimeLogger('Warning: NatSpec is currently not available for state variables, structs, or enums.');
const warnNatSpecIsNotAvailable = oneTimeLogger('Warning: NatSpec is currently not available for structs and enums.');

0 comments on commit 33ef1fc

Please sign in to comment.