Skip to content

Commit

Permalink
Fixes #105: Handle rules containing only include
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Aug 16, 2019
1 parent 6dc9b72 commit d7c7996
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
6 changes: 5 additions & 1 deletion release/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,11 @@ var RuleFactory = /** @class */ (function () {
if (desc.repository) {
repository = utils_1.mergeObjects({}, repository, desc.repository);
}
return new IncludeOnlyRule(desc.$vscodeTextmateLocation, desc.id, desc.name, desc.contentName, RuleFactory._compilePatterns(desc.patterns, helper, repository));
var patterns = desc.patterns;
if (typeof patterns === 'undefined' && desc.include) {
patterns = [{ include: desc.include }];
}
return new IncludeOnlyRule(desc.$vscodeTextmateLocation, desc.id, desc.name, desc.contentName, RuleFactory._compilePatterns(patterns, helper, repository));
}
if (desc.while) {
return new BeginWhileRule(desc.$vscodeTextmateLocation, desc.id, desc.name, desc.contentName, desc.begin, RuleFactory._compileCaptures(desc.beginCaptures || desc.captures, helper, repository), desc.while, RuleFactory._compileCaptures(desc.whileCaptures || desc.captures, helper, repository), RuleFactory._compilePatterns(desc.patterns, helper, repository));
Expand Down
6 changes: 5 additions & 1 deletion src/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,16 @@ export class RuleFactory {
if (desc.repository) {
repository = mergeObjects({}, repository, desc.repository);
}
let patterns = desc.patterns;
if (typeof patterns === 'undefined' && desc.include) {
patterns = [{ include: desc.include }];
}
return new IncludeOnlyRule(
desc.$vscodeTextmateLocation,
desc.id,
desc.name,
desc.contentName,
RuleFactory._compilePatterns(desc.patterns, helper, repository)
RuleFactory._compilePatterns(patterns, helper, repository)
);
}

Expand Down
20 changes: 20 additions & 0 deletions test-cases/suite1/fixtures/105.grammarA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"scopeName": "source.test",
"patterns": [{ "include": "#test" }, { "include": "#embedded" }],
"repository": {
"test": {
"begin": "testStart",
"end": "testEnd",
"patterns": [{ "include": "#test2" }]
},
"test2": {
"match": "some test pattern",
"name": "test.name"
},
"embedded": {
"begin": "embedStart",
"end": "embedEnd",
"patterns": [{ "include": "source.test.embedded" }]
}
}
}
14 changes: 14 additions & 0 deletions test-cases/suite1/fixtures/105.grammarB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"scopeName": "source.test.embedded",
"patterns": [{ "include": "#test" }],
"repository": {
"test": {
"begin": "testStart",
"end": "testEnd",
"patterns": [{ "include": "#test2" }]
},
"test2": {
"include": "source.test#test2"
}
}
}
46 changes: 45 additions & 1 deletion test-cases/suite1/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -1474,5 +1474,49 @@
]
}
]
},
{
"grammars": [
"fixtures/105.grammarA.json",
"fixtures/105.grammarB.json"
],
"grammarPath": "fixtures/105.grammarA.json",
"desc": "Issue #105",
"lines": [
{
"line": "embedStart",
"tokens": [
{
"value": "embedStart",
"scopes": [
"source.test"
]
}
]
},
{
"line": "testStart",
"tokens": [
{
"value": "testStart",
"scopes": [
"source.test"
]
}
]
},
{
"line": "some test pattern",
"tokens": [
{
"value": "some test pattern",
"scopes": [
"source.test",
"test.name"
]
}
]
}
]
}
]
]

0 comments on commit d7c7996

Please sign in to comment.