From b62332150e2f97d0fab68f4cdf5aebd17e994ffa Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Wed, 8 Nov 2023 22:43:23 -0800 Subject: [PATCH] Add textmate definition for kotlin dsl (#3377) Signed-off-by: Sheng Chen --- .../kotlin/kotlin.tmLanguage.json | 571 ++++++++++++++++++ .../kotlin/language-configuration.json | 27 + package.json | 15 + 3 files changed, 613 insertions(+) create mode 100644 language-support/kotlin/kotlin.tmLanguage.json create mode 100644 language-support/kotlin/language-configuration.json diff --git a/language-support/kotlin/kotlin.tmLanguage.json b/language-support/kotlin/kotlin.tmLanguage.json new file mode 100644 index 000000000..eaa053b90 --- /dev/null +++ b/language-support/kotlin/kotlin.tmLanguage.json @@ -0,0 +1,571 @@ +{ + "information_for_contributors": [ + "This file has been copied from https://github.com/eclipse/buildship/blob/b848d9a08283b68860671a73ceec3c99bdab27c2/org.eclipse.buildship.kotlindsl.provider/kotlin.tmLanguage.json" + ], + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "Kotlin", + "scopeName": "source.kotlin", + "patterns": [ + { + "include": "#import" + }, + { + "include": "#package" + }, + { + "include": "#code" + } + ], + "fileTypes": [ + "kts" + ], + "repository": { + "import": { + "begin": "\\b(import)\\b\\s*", + "beginCaptures": { + "1": { + "name": "storage.type.import.kotlin" + } + }, + "end": ";|$", + "name": "meta.import.kotlin", + "contentName": "entity.name.package.kotlin", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#hard-keywords" + }, + { + "match": "\\*", + "name": "variable.language.wildcard.kotlin" + } + ] + }, + "package": { + "begin": "\\b(package)\\b\\s*", + "beginCaptures": { + "1": { + "name": "storage.type.package.kotlin" + } + }, + "end": ";|$", + "name": "meta.package.kotlin", + "contentName": "entity.name.package.kotlin", + "patterns": [ + { + "include": "#comments" + } + ] + }, + "code": { + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#keywords" + }, + { + "include": "#annotation-simple" + }, + { + "include": "#annotation-site-list" + }, + { + "include": "#annotation-site" + }, + { + "include": "#class-declaration" + }, + { + "include": "#object-declaration" + }, + { + "include": "#type-alias" + }, + { + "include": "#function-declaration" + }, + { + "include": "#variable-declaration" + }, + { + "include": "#type-constraint" + }, + { + "include": "#type-annotation" + }, + { + "include": "#function-call" + }, + { + "include": "#method-reference" + }, + { + "include": "#key" + }, + { + "include": "#string" + }, + { + "include": "#string-empty" + }, + { + "include": "#string-multiline" + }, + { + "include": "#character" + }, + { + "include": "#lambda-arrow" + }, + { + "include": "#operators" + }, + { + "include": "#self-reference" + }, + { + "include": "#decimal-literal" + }, + { + "include": "#hex-literal" + }, + { + "include": "#binary-literal" + }, + { + "include": "#boolean-literal" + }, + { + "include": "#null-literal" + } + ] + }, + "comments": { + "patterns": [ + { + "include": "#comment-line" + }, + { + "include": "#comment-block" + }, + { + "include": "#comment-javadoc" + } + ] + }, + "comment-line": { + "begin": "//", + "end": "$", + "name": "comment.line.double-slash.kotlin" + }, + "comment-block": { + "begin": "/\\*(?!\\*)", + "end": "\\*/", + "name": "comment.block.kotlin" + }, + "comment-javadoc": { + "patterns": [ + { + "begin": "/\\*\\*", + "end": "\\*/", + "name": "comment.block.javadoc.kotlin", + "patterns": [ + { + "match": "@(author|deprecated|return|see|serial|since|version)\\b", + "name": "keyword.other.documentation.javadoc.kotlin" + }, + { + "match": "(@param)\\s+(\\S+)", + "captures": { + "1": { + "name": "keyword.other.documentation.javadoc.kotlin" + }, + "2": { + "name": "variable.parameter.kotlin" + } + } + }, + { + "match": "(@(?:exception|throws))\\s+(\\S+)", + "captures": { + "1": { + "name": "keyword.other.documentation.javadoc.kotlin" + }, + "2": { + "name": "entity.name.type.class.kotlin" + } + } + }, + { + "match": "{(@link)\\s+(\\S+)?#([\\w$]+\\s*\\([^\\(\\)]*\\)).*}", + "captures": { + "1": { + "name": "keyword.other.documentation.javadoc.kotlin" + }, + "2": { + "name": "entity.name.type.class.kotlin" + }, + "3": { + "name": "variable.parameter.kotlin" + } + } + } + ] + } + ] + }, + "keywords": { + "patterns": [ + { + "include": "#prefix-modifiers" + }, + { + "include": "#postfix-modifiers" + }, + { + "include": "#soft-keywords" + }, + { + "include": "#hard-keywords" + }, + { + "include": "#control-keywords" + } + ] + }, + "prefix-modifiers": { + "match": "\\b(abstract|final|enum|open|annotation|sealed|data|override|final|lateinit|private|protected|public|internal|inner|companion|noinline|crossinline|vararg|reified|tailrec|operator|infix|inline|external|const|suspend|value)\\b", + "name": "storage.modifier.other.kotlin" + }, + "postfix-modifiers": { + "match": "\\b(where|by|get|set)\\b", + "name": "storage.modifier.other.kotlin" + }, + "soft-keywords": { + "match": "\\b(catch|finally|field)\\b", + "name": "keyword.soft.kotlin" + }, + "hard-keywords": { + "match": "\\b(as|typeof|is|in)\\b", + "name": "keyword.hard.kotlin" + }, + "control-keywords": { + "match": "\\b(if|else|while|do|when|try|throw|break|continue|return|for)\\b", + "name": "keyword.control.kotlin" + }, + "annotation-simple": { + "match": "(?<([^<>]|\\g)+>)?", + "captures": { + "1": { + "name": "storage.type.class.kotlin" + }, + "2": { + "name": "entity.name.type.class.kotlin" + }, + "3": { + "patterns": [ + { + "include": "#type-parameter" + } + ] + } + } + }, + "object-declaration": { + "match": "\\b(object)\\s+(\\b\\w+\\b|`[^`]+`)", + "captures": { + "1": { + "name": "storage.type.object.kotlin" + }, + "2": { + "name": "entity.name.type.object.kotlin" + } + } + }, + "type-alias": { + "match": "\\b(typealias)\\s+(\\b\\w+\\b|`[^`]+`)\\s*(?<([^<>]|\\g)+>)?", + "captures": { + "1": { + "name": "storage.type.alias.kotlin" + }, + "2": { + "name": "entity.name.type.kotlin" + }, + "3": { + "patterns": [ + { + "include": "#type-parameter" + } + ] + } + } + }, + "function-declaration": { + "match": "\\b(fun)\\b\\s*(?<([^<>]|\\g)+>)?\\s*(?:(\\w+)\\.)?(\\b\\w+\\b|`[^`]+`)", + "captures": { + "1": { + "name": "storage.type.function.kotlin" + }, + "2": { + "patterns": [ + { + "include": "#type-parameter" + } + ] + }, + "4": { + "name": "entity.name.type.class.extension.kotlin" + }, + "5": { + "name": "entity.name.function.declaration.kotlin" + } + } + }, + "variable-declaration": { + "match": "\\b(val|var)\\b\\s*(?<([^<>]|\\g)+>)?", + "captures": { + "1": { + "name": "storage.type.variable.kotlin" + }, + "2": { + "patterns": [ + { + "include": "#type-parameter" + } + ] + } + } + }, + "type-parameter": { + "patterns": [ + { + "match": "\\b\\w+\\b", + "name": "entity.name.type.kotlin" + }, + { + "match": "\\b(in|out)\\b", + "name": "storage.modifier.kotlin" + } + ] + }, + "type-annotation": { + "match": "(?|(?[<(]([^<>()\"']|\\g)+[)>]))+", + "captures": { + "0": { + "patterns": [ + { + "include": "#type-parameter" + } + ] + } + } + }, + "function-call": { + "match": "\\??\\.?(\\b\\w+\\b|`[^`]+`)\\s*(?<([^<>]|\\g)+>)?\\s*(?=[({])", + "captures": { + "1": { + "name": "entity.name.function.call.kotlin" + }, + "2": { + "patterns": [ + { + "include": "#type-parameter" + } + ] + } + } + }, + "method-reference": { + "match": "\\??::(\\b\\w+\\b|`[^`]+`)", + "captures": { + "1": { + "name": "entity.name.function.reference.kotlin" + } + } + }, + "key": { + "match": "\\b(\\w=)\\s*(=)", + "captures": { + "1": { + "name": "variable.parameter.kotlin" + }, + "2": { + "name": "keyword.operator.assignment.kotlin" + } + } + }, + "string-empty": { + "match": "(?", + "name": "storage.type.function.arrow.kotlin" + }, + "operators": { + "patterns": [ + { + "match": "(===?|\\!==?|<=|>=|<|>)", + "name": "keyword.operator.comparison.kotlin" + }, + { + "match": "([+*/%-]=)", + "name": "keyword.operator.assignment.arithmetic.kotlin" + }, + { + "match": "(=)", + "name": "keyword.operator.assignment.kotlin" + }, + { + "match": "([+*/%-])", + "name": "keyword.operator.arithmetic.kotlin" + }, + { + "match": "(!|&&|\\|\\|)", + "name": "keyword.operator.logical.kotlin" + }, + { + "match": "(--|\\+\\+)", + "name": "keyword.operator.increment-decrement.kotlin" + }, + { + "match": "(\\.\\.)", + "name": "keyword.operator.range.kotlin" + } + ] + }, + "self-reference": { + "match": "\\b(this|super)(@\\w+)?\\b", + "name": "variable.language.this.kotlin" + } + } +} \ No newline at end of file diff --git a/language-support/kotlin/language-configuration.json b/language-support/kotlin/language-configuration.json new file mode 100644 index 000000000..56225afa7 --- /dev/null +++ b/language-support/kotlin/language-configuration.json @@ -0,0 +1,27 @@ +{ + "comments": { + "lineComment": "//", + "blockComment": [ "/*", "*/" ] + }, + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + "autoClosingPairs": [ + { "open": "{", "close": "}" }, + { "open": "[", "close": "]" }, + { "open": "(", "close": ")" }, + { "open": "'", "close": "'", "notIn": ["string", "comment"] }, + { "open": "\"", "close": "\"", "notIn": ["string"] }, + { "open": "/*", "close": " */", "notIn": ["string"] } + ], + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["<", ">"], + ["'", "'"], + ["\"", "\""] + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 644628726..5344efd10 100644 --- a/package.json +++ b/package.json @@ -174,6 +174,16 @@ ".properties" ], "configuration": "./language-support/properties/java-properties-configuration.json" + }, + { + "id": "gradle-kotlin-dsl", + "aliases": [ + "Gradle Kotlin DSL" + ], + "extensions": [ + ".gradle.kts" + ], + "configuration": "./language-support/kotlin/language-configuration.json" } ], "grammars": [ @@ -186,6 +196,11 @@ "language": "java-properties", "scopeName": "source.java-properties", "path": "./language-support/properties/JavaProperties.tmLanguage.json" + }, + { + "language": "gradle-kotlin-dsl", + "scopeName": "source.kotlin", + "path": "./language-support/kotlin/kotlin.tmLanguage.json" } ], "jsonValidation": [