Injections: Priority match not working. Fixes Microsoft/vscode#15792

This commit is contained in:
Martin Aeschlimann 2016-12-08 16:31:28 +01:00
Родитель a33377e93d
Коммит 96fc5e52da
4 изменённых файлов: 4403 добавлений и 79 удалений

Просмотреть файл

@ -357,7 +357,9 @@ function matchInjections(injections:Injection[], grammar: Grammar, lineText: Oni
let matchRating = matchResult.captureIndices[0].start;
if (matchRating >= bestMatchRating) {
if (matchRating > bestMatchRating) {
continue;
} else if (matchRating === bestMatchRating && (!injection.priorityMatch || bestMatchResultPriority)) {
continue;
}

Просмотреть файл

@ -0,0 +1,542 @@
{
"fileTypes": [
"html",
"htm",
"shtml",
"xhtml",
"inc",
"tmpl",
"tpl"
],
"firstLineMatch": "<(?i:(!DOCTYPE\\s*)?html)",
"injections": {
"R:text.html - comment.block": {
"comment": "Use R: to ensure this matches after any other injections.",
"patterns": [
{
"match": "<",
"name": "invalid.illegal.bad-angle-bracket.html"
}
]
}
},
"keyEquivalent": "^~H",
"name": "HTML",
"patterns": [
{
"begin": "(<)([a-zA-Z0-9:]++)(?=[^>]*></\\2>)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.tag.html"
},
"2": {
"name": "entity.name.tag.html"
}
},
"end": "(>(<)/)(\\2)(>)",
"endCaptures": {
"1": {
"name": "punctuation.definition.tag.html"
},
"2": {
"name": "meta.scope.between-tag-pair.html"
},
"3": {
"name": "entity.name.tag.html"
},
"4": {
"name": "punctuation.definition.tag.html"
}
},
"name": "meta.tag.any.html",
"patterns": [
{
"include": "#tag-stuff"
}
]
},
{
"begin": "(<\\?)(xml)",
"captures": {
"1": {
"name": "punctuation.definition.tag.html"
},
"2": {
"name": "entity.name.tag.xml.html"
}
},
"end": "(\\?>)",
"name": "meta.tag.preprocessor.xml.html",
"patterns": [
{
"include": "#tag-generic-attribute"
},
{
"include": "#string-double-quoted"
},
{
"include": "#string-single-quoted"
}
]
},
{
"begin": "<!--",
"captures": {
"0": {
"name": "punctuation.definition.comment.html"
}
},
"end": "--\\s*>",
"name": "comment.block.html",
"patterns": [
{
"match": "--",
"name": "invalid.illegal.bad-comments-or-CDATA.html"
},
{
"include": "#embedded-code"
}
]
},
{
"begin": "<!",
"captures": {
"0": {
"name": "punctuation.definition.tag.html"
}
},
"end": ">",
"name": "meta.tag.sgml.html",
"patterns": [
{
"begin": "(?i:DOCTYPE)",
"captures": {
"1": {
"name": "entity.name.tag.doctype.html"
}
},
"end": "(?=>)",
"name": "meta.tag.sgml.doctype.html",
"patterns": [
{
"match": "\"[^\">]*\"",
"name": "string.quoted.double.doctype.identifiers-and-DTDs.html"
}
]
},
{
"begin": "\\[CDATA\\[",
"end": "]](?=>)",
"name": "constant.other.inline-data.html"
},
{
"match": "(\\s*)(?!--|>)\\S(\\s*)",
"name": "invalid.illegal.bad-comments-or-CDATA.html"
}
]
},
{
"include": "#embedded-code"
},
{
"begin": "(?:^\\s+)?(<)((?i:style))\\b(?![^>]*/>)",
"captures": {
"1": {
"name": "punctuation.definition.tag.html"
},
"2": {
"name": "entity.name.tag.style.html"
},
"3": {
"name": "punctuation.definition.tag.html"
}
},
"end": "(</)((?i:style))(>)(?:\\s*\\n)?",
"name": "source.css.embedded.html",
"patterns": [
{
"include": "#tag-stuff"
},
{
"begin": "(>)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.tag.html"
}
},
"end": "(?=</(?i:style))",
"patterns": [
{
"include": "#embedded-code"
},
{
"include": "source.css"
}
]
}
]
},
{
"begin": "(?:^\\s+)?(<)((?i:script))\\b(?![^>]*/>)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.tag.html"
},
"2": {
"name": "entity.name.tag.script.html"
}
},
"end": "(?<=</(script|SCRIPT))(>)(?:\\s*\\n)?",
"endCaptures": {
"2": {
"name": "punctuation.definition.tag.html"
}
},
"name": "source.js.embedded.html",
"patterns": [
{
"include": "#tag-stuff"
},
{
"begin": "(?<!</(?:script|SCRIPT))(>)",
"captures": {
"1": {
"name": "punctuation.definition.tag.html"
},
"2": {
"name": "entity.name.tag.script.html"
}
},
"end": "(</)((?i:script))",
"patterns": [
{
"captures": {
"1": {
"name": "punctuation.definition.comment.js"
}
},
"match": "(//).*?((?=</script)|$\\n?)",
"name": "comment.line.double-slash.js"
},
{
"begin": "/\\*",
"captures": {
"0": {
"name": "punctuation.definition.comment.js"
}
},
"end": "\\*/|(?=</script)",
"name": "comment.block.js"
},
{
"include": "source.js"
}
]
}
]
},
{
"begin": "(</?)((?i:body|head|html)\\b)",
"captures": {
"1": {
"name": "punctuation.definition.tag.html"
},
"2": {
"name": "entity.name.tag.structure.any.html"
}
},
"end": "(>)",
"name": "meta.tag.structure.any.html",
"patterns": [
{
"include": "#tag-stuff"
}
]
},
{
"begin": "(</?)((?i:address|blockquote|dd|div|section|article|aside|header|footer|nav|menu|dl|dt|fieldset|form|frame|frameset|h1|h2|h3|h4|h5|h6|iframe|noframes|object|ol|p|ul|applet|center|dir|hr|pre)\\b)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.tag.begin.html"
},
"2": {
"name": "entity.name.tag.block.any.html"
}
},
"end": "(>)",
"endCaptures": {
"1": {
"name": "punctuation.definition.tag.end.html"
}
},
"name": "meta.tag.block.any.html",
"patterns": [
{
"include": "#tag-stuff"
}
]
},
{
"begin": "(</?)((?i:a|abbr|acronym|area|b|base|basefont|bdo|big|br|button|caption|cite|code|col|colgroup|del|dfn|em|font|head|html|i|img|input|ins|isindex|kbd|label|legend|li|link|map|meta|noscript|optgroup|option|param|q|s|samp|script|select|small|span|strike|strong|style|sub|sup|table|tbody|td|textarea|tfoot|th|thead|title|tr|tt|u|var)\\b)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.tag.begin.html"
},
"2": {
"name": "entity.name.tag.inline.any.html"
}
},
"end": "((?: ?/)?>)",
"endCaptures": {
"1": {
"name": "punctuation.definition.tag.end.html"
}
},
"name": "meta.tag.inline.any.html",
"patterns": [
{
"include": "#tag-stuff"
}
]
},
{
"begin": "(</?)([a-zA-Z0-9:]+)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.tag.begin.html"
},
"2": {
"name": "entity.name.tag.other.html"
}
},
"end": "(>)",
"endCaptures": {
"1": {
"name": "punctuation.definition.tag.end.html"
}
},
"name": "meta.tag.other.html",
"patterns": [
{
"include": "#tag-stuff"
}
]
},
{
"include": "#entities"
},
{
"match": "<>",
"name": "invalid.illegal.incomplete.html"
}
],
"repository": {
"embedded-code": {
"patterns": [
{
"include": "#smarty"
},
{
"include": "#python"
}
]
},
"entities": {
"patterns": [
{
"captures": {
"1": {
"name": "punctuation.definition.entity.html"
},
"3": {
"name": "punctuation.definition.entity.html"
}
},
"match": "(&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;)",
"name": "constant.character.entity.html"
},
{
"match": "&",
"name": "invalid.illegal.bad-ampersand.html"
}
]
},
"python": {
"begin": "(?:^\\s*)<\\?python(?!.*\\?>)",
"end": "\\?>(?:\\s*$\\n)?",
"name": "source.python.embedded.html",
"patterns": [
{
"include": "source.python"
}
]
},
"smarty": {
"patterns": [
{
"begin": "(\\{(literal)\\})",
"captures": {
"1": {
"name": "source.smarty.embedded.html"
},
"2": {
"name": "support.function.built-in.smarty"
}
},
"end": "(\\{/(literal)\\})"
},
{
"begin": "{{|{",
"disabled": 1,
"end": "}}|}",
"name": "source.smarty.embedded.html",
"patterns": [
{
"include": "source.smarty"
}
]
}
]
},
"string-double-quoted": {
"begin": "\"",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.html"
}
},
"end": "\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.html"
}
},
"name": "string.quoted.double.html",
"patterns": [
{
"include": "#embedded-code"
},
{
"include": "#entities"
}
]
},
"string-single-quoted": {
"begin": "'",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.html"
}
},
"end": "'",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.html"
}
},
"name": "string.quoted.single.html",
"patterns": [
{
"include": "#embedded-code"
},
{
"include": "#entities"
}
]
},
"tag-generic-attribute": {
"match": "(?<=[^=])\\b([a-zA-Z0-9:-]+)",
"name": "entity.other.attribute-name.html"
},
"tag-id-attribute": {
"begin": "\\b(id)\\b\\s*(=)",
"captures": {
"1": {
"name": "entity.other.attribute-name.id.html"
},
"2": {
"name": "punctuation.separator.key-value.html"
}
},
"end": "(?<='|\")",
"name": "meta.attribute-with-value.id.html",
"patterns": [
{
"begin": "\"",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.html"
}
},
"contentName": "meta.toc-list.id.html",
"end": "\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.html"
}
},
"name": "string.quoted.double.html",
"patterns": [
{
"include": "#embedded-code"
},
{
"include": "#entities"
}
]
},
{
"begin": "'",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.html"
}
},
"contentName": "meta.toc-list.id.html",
"end": "'",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.html"
}
},
"name": "string.quoted.single.html",
"patterns": [
{
"include": "#embedded-code"
},
{
"include": "#entities"
}
]
}
]
},
"tag-stuff": {
"patterns": [
{
"include": "#tag-id-attribute"
},
{
"include": "#tag-generic-attribute"
},
{
"include": "#string-double-quoted"
},
{
"include": "#string-single-quoted"
},
{
"include": "#embedded-code"
},
{
"include": "#unquoted-attribute"
}
]
},
"unquoted-attribute": {
"match": "(?<==)(?:[^\\s<>/'\"]|/(?!>))+",
"name": "string.unquoted.html"
}
},
"scopeName": "text.html.basic"
}

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -79,16 +79,16 @@
"lines": [
{
"line": "This is a paragraph",
"tokens": [
{
"value": "This is a paragraph",
"scopes": [
"text.html.markdown",
"meta.paragraph.markdown"
]
}
]
},
"tokens": [
{
"value": "This is a paragraph",
"scopes": [
"text.html.markdown",
"meta.paragraph.markdown"
]
}
]
},
{
"line": "## This is *great* stuff",
"tokens": [
@ -286,7 +286,9 @@
},
{
"grammars": [
"fixtures/php.plist"
"fixtures/php.plist",
"fixtures/javascript.json",
"fixtures/html.json"
],
"grammarPath": "fixtures/php.plist",
"desc": "Injections in PHP",
@ -423,6 +425,155 @@
]
}
]
},
{
"line": "<script><?php echo $test; ?></script>",
"tokens": [
{
"value": "<",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"punctuation.definition.tag.html"
]
},
{
"value": "script",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"entity.name.tag.script.html"
]
},
{
"value": ">",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"punctuation.definition.tag.html"
]
},
{
"value": "<?php",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"meta.embedded.line.php",
"punctuation.section.embedded.begin.php"
]
},
{
"value": " ",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"meta.embedded.line.php",
"source.php"
]
},
{
"value": "echo",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"meta.embedded.line.php",
"source.php",
"support.function.construct.php"
]
},
{
"value": " ",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"meta.embedded.line.php",
"source.php"
]
},
{
"value": "$",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"meta.embedded.line.php",
"source.php",
"variable.other.php",
"punctuation.definition.variable.php"
]
},
{
"value": "test",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"meta.embedded.line.php",
"source.php",
"variable.other.php"
]
},
{
"value": ";",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"meta.embedded.line.php",
"source.php",
"punctuation.terminator.expression.php"
]
},
{
"value": " ",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"meta.embedded.line.php",
"source.php"
]
},
{
"value": "?",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"meta.embedded.line.php",
"punctuation.section.embedded.end.php",
"source.php"
]
},
{
"value": ">",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"meta.embedded.line.php",
"punctuation.section.embedded.end.php"
]
},
{
"value": "</",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"punctuation.definition.tag.html"
]
},
{
"value": "script",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"entity.name.tag.script.html"
]
},
{
"value": ">",
"scopes": [
"text.html.php",
"source.js.embedded.html",
"punctuation.definition.tag.html"
]
}
]
}
]
},
@ -735,7 +886,7 @@
{
"line": " $(eval $(SET_VERSION):,@:)",
"tokens": [
{
{
"value": " ",
"scopes": [
"source.makefile",
@ -860,61 +1011,73 @@
"lines": [
{
"line": "[test]|",
"tokens": [{
"value": "[test]|",
"scopes": [
"text.testlang",
"string.unquoted.verbatim.youki"
]
}]
"tokens": [
{
"value": "[test]|",
"scopes": [
"text.testlang",
"string.unquoted.verbatim.youki"
]
}
]
},
{
"line": "\tverb",
"tokens": [{
"value": "\tverb",
"scopes": [
"text.testlang",
"string.unquoted.verbatim.youki"
]
}]
"tokens": [
{
"value": "\tverb",
"scopes": [
"text.testlang",
"string.unquoted.verbatim.youki"
]
}
]
},
{
"line": "asd",
"tokens": [{
"value": "asd",
"scopes": [
"text.testlang"
]
}]
"tokens": [
{
"value": "asd",
"scopes": [
"text.testlang"
]
}
]
},
{
"line": "asd",
"tokens": [{
"value": "asd",
"scopes": [
"text.testlang"
]
}]
"tokens": [
{
"value": "asd",
"scopes": [
"text.testlang"
]
}
]
},
{
"line": "[test]|",
"tokens": [{
"value": "[test]|",
"scopes": [
"text.testlang",
"string.unquoted.verbatim.youki"
]
}]
"tokens": [
{
"value": "[test]|",
"scopes": [
"text.testlang",
"string.unquoted.verbatim.youki"
]
}
]
},
{
"line": "\tverbatim",
"tokens": [{
"value": "\tverbatim",
"scopes": [
"text.testlang",
"string.unquoted.verbatim.youki"
]
}]
"tokens": [
{
"value": "\tverbatim",
"scopes": [
"text.testlang",
"string.unquoted.verbatim.youki"
]
}
]
}
]
},
@ -927,37 +1090,44 @@
"lines": [
{
"line": ".ssdsd",
"tokens": [{
"value": ".ssdsd",
"scopes": [
"text.jade"
]
}]
"tokens": [
{
"value": ".ssdsd",
"scopes": [
"text.jade"
]
}
]
},
{
"line": "",
"tokens": [{
"value": "",
"scopes": [
"text.jade"
]
}]
"tokens": [
{
"value": "",
"scopes": [
"text.jade"
]
}
]
},
{
"line": " // asdsdas",
"tokens": [{
"value": " //",
"scopes": [
"text.jade",
"string.comment.buffered.block.jade"
]
}, {
"value": " asdsdas",
"scopes": [
"text.jade",
"string.comment.buffered.block.jade"
]
}]
"tokens": [
{
"value": " //",
"scopes": [
"text.jade",
"string.comment.buffered.block.jade"
]
},
{
"value": " asdsdas",
"scopes": [
"text.jade",
"string.comment.buffered.block.jade"
]
}
]
}
]
},
@ -1016,4 +1186,4 @@
}
]
}
]
]