Skip to content

Commit

Permalink
Fix highlighting for payable, immutable, receive, fallback, and enum …
Browse files Browse the repository at this point in the history
  • Loading branch information
apottere authored Sep 3, 2022
1 parent 236035a commit cd84374
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/main/kotlin/me/serce/solidity/ide/annotation/annotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class SolidityAnnotator : Annotator {
when (element) {
is SolNumberType -> applyColor(holder, element, SolColor.TYPE)
is SolElementaryTypeName -> applyColor(holder, element, SolColor.TYPE)
is SolStateMutability -> if (element.text == "payable") {
applyColor(holder, element, SolColor.KEYWORD)
}
is SolEnumValue -> applyColor(holder, element, SolColor.ENUM_VALUE)
is SolMemberAccessExpression -> when(element.expression.firstChild.text) {
"super" -> applyColor(holder, element.expression.firstChild, SolColor.KEYWORD)
"msg", "block", "abi" -> applyColor(holder, element.expression.firstChild, SolColor.GLOBAL)
Expand Down Expand Up @@ -58,7 +62,17 @@ class SolidityAnnotator : Annotator {
applyColor(holder, element.identifier, SolColor.STATE_VARIABLE)
}
}
is SolFunctionDefinition -> element.identifier?.let { applyColor(holder, it, SolColor.FUNCTION_DECLARATION) }
is SolFunctionDefinition -> {
val identifier = element.identifier
if (identifier !== null) {
applyColor(holder, identifier, SolColor.FUNCTION_DECLARATION)
} else {
val firstChildNode = element.node.firstChildNode
if (firstChildNode.text == "receive" || firstChildNode.text == "fallback") {
applyColor(holder, firstChildNode.textRange, SolColor.RECEIVE_FALLBACK_DECLARATION)
}
}
}
is SolModifierDefinition -> element.identifier?.let { applyColor(holder, it, SolColor.FUNCTION_DECLARATION) }
is SolModifierInvocation -> applyColor(holder, element.varLiteral.identifier, SolColor.FUNCTION_CALL)
is SolUserDefinedTypeName -> {
Expand All @@ -72,6 +86,7 @@ class SolidityAnnotator : Annotator {
is SolFunctionCallElement -> when(element.firstChild.text) {
"keccak256" -> applyColor(holder, element.firstChild, SolColor.GLOBAL_FUNCTION_CALL)
"require" -> applyColor(holder, element.firstChild, SolColor.KEYWORD)
"assert" -> applyColor(holder, element.firstChild, SolColor.KEYWORD)
else -> when(SolResolver.resolveTypeNameUsingImports(element).firstOrNull()) {
is SolErrorDefinition -> applyColor(holder, element.referenceNameElement, SolColor.ERROR_NAME)
is SolEventDefinition -> applyColor(holder, element.referenceNameElement, SolColor.EVENT_NAME)
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/me/serce/solidity/ide/colors/SolColor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum class SolColor(humanName: String, default: TextAttributesKey) {
ERROR_NAME("Types//Error name", Defaults.CLASS_NAME),
EVENT_NAME("Types//Event name", Defaults.CLASS_NAME),
ENUM_NAME("Types//Enum name", Defaults.CLASS_NAME),
ENUM_VALUE("Types//Enum value", Defaults.STATIC_FIELD),
TYPE("Types//Value type", Defaults.KEYWORD),
USER_DEFINED_VALUE_TYPE("Types//User-defined value type", Defaults.CLASS_NAME),

Expand All @@ -21,6 +22,7 @@ enum class SolColor(humanName: String, default: TextAttributesKey) {
STATE_VARIABLE("Identifiers//State variable", Defaults.INSTANCE_FIELD),

FUNCTION_DECLARATION("Functions//Function declaration", Defaults.FUNCTION_DECLARATION),
RECEIVE_FALLBACK_DECLARATION("Functions//Receive/Fallback declaration", Defaults.STATIC_METHOD),
FUNCTION_CALL("Functions//Function call", Defaults.FUNCTION_CALL),
GLOBAL_FUNCTION_CALL("Functions//Global function call", Defaults.GLOBAL_VARIABLE),

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/me/serce/solidity/ide/highlighter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object SolHighlighter : SyntaxHighlighterBase() {
IF, ELSE, FOR, WHILE, DO, BREAK, CONTINUE, THROW, USING, RETURN, RETURNS,
MAPPING, EVENT, /*ERROR,*/ ANONYMOUS, MODIFIER, ASSEMBLY,
VAR, STORAGE, MEMORY, WEI, ETHER, GWEI, SZABO, FINNEY, SECONDS, MINUTES, HOURS,
DAYS, WEEKS, YEARS, TYPE, VIRTUAL, OVERRIDE
DAYS, WEEKS, YEARS, TYPE, VIRTUAL, OVERRIDE, IMMUTABLE, INDEXED
)

private fun types() = setOf<IElementType>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

<TYPE>uint8</TYPE> <KEYWORD>constant</KEYWORD> <CONSTANT>MASK</CONSTANT> = 0x01;

<KEYWORD>enum</KEYWORD> <ENUM_NAME>Types</ENUM_NAME> {
<ENUM_VALUE>Type1</ENUM_VALUE>,
<ENUM_VALUE>Type2</ENUM_VALUE>
}

<KEYWORD>type</KEYWORD> <USER_DEFINED_VALUE_TYPE>Arg</USER_DEFINED_VALUE_TYPE> <KEYWORD>is</KEYWORD> <TYPE>uint256</TYPE>;

/**
* @title Claimable
* @dev Extension for the Ownable contract, where the ownership needs to be claimed.
Expand All @@ -28,6 +35,9 @@
_;
}

<RECEIVE_FALLBACK_DECLARATION>receive</RECEIVE_FALLBACK_DECLARATION>() <KEYWORD>external</KEYWORD> <KEYWORD>payable</KEYWORD> {}
<RECEIVE_FALLBACK_DECLARATION>fallback</RECEIVE_FALLBACK_DECLARATION>() <KEYWORD>external</KEYWORD> {}

<KEYWORD>function</KEYWORD> <FUNCTION_DECLARATION>transferOwnership</FUNCTION_DECLARATION>(<TYPE>address</TYPE> newOwner) <FUNCTION_CALL>onlyOwner</FUNCTION_CALL> {
pendingOwner = newOwner;
}
Expand Down

0 comments on commit cd84374

Please sign in to comment.