Skip to content

Commit 1397642

Browse files
committed
Improve and fix package.json "scripts" injection
1 parent e7a886c commit 1397642

File tree

2 files changed

+24
-35
lines changed

2 files changed

+24
-35
lines changed

syntaxes/scripts.tmLanguage.json

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,40 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json",
3-
"name": "package.json",
3+
"name": "`package.json` \"scripts\": {}",
44
"scopeName": "source.json.shellscript",
5-
"injectionSelector": "L:source.json .meta.embedded.scripts. meta.structure.dictionary.json meta.structure.dictionary.value.json -(meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json) -meta.structure.array.json -string -comment",
5+
"injectionSelector": "L:source.json .meta.embedded.scripts. meta.structure.dictionary.json string.quoted.double.json -(meta.structure.dictionary.json meta.structure.dictionary.json meta.structure.dictionary.json) -meta.structure.array.json -meta.embedded.shellscript.json -comment -source.json.comments",
66
"patterns": [
7+
{
8+
"comment": "https://github.com/microsoft/vscode-textmate/issues/242",
9+
"include": "source.shell#_pre-load_"
10+
},
711
{ "include": "#scripts" }
812
],
913
"repository": {
1014
"scripts": {
11-
"patterns": [
12-
{
13-
"comment": "VSCode TextMate bug. For some reason, including a grammar from within a capture group doesn't load the include. We have to pre-load the include outside of a capture group. `source.shell`",
14-
"begin": "(*FAIL)",
15-
"end": "|",
16-
"patterns": [ { "include": "source.shell" } ]
17-
},
18-
{
19-
"match": "(\")((?>[^\\\\\"]++|\\\\.)++)(\")",
20-
"captures": {
21-
"0": { "name": "string.quoted.double.json" },
22-
"1": { "name": "punctuation.definition.string.begin.json" },
23-
"2": {
24-
"name": "meta.embedded.shellscript.json",
15+
"match": "\\G(?>[^\\\\\"\\x-\\x1F]++|\\\\.)++",
16+
"captures": {
17+
"0": {
18+
"name": "meta.embedded.shellscript.json",
19+
"patterns": [
20+
{
21+
"comment": "Setup a `\\G` anchor for ShellScript to use",
22+
"begin": "|",
23+
"end": "(*FAIL)",
2524
"patterns": [
25+
{ "include": "source.shell" },
2626
{
27-
"comment": "Setup a `\\G` anchor for ShellScript to use",
28-
"begin": "|",
29-
"end": "(*FAIL)",
30-
"patterns": [
31-
{ "include": "source.shell" },
32-
{
33-
"begin": "(?!^[ \\t]*+$)(?:(?<=^until | until |\\tuntil |^while | while |\\twhile |^elif | elif |\\telif |^else | else |\\telse |^then | then |\\tthen |^do | do |\\tdo |^if | if |\\tif )|(?<=\"\\G|^|;|\\||&|!|\\(|\\{|`))[ \\t]*+(?!nocorrect\\W|nocorrect\\$|function\\W|function\\$|foreach\\W|foreach\\$|repeat\\W|repeat\\$|logout\\W|logout\\$|coproc\\W|coproc\\$|select\\W|select\\$|while\\W|while\\$|pushd\\W|pushd\\$|until\\W|until\\$|case\\W|case\\$|done\\W|done\\$|elif\\W|elif\\$|else\\W|else\\$|esac\\W|esac\\$|popd\\W|popd\\$|then\\W|then\\$|time\\W|time\\$|for\\W|for\\$|end\\W|end\\$|fi\\W|fi\\$|do\\W|do\\$|in\\W|in\\$|if\\W|if\\$)",
34-
"end": "(?=;|\\||&|\\n|\\)|`|\\{|\\}|[ \\t]*#|\\])(?<!\\\\)",
35-
"beginCaptures": { },
36-
"endCaptures": { },
37-
"name": "meta.statement.shell",
38-
"patterns": [ { "include": "source.shell#typical_statements" } ]
39-
}
40-
]
27+
"begin": "(?<=\"\\G)[ \\t]*+(?!(?>nocorrect|function|foreach|repeat|logout|coproc|select|while|pushd|until|case|done|elif|else|esac|popd|then|time|for|end|fi|do|in|if)\\W)",
28+
"end": "(?<!\\\\)(?=[];|&\n)`{}]|[ \t]*+#)",
29+
"name": "meta.statement.shell",
30+
"patterns": [ { "include": "source.shell#typical_statements" } ]
4131
},
4232
{ "include": "source.json#stringcontent" }
4333
]
44-
},
45-
"3": { "name": "punctuation.definition.string.end.json" }
46-
}
34+
}
35+
]
4736
}
48-
]
37+
}
4938
}
5039
}
5140
}

syntaxes/shellscript.json.escaped.tmLanguage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Shellscript JSON escaped",
44
"comment": "Double quotes requiring escaping when embedded inside JSON",
55
"scopeName": "source.shellscript.json.escaped",
6-
"injectionSelector": "L:source.json meta.embedded.shellscript.json.scripts -string.quoted.double.shell",
6+
"injectionSelector": "L:source.json meta.embedded.shellscript.json -string.quoted.double.shell",
77
"patterns": [
88
{ "include": "#string" }
99
],

0 commit comments

Comments
 (0)