Skip to content

Commit

Permalink
Fix #69 Fix semantic tokens of a comment embedded in an ENV
Browse files Browse the repository at this point in the history
If an ENV instruction spans multiple lines and an embedded comment
appears before any declared variables, the semantic token calculation
will get stuck in an infinite loop. This has now been fixed with an
upgrade to dockerfile-ast.

Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Jun 18, 2020
1 parent 3297d23 commit c57882f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
21 changes: 18 additions & 3 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
Expand Up @@ -20,7 +20,7 @@
"node": "*"
},
"dependencies": {
"dockerfile-ast": "0.0.25",
"dockerfile-ast": "0.0.27",
"dockerfile-utils": "0.0.16",
"vscode-languageserver-protocol": "^3.15.3",
"vscode-languageserver-types": "^3.15.1"
Expand Down
25 changes: 25 additions & 0 deletions test/dockerSemanticTokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,31 @@ describe("Dockerfile Semantic Token tests", () => {
assertEdit(tokens.data, SemanticTokenTypes.parameter, 25, 0, 5, 2);
assertEdit(tokens.data, SemanticTokenTypes.parameter, 30, 0, 3, 4);
});

it("multiline ENV instruction with only a comment", () => {
let content = "ENV \\\n# common variables:";
let tokens = computeSemanticTokens(content);
assert.equal(15, tokens.data.length);
assertEdit(tokens.data, SemanticTokenTypes.keyword, 0, 0, 0, 3);
assertEdit(tokens.data, SemanticTokenTypes.macro, 5, 0, 4, 1);
assertEdit(tokens.data, SemanticTokenTypes.comment, 10, 1, 0, 19);
});

it("multiline ENV instruction with a comment its variables", () => {
let content = "ENV \\\n# common variables:\n ENV1=something \\\n ENV2=999";
let tokens = computeSemanticTokens(content);
assert.equal(50, tokens.data.length);
assertEdit(tokens.data, SemanticTokenTypes.keyword, 0, 0, 0, 3);
assertEdit(tokens.data, SemanticTokenTypes.macro, 5, 0, 4, 1);
assertEdit(tokens.data, SemanticTokenTypes.comment, 10, 1, 0, 19);
assertEdit(tokens.data, SemanticTokenTypes.variable, 15, 1, 2, 4, [SemanticTokenModifiers.declaration]);
assertEdit(tokens.data, SemanticTokenTypes.operator, 20, 0, 4, 1);
assertEdit(tokens.data, SemanticTokenTypes.parameter, 25, 0, 1, 9);
assertEdit(tokens.data, SemanticTokenTypes.macro, 30, 0, 10, 1);
assertEdit(tokens.data, SemanticTokenTypes.variable, 35, 1, 2, 4, [SemanticTokenModifiers.declaration]);
assertEdit(tokens.data, SemanticTokenTypes.operator, 40, 0, 4, 1);
assertEdit(tokens.data, SemanticTokenTypes.parameter, 45, 0, 1, 3);
});
});
});
});

0 comments on commit c57882f

Please sign in to comment.