diff --git a/Github Actions.sublime-syntax b/Github Actions.sublime-syntax index 6ba84b7..49fa80d 100644 --- a/Github Actions.sublime-syntax +++ b/Github Actions.sublime-syntax @@ -9,6 +9,11 @@ extends: Packages/YamlPipelines/YamlPipeline.sublime-syntax contexts: node: - meta_prepend: true + - match: \s+(uses)\s*(:)(?=\s+actions/github-script\b) + captures: + 1: meta.mapping.key.yaml meta.string.yaml string.unquoted.plain.out.yaml + 2: punctuation.separator.key-value.yaml + push: github-script-step - match: \s+(shell)\s*(:)(?=\s|$) captures: 1: meta.mapping.key.yaml meta.string.yaml string.unquoted.plain.out.yaml keyword.control.shell.pipeline @@ -44,6 +49,21 @@ contexts: 2: punctuation.separator.key-value.yaml push: expect-jobs + github-script-step: + # bailout at end of step + # - either next step + # - or next job + - match: ^(?=\s*-|\s{,2}\S) + pop: 1 + # consume single script block with powershell syntax + - match: \s+(script)\s*(:)(?=\s|$) + captures: + 1: meta.mapping.key.yaml meta.string.yaml string.unquoted.plain.out.yaml + 2: punctuation.separator.key-value.yaml + set: javascript-block-node + # consume ordinary nodes + - include: node + expect-shell-name: - match: \b(?i:pwsh|powershell)\b scope: constant.other.language-name.yaml @@ -117,6 +137,12 @@ contexts: - include: scope:source.shell.bash.folded-github-actions apply_prototype: true + embedded-javascript: + - meta_include_prototype: false + - meta_content_scope: source.js.embedded + - include: scope:source.js + apply_prototype: true + embedded-pwsh: - meta_include_prototype: false - meta_content_scope: source.powershell.embedded diff --git a/YamlPipeline.sublime-syntax b/YamlPipeline.sublime-syntax index 59d258a..1192ac6 100644 --- a/YamlPipeline.sublime-syntax +++ b/YamlPipeline.sublime-syntax @@ -55,6 +55,7 @@ contexts: - include: strings inside-function-call-parens: + - meta_include_prototype: false - meta_content_scope: meta.function-call.arguments.pipeline - match: \) scope: punctuation.section.parens.end.pipeline @@ -63,6 +64,71 @@ contexts: scope: punctuation.separator.argument.pipeline - include: inside-expression +###[ JAVASCRIPT SCRIPT BLOCKS ]################################################ + + javascript-block-node: + - meta_scope: meta.block.javascript.pipeline + - include: javascript-block-scalar + - include: flow-scalar-javascript-out + + javascript-block-scalar: + # http://www.yaml.org/spec/1.2/spec.html#style/block/scalar + # c-l+folded(n) + - match: (>)([1-9])?([-+]?) # c-b-block-header(m,t) + captures: + 1: keyword.control.flow.block-scalar.folded.yaml + 2: constant.numeric.indentation-indicator.yaml + 3: javascript-block-scalar-begin + set: javascript-block-scalar-begin + # c-l+literal(n) + - match: (\|)([1-9])?([-+]?) # c-b-block-header(m,t) + captures: + 1: keyword.control.flow.block-scalar.literal.yaml + 2: constant.numeric.indentation-indicator.yaml + 3: storage.modifier.chomping-indicator.yaml + set: javascript-block-scalar-begin + + flow-scalar-javascript-out: + # double quoted scalar + - match: \" + scope: meta.string.yaml string.quoted.double.yaml punctuation.definition.string.begin.yaml + embed: embedded-javascript + embed_scope: meta.string.yaml + escape: \" + escape_captures: + 0: meta.string.yaml string.quoted.double.yaml punctuation.definition.string.end.yaml + pop: 1 + # single quoted scalar + - match: \' + scope: meta.string.yaml string.quoted.single.yaml punctuation.definition.string.begin.yaml + embed: embedded-javascript + embed_scope: meta.string.yaml + escape: \' + escape_captures: + 0: meta.string.yaml string.quoted.single.yaml punctuation.definition.string.end.yaml + pop: 1 + # unquoted scalar + - match: (?={{ns_plain_first_plain_out}}) + embed: embedded-javascript + embed_scope: meta.string.yaml + escape: '{{_flow_scalar_end_plain_out}}' + pop: 1 + + javascript-block-scalar-begin: + - meta_include_prototype: false + - include: comment + - match: ^([ ]+)(?! ) # match first non-empty line to determine indentation level + scope: meta.block.javascript.pipeline source.js.embedded + # note that we do not check if indentation is enough + embed: embedded-javascript + embed_scope: meta.block.javascript.pipeline + escape: ^(?!\1|\s*$) + pop: 1 + - match: ^(?=\S) # the block is empty + pop: 1 + - match: .+ + scope: invalid.illegal.expected-comment-or-newline.yaml + ###[ POWERSHELL SCRIPT BLOCKS ]################################################ pwsh-block-node: @@ -273,6 +339,9 @@ contexts: embedded-bash-folded: - meta_include_prototype: false + embedded-javascript: + - meta_include_prototype: false + embedded-pwsh: - meta_include_prototype: false diff --git a/tests/syntax_test_github_actions.yml b/tests/syntax_test_github_actions.yml index e0733d4..bc0de8a 100644 --- a/tests/syntax_test_github_actions.yml +++ b/tests/syntax_test_github_actions.yml @@ -91,6 +91,28 @@ jobs: steps: + + - name: Test JavaScript Highlighting + uses: actions/github-script@v9 + with: + script: | +# <- meta.block.javascript.pipeline +#^^^^^^^^^^^^^^^^^^ meta.block.javascript.pipeline +# ^^^^^^ meta.mapping.key.yaml meta.string.yaml string.unquoted.plain.out.yaml +# ^ punctuation.separator.key-value.yaml +# ^ keyword.control.flow.block-scalar.literal.yaml + await github.rest.repos.merge({ + # <- meta.block.javascript.pipeline source.js.embedded keyword.control.flow.await.js + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.javascript.pipeline source.js.embedded + #^^^^ keyword.control.flow.await.js + owner: context.repo.owner, + repo: context.repo.repo, + base: "v1", + head: context.sha, + commit_message: "Merge to v1" + }); + # <- meta.block.javascript.pipeline source.js.embedded meta.function-call.arguments.js meta.group.js meta.mapping.js punctuation.section.mapping.end.js + - name: Test leading source.powershell shell: pwsh # <- meta.mapping.key.yaml meta.string.yaml string.unquoted.plain.out.yaml keyword.control.shell.pipeline