Skip to content

Commit

Permalink
feat: Comment commands [pre-release] (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
harrydowning authored Sep 14, 2024
1 parent 6fe768a commit 76e5ca9
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
needs: release-check
if: contains(github.event.head_commit.message, '[pre-release]') && !contains(github.event.head_commit.message, '[release]')
env:
PRE_RELEASE: true
PRE_RELEASE: "true"
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

## [1.1.0-beta] - 2024-09-14

### Added

- Comment commands to allow highlighting complete sections

## [1.0.6] - 2024-09-12

### Fixed
Expand Down Expand Up @@ -146,6 +152,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Highlighting support for 40 languages in YAML block-scalars

[unreleased]: https://github.com/harrydowning/vscode-yaml-embedded-languages/compare/v1.0.6...HEAD
[1.1.0-beta]: https://github.com/harrydowning/vscode-yaml-embedded-languages/compare/v1.0.6...v1.1.0-beta
[1.0.6]: https://github.com/harrydowning/vscode-yaml-embedded-languages/compare/v1.0.5...v1.0.6
[1.0.5]: https://github.com/harrydowning/vscode-yaml-embedded-languages/compare/v1.0.4...v1.0.5
[1.0.4]: https://github.com/harrydowning/vscode-yaml-embedded-languages/compare/v1.0.3...v1.0.4
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yaml-embedded-languages",
"version": "1.0.6",
"version": "1.1.0-beta",
"displayName": "YAML Embedded Languages",
"description": "Support for syntax highlighting within YAML block-scalars.",
"icon": "images/icon.png",
Expand Down
106 changes: 76 additions & 30 deletions src/injection-grammar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Languages } from "./constants";
import packageJson from "@package";
import { Languages, PRE_RELEASE } from "./constants";
import { Writable } from "./writable";

export class InjectionGrammar extends Writable {
Expand All @@ -16,42 +17,87 @@ export class InjectionGrammar extends Writable {

#getPatterns() {
const entries = Object.entries(this.languages);
return entries.map(([id, { scopeName, stripIndent }]) => ({
begin: `(?i)(?:(\\|)|(>))([1-9])?([-+])?\\s+(#\\s*(?:${id})\\s*\\n)`,
beginCaptures: {
1: {
name: "keyword.control.flow.block-scalar.literal.yaml",
},
2: {
name: "keyword.control.flow.block-scalar.folded.yaml",
},
3: {
name: "constant.numeric.indentation-indicator.yaml",
},
4: {
name: "storage.modifier.chomping-indicator.yaml",
},
5: {
name: "entity.name.type.yaml",
},
},
end: "^(?=\\S)|(?!\\G)",
patterns: [
const patterns = [];

if (PRE_RELEASE) {
patterns.push(
{
begin: "(?>^|\\G)([ ]+)(?! )",
end: "^(?!\\1|\\s*$)",
while: stripIndent ? "^$|\\1" : undefined,
name: `${this.embeddedScopeNamePrefix}.${id}`,
patterns: [{ include: scopeName }],
begin: `#\\s*${packageJson.name}\\s*$`,
beginCaptures: {
0: { name: "entity.name.type.yaml" },
},
patterns: [{ include: this.injectionScopeName }],
},
...entries.map(([id, { scopeName, stripIndent }]) => ({
begin: `#\\s*${packageJson.name}\\s*:\\s*${id}\\s*$`,
beginCaptures: {
0: { name: "entity.name.type.yaml" },
},
patterns: [
{
begin: `(?i)(?:(\\|)|(>))([1-9])?([-+])?(.*)\\s*$`,
beginCaptures: {
1: { name: "keyword.control.flow.block-scalar.literal.yaml" },
2: { name: "keyword.control.flow.block-scalar.folded.yaml" },
3: { name: "constant.numeric.indentation-indicator.yaml" },
4: { name: "storage.modifier.chomping-indicator.yaml" },
5: {
patterns: [
{ include: `${this.injectionScopeName}#comment` },
{
match: ".+",
name: "invalid.illegal.expected-comment-or-newline.yaml",
},
],
},
},
end: "^(?=\\S)|(?!\\G)",
patterns: [
{
begin: "(?>^|\\G)([ ]+)(?! )",
end: "^(?!\\1|\\s*$)",
while: stripIndent ? "^$|\\1" : undefined,
name: `${this.embeddedScopeNamePrefix}.${id}`,
patterns: [{ include: scopeName }],
},
],
},
{ include: this.injectionScopeName },
],
})),
);
}

patterns.push(
...entries.map(([id, { scopeName, stripIndent }]) => ({
begin: `(?i)(?:(\\|)|(>))([1-9])?([-+])?\\s+(#\\s*(?:${id})\\s*)$`,
beginCaptures: {
1: { name: "keyword.control.flow.block-scalar.literal.yaml" },
2: { name: "keyword.control.flow.block-scalar.folded.yaml" },
3: { name: "constant.numeric.indentation-indicator.yaml" },
4: { name: "storage.modifier.chomping-indicator.yaml" },
5: { name: "entity.name.type.yaml" },
},
],
}));
end: "^(?=\\S)|(?!\\G)",
patterns: [
{
begin: "(?>^|\\G)([ ]+)(?! )",
end: "^(?!\\1|\\s*$)",
while: stripIndent ? "^$|\\1" : undefined,
name: `${this.embeddedScopeNamePrefix}.${id}`,
patterns: [{ include: scopeName }],
},
],
})),
);

return patterns;
}

valueOf() {
return {
scopeName: this.scopeName,
injectionSelector: `L:${this.injectionScopeName} -comment`,
injectionSelector: `L:${this.injectionScopeName} -comment -string -meta.embedded`,
patterns: this.#getPatterns(),
};
}
Expand Down
Loading

0 comments on commit 76e5ca9

Please sign in to comment.