Skip to content

Commit

Permalink
[Groovy] use more specific sub-scopes for keywords (#4051)
Browse files Browse the repository at this point in the history
Co-authored-by: Keith Hall <[email protected]>
  • Loading branch information
keith-hall and Keith Hall authored Dec 8, 2024
1 parent 6816b39 commit 3b59164
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 20 deletions.
57 changes: 40 additions & 17 deletions Groovy/Groovy.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -147,49 +147,72 @@ 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: $|(?=\})
pop: true
- 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: \.\.
scope: keyword.operator.range.groovy
- 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:
Expand Down
6 changes: 3 additions & 3 deletions Groovy/tests/syntax_test_Strings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions Groovy/tests/syntax_test_jenkins.Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3b59164

Please sign in to comment.