From 3b591641b3bbfe26ccbf7c23e2a64e2cd33425fa Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Sun, 8 Dec 2024 15:01:12 +0200 Subject: [PATCH] [Groovy] use more specific sub-scopes for keywords (#4051) Co-authored-by: Keith Hall --- Groovy/Groovy.sublime-syntax | 57 ++++++++++++++------ Groovy/tests/syntax_test_Strings.groovy | 6 +-- Groovy/tests/syntax_test_jenkins.Jenkinsfile | 30 +++++++++++ 3 files changed, 73 insertions(+), 20 deletions(-) diff --git a/Groovy/Groovy.sublime-syntax b/Groovy/Groovy.sublime-syntax index f4c1a17ad1..74c273cf9a 100644 --- a/Groovy/Groovy.sublime-syntax +++ b/Groovy/Groovy.sublime-syntax @@ -147,23 +147,46 @@ contexts: - include: keyword-operator - include: keyword-language keyword-language: - - match: \b(try|catch|finally|throw)\b - scope: keyword.control.exception.groovy - - match: \b(return|break|continue|default|do|while|for|switch|if|else)\b - scope: keyword.control.groovy + - match: \bthrow\b + scope: keyword.control.flow.throw.groovy + - match: \btry\b + scope: keyword.control.exception.try.groovy + - match: \bfinally\b + scope: keyword.control.exception.finally.groovy + - match: \bcatch\b + scope: keyword.control.exception.catch.groovy + - match: \bdefault\b + scope: keyword.control.conditional.groovy + - match: \bfor\b + scope: keyword.control.loop.for.groovy + - match: \bwhile\b + scope: keyword.control.loop.while.groovy + - match: \bdo\b + scope: keyword.control.loop.do-while.groovy + - match: \breturn\b + scope: keyword.control.flow.return.groovy + - match: \bbreak\b + scope: keyword.control.flow.break.groovy + - match: \bcontinue\b + scope: keyword.control.flow.continue.groovy + - match: \bif\b + scope: keyword.control.conditional.if.groovy + - match: \belse\b + scope: keyword.control.conditional.else.groovy + - match: \bswitch\b + scope: keyword.control.conditional.switch.groovy - match: \bcase\b - scope: keyword.control.groovy + scope: keyword.control.conditional.case.groovy push: - meta_scope: meta.case.groovy - match: ":" scope: punctuation.definition.case-terminator.groovy pop: true - include: groovy-code-minus-map-keys - - match: \b(new)\b - scope: keyword.other.new.groovy - - match: \b(assert)\s - captures: - 1: keyword.control.assert.groovy + - match: \bnew\b + scope: keyword.operator.new.groovy + - match: \bassert\b + scope: keyword.control.exception.assert.groovy push: - meta_scope: meta.declaration.assertion.groovy - match: $|(?=\}) @@ -171,13 +194,13 @@ contexts: - match: ":" scope: keyword.operator.assert.expression-separator.groovy - include: groovy-code-minus-map-keys - - match: \b(throws)\b - scope: keyword.other.throws.groovy + - match: \bthrows\b + scope: keyword.control.exception.groovy keyword-operator: - - match: \b(as)\b + - match: \bas\b scope: keyword.operator.as.groovy - - match: \b(is)\b - scope: keyword.operator.is.groovy + - match: \bis\b + scope: keyword.operator.reflection.groovy - match: '\?\:' scope: keyword.operator.elvis.groovy - match: \.\. @@ -185,11 +208,11 @@ contexts: - match: \-> scope: keyword.operator.arrow.groovy - match: "<<" - scope: keyword.operator.leftshift.groovy + scope: keyword.operator.bitwise.groovy - match: (?<=\S)\.(?=\S) scope: punctuation.accessor.dot.groovy - match: (?<=\S)\?\.(?=\S) - scope: punctuation.accessor.groovy + scope: punctuation.accessor.null-coalescing.groovy - match: \? scope: keyword.operator.ternary.groovy push: diff --git a/Groovy/tests/syntax_test_Strings.groovy b/Groovy/tests/syntax_test_Strings.groovy index 51251f3612..44fed6ea09 100644 --- a/Groovy/tests/syntax_test_Strings.groovy +++ b/Groovy/tests/syntax_test_Strings.groovy @@ -110,10 +110,10 @@ interpolation6 = "The sum of 1 and 2 is equal to ${def a = 1; a + 2}" interpolation7 = "foo { ${if (x) { y } else { z } } }" // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.groovy // ^ - punctuation -// ^^ keyword.control.groovy +// ^^ keyword.control.conditional.if.groovy // ^ punctuation.section.block.begin.groovy // ^ punctuation.section.block.end.groovy - punctuation.section.interpolation -// ^^^^ keyword.control.groovy +// ^^^^ keyword.control.conditional.else.groovy // ^ punctuation.section.block.begin.groovy // ^ punctuation.section.block.end.groovy - punctuation.section.interpolation // ^ punctuation.section.interpolation.end.groovy @@ -256,7 +256,7 @@ dollarSlashy01 = $/Hello $person.name/$ dollarSlashy02 = $/today is ${new Date().format( 'yyyy-MM-dd' )}./$ // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.groovy.embedded.source // ^^ punctuation.section.interpolation.begin.groovy -// ^^^ keyword.other.new.groovy +// ^^^ keyword.operator.new.groovy // ^^^^^^^^^^^^^^^^^^^^^^ meta.function-call // ^^ string.quoted.other.dollar-slashy.groovy punctuation.definition.string.end.groovy diff --git a/Groovy/tests/syntax_test_jenkins.Jenkinsfile b/Groovy/tests/syntax_test_jenkins.Jenkinsfile index 1b7e51d494..d77bedced8 100644 --- a/Groovy/tests/syntax_test_jenkins.Jenkinsfile +++ b/Groovy/tests/syntax_test_jenkins.Jenkinsfile @@ -84,3 +84,33 @@ int something = sh(returnStdout: true, script: '''#!/bin/bash echo 7 ''') // TODO: highlight bash above + +node('some-node-name') { + try { + // <- meta.block.groovy keyword.control.exception.try.groovy + // ^ punctuation.section.block.begin.groovy + lock(lockName) { + + } + } catch (InterruptedException e) { + // <- punctuation.section.block.end.groovy + //^^^^^ keyword.control.exception.catch.groovy + // ^ punctuation.section.group.begin.groovy + // ^^^^^^^^^^^^^^^^^^^^ storage.type.class.groovy + // ^ variable.other.readwrite.groovy + // ^ punctuation.section.group.end.groovy + // ^ punctuation.section.block.begin.groovy + if (isDeployment) { + // <- meta.block.groovy meta.block.groovy keyword.control.conditional.if.groovy + // ^ meta.block.groovy meta.block.groovy meta.group.groovy punctuation.section.group.begin.groovy + // ^^^^^^^^^^^^ meta.block.groovy meta.block.groovy meta.group.groovy variable.other.readwrite.groovy + // ^ meta.block.groovy meta.block.groovy meta.group.groovy punctuation.section.group.end.groovy + // ^ meta.block.groovy meta.block.groovy meta.block.groovy punctuation.section.block.begin.groovy + notify.deployment(channel: config.jobStatusChannel, status: 'ABORTED', environment: params.CI_ENVIRONMENT) + } + throw e + // <- meta.block.groovy meta.block.groovy keyword.control.flow.throw.groovy + // ^ meta.block.groovy meta.block.groovy variable.other.readwrite.groovy + } + // <- meta.block.groovy meta.block.groovy punctuation.section.block.end.groovy +}