From acb342cacc822bf9813429c71781abf348fe7cb6 Mon Sep 17 00:00:00 2001 From: sam bacha Date: Sat, 6 Jul 2024 03:50:11 -0700 Subject: [PATCH] feat(solidity): add support for custom types --- syntaxes/solidity.tmLanguage.json | 175 ++++++++++++++++++++---------- 1 file changed, 116 insertions(+), 59 deletions(-) diff --git a/syntaxes/solidity.tmLanguage.json b/syntaxes/solidity.tmLanguage.json index 59f62f0..17da007 100644 --- a/syntaxes/solidity.tmLanguage.json +++ b/syntaxes/solidity.tmLanguage.json @@ -3,11 +3,13 @@ "sol" ], "name": "Solidity", - "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", "patterns": [ { "include": "#natspec" }, + { + "include": "#declaration-userType" + }, { "include": "#comment" }, @@ -29,6 +31,9 @@ { "include": "#type-primitive" }, + { + "include": "#type-user" + }, { "include": "#type-modifier-extended-scope" }, @@ -72,9 +77,6 @@ }, "natspec-tags": { "patterns": [ - { - "include": "#comment-todo" - }, { "include": "#natspec-tag-title" }, @@ -87,6 +89,9 @@ { "include": "#natspec-tag-dev" }, + { + "include": "#natspec-tag-inheritdoc" + }, { "include": "#natspec-tag-param" }, @@ -114,9 +119,9 @@ "match": "(@dev)\\b", "name": "storage.type.dev.natspec" }, - "natspec-tag-custom": { - "match": "(@custom:)\\b", - "name": "storage.type.custom.natspec" + "natspec-tag-inheritdoc": { + "match": "(@inheritdoc)\\b", + "name": "storage.type.dev.natspec" }, "natspec-tag-param": { "match": "(@param)(\\s+([A-Za-z_]\\w*))?\\b", @@ -130,7 +135,7 @@ } }, "natspec-tag-return": { - "match": "(@return)(\\s+([A-Za-z_]\\w*))?\\b", + "match": "(@return)(\\s+(_?[a-z]\\w*))?\\b", "captures": { "1": { "name": "storage.type.return.natspec" @@ -140,6 +145,10 @@ } } }, + "natspec-tag-custom": { + "match": "(@custom:[a-z]+(-[a-z]+)*)\\b", + "name": "storage.type.custom.natspec" + }, "comment": { "patterns": [ { @@ -150,29 +159,15 @@ } ] }, - "comment-todo": { - "match": "(?i)\\b(FIXME|TODO|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|SUPPRESS|LINT|\\w+-disable|\\w+-suppress)\\b(?-i)", - "name": "keyword.comment.todo" - }, "comment-line": { "begin": "(?(?!>)|>=|\\&\\&|\\|\\||\\:(?!=)|\\?|\\!)", + "match": "(!|==|!=|<(?!<)|<=|>(?!>)|>=|\\&\\&|\\|\\||\\:(?!=)|\\?)", "name": "keyword.operator.logic" }, "operator-mapping": { @@ -202,7 +197,7 @@ "name": "keyword.operator.mapping" }, "operator-arithmetic": { - "match": "(\\+|\\-|\\/|\\*)", + "match": "(\\+|\\-|\\/|\\%|\\*)", "name": "keyword.operator.arithmetic" }, "operator-binary": { @@ -360,9 +355,6 @@ }, { "include": "#constant-currency" - }, - { - "include": "#constant-ucase" } ] }, @@ -375,13 +367,9 @@ "name": "constant.language.time" }, "constant-currency": { - "match": "\\b(ether|wei|gwei|nanoeth|finney|szabo)\\b", + "match": "\\b(ether|wei|finney|szabo)\\b", "name": "constant.language.currency" }, - "constant-ucase": { - "match": "\\b((?=\\D)[A-Z_0-9]+)\\b", - "name": "constant.language.ucase.solidity" - }, "number": { "patterns": [ { @@ -466,6 +454,37 @@ } ] }, + "type-user": { + "patterns": [ + { + "begin": "\\b([A-Z]\\w*)\\b(?:\\[\\])(\\()", + "beginCaptures": { + "1": { + "name": "entity.name.type" + } + }, + "end": "(\\))", + "patterns": [ + { + "include": "#primitive" + }, + { + "include": "#punctuation" + }, + { + "include": "#global" + }, + { + "include": "#variable" + } + ] + }, + { + "match": "\\b([A-Z]\\w*)\\b", + "name": "entity.name.type" + } + ] + }, "global": { "patterns": [ { @@ -592,6 +611,9 @@ { "include": "#declaration-contract" }, + { + "include": "#declaration-userType" + }, { "include": "#declaration-interface" }, @@ -629,12 +651,18 @@ { "include": "#type-primitive" }, + { + "include": "#type-user" + }, { "include": "#type-modifier-access" }, { "include": "#type-modifier-immutable" }, + { + "include": "#type-modifier-extend-scope" + }, { "include": "#type-modifier-payable" }, @@ -673,6 +701,17 @@ }, "declaration-contract": { "patterns": [ + { + "match": "\\b(contract)\\b\\s+(\\w+)\\b\\s*(?=\\{)", + "captures": { + "1": { + "name": "storage.type.contract" + }, + "2": { + "name": "entity.name.type.contract" + } + } + }, { "begin": "\\b(contract)\\b\\s+(\\w+)\\b\\s+\\b(is)\\b\\s+", "end": "(?=\\{)", @@ -693,22 +732,36 @@ "name": "entity.name.type.contract.extend" } ] + } + ] + }, + "declaration-userType": { + "match": "\\b(type)\\b\\s+(\\w+)\\b\\s+\\b(is)\\b", + "captures": { + "1": { + "name": "storage.type.userType" + }, + "2": { + "name": "entity.name.type.userType" }, + "3": { + "name": "storage.modifier.is" + } + } + }, + "declaration-interface": { + "patterns": [ { - "match": "\\b(contract)(\\s+([A-Za-z_]\\w*))?\\b", + "match": "\\b(interface)\\b\\s+(\\w+)\\b\\s*(?=\\{)", "captures": { "1": { - "name": "storage.type.contract" + "name": "storage.type.interface" }, "2": { - "name": "entity.name.type.contract" + "name": "entity.name.type.interface" } } - } - ] - }, - "declaration-interface": { - "patterns": [ + }, { "begin": "\\b(interface)\\b\\s+(\\w+)\\b\\s+\\b(is)\\b\\s+", "end": "(?=\\{)", @@ -727,19 +780,11 @@ { "match": "\\b(\\w+)\\b", "name": "entity.name.type.interface.extend" - } - ] - }, - { - "match": "\\b(interface)(\\s+([A-Za-z_]\\w*))?\\b", - "captures": { - "1": { - "name": "storage.type.interface" }, - "2": { - "name": "entity.name.type.interface" + { + "include": "#comment" } - } + ] } ] }, @@ -782,6 +827,9 @@ { "include": "#type-primitive" }, + { + "include": "#type-user" + }, { "include": "#variable" }, @@ -812,6 +860,9 @@ { "include": "#type-primitive" }, + { + "include": "#type-user" + }, { "match": "\\b(?:(indexed)\\s)?(\\w+)(?:,\\s*|)", "captures": { @@ -905,6 +956,9 @@ }, { "include": "#punctuation" + }, + { + "include": "#comment" } ] }, @@ -928,6 +982,9 @@ { "include": "#type-primitive" }, + { + "include": "#type-user" + }, { "include": "#type-modifier-extended-scope" }, @@ -995,7 +1052,7 @@ "include": "#modifier-call" }, { - "include": "#punctuation" + "include": "#comment" } ] }, @@ -1091,6 +1148,9 @@ { "include": "#type-primitive" }, + { + "include": "#type-user" + }, { "include": "#punctuation" }, @@ -1117,13 +1177,10 @@ } }, "function-call": { - "match": "\\b([A-Za-z_]\\w*)\\s*(\\()", + "match": "\\b([A-Za-z_]\\w*)\\s*\\(", "captures": { "1": { "name": "entity.name.function" - }, - "2": { - "name": "punctuation.parameters.begin" } } }, @@ -1181,5 +1238,5 @@ } }, "scopeName": "source.solidity", - "uuid": "18e064f3-32b1-44de-ac9e-10f0607d7b84" + "uuid": "4a2eb52d-02e5-46fd-848a-0648e20ef769" }