Skip to content

Commit

Permalink
Fix #8 Align active parameter of FROM signatures
Browse files Browse the repository at this point in the history
Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Feb 19, 2018
1 parent 3dab478 commit c47abd2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.

### Fixed
- change documentation to state that STOPSIGNAL was added in Docker 1.9 instead of Docker 1.12 ([#6](https://github.com/rcjsuen/dockerfile-language-service/issues/6))
- align active parameter amongst all displayed signatures for a FROM with a build stage name ([#8](https://github.com/rcjsuen/dockerfile-language-service/issues/8))

### Removed
- replaced DockerfileLanguageService's createWorkspaceEdit with a computeCommandEdits function ([#4](https://github.com/rcjsuen/dockerfile-language-service/issues/4))
Expand Down
26 changes: 15 additions & 11 deletions src/dockerSignatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,12 @@ export class DockerSignatures {
label: "baseImage",
documentation: this.documentation.getDocumentation("signatureFrom_Signature3_Param0")
},
{
// placeholder parameter to get the activeParameter to line
// up with all three signature types of FROM
// see rcjsuen/dockerfile-language-service#8
label: ""
},
{
label: "AS",
},
Expand Down Expand Up @@ -1103,22 +1109,20 @@ export class DockerSignatures {
const inDigest = digest && Util.isInsideRange(position, from.getImageDigestRange());
if (args.length === 1) {
if (args[0].isBefore(position)) {
return tag || digest ? 2 : 1;
return 2;
}
return inTag || inDigest ? 1 : 0;
} else if (args.length === 2) {
if (args[1].isBefore(position)) {
return tag || digest ? 3 : 2;
return 3;
} else if (Util.isInsideRange(position, args[1].getRange()) || args[0].isBefore(position)) {
return tag || digest ? 2 : 1;
return 2;
}
} else {
if (Util.isInsideRange(position, args[2].getRange()) || args[1].isBefore(position)) {
return 3;
} else if (Util.isInsideRange(position, args[1].getRange()) || args[0].isBefore(position)) {
return 2;
}
return inTag || inDigest ? 1 : 0;
}

if (Util.isInsideRange(position, args[2].getRange()) || args[1].isBefore(position)) {
return tag || digest ? 3 : 2;
} else if (Util.isInsideRange(position, args[1].getRange()) || args[0].isBefore(position)) {
return tag || digest ? 2 : 1;
}
return inTag || inDigest ? 1 : 0;
}
Expand Down
34 changes: 18 additions & 16 deletions test/dockerSignatures.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,17 @@ function assertFrom_Image_BuildStage(signature: SignatureInformation) {
assert.equal(signature.label, "FROM baseImage AS stage");
assert.notEqual(signature.documentation, null);
assert.equal(signature.documentation, docs.getDocumentation("signatureFrom_Signature3"));
assert.equal(signature.parameters.length, 3);
assert.equal(signature.parameters.length, 4);
assert.equal(signature.parameters[0].label, "baseImage");
assert.notEqual(signature.parameters[0].documentation, null);
assert.equal(signature.parameters[0].documentation, docs.getDocumentation("signatureFrom_Signature3_Param0"));
assert.equal(signature.parameters[1].label, "AS");
assert.equal(signature.parameters[1].label, "");
assert.equal(signature.parameters[1].documentation, null);
assert.equal(signature.parameters[2].label, "stage");
assert.notEqual(signature.parameters[2].documentation, null);
assert.equal(signature.parameters[2].documentation, docs.getDocumentation("signatureFrom_Signature3_Param2"));
assert.equal(signature.parameters[2].label, "AS");
assert.equal(signature.parameters[2].documentation, null);
assert.equal(signature.parameters[3].label, "stage");
assert.notEqual(signature.parameters[3].documentation, null);
assert.equal(signature.parameters[3].documentation, docs.getDocumentation("signatureFrom_Signature3_Param2"));
}

function assertFrom_ImageTag_BuildStage(signature: SignatureInformation) {
Expand Down Expand Up @@ -1562,26 +1564,26 @@ describe("Dockerfile Signature Tests", function () {
});

it("stages", function () {
assertFrom_BuildStages(compute("FROM node ", 0, 10), 1);
assertFrom_BuildStages(compute("FROM node ", 0, 10), 2);

assertFrom_BuildStages(compute("FROM node AS", 0, 5), 0);
assertFrom_BuildStages(compute("FROM node AS", 0, 7), 0);
assertFrom_BuildStages(compute("FROM node AS", 0, 9), 0);
assertFrom_BuildStages(compute("FROM node AS", 0, 10), 1);
assertFrom_BuildStages(compute("FROM node AS", 0, 11), 1);
assertFrom_BuildStages(compute("FROM node AS", 0, 12), 1);
assertFrom_BuildStages(compute("FROM node AS", 0, 10), 2);
assertFrom_BuildStages(compute("FROM node AS", 0, 11), 2);
assertFrom_BuildStages(compute("FROM node AS", 0, 12), 2);

assertFrom_BuildStages(compute("FROM node AS ", 0, 13), 2);
assertFrom_BuildStages(compute("FROM node AS ", 0, 13), 3);

assertFrom_BuildStages(compute("FROM node AS js", 0, 5), 0);
assertFrom_BuildStages(compute("FROM node AS js", 0, 7), 0);
assertFrom_BuildStages(compute("FROM node AS js", 0, 9), 0);
assertFrom_BuildStages(compute("FROM node AS js", 0, 10), 1);
assertFrom_BuildStages(compute("FROM node AS js", 0, 11), 1);
assertFrom_BuildStages(compute("FROM node AS js", 0, 12), 1);
assertFrom_BuildStages(compute("FROM node AS js", 0, 13), 2);
assertFrom_BuildStages(compute("FROM node AS js", 0, 14), 2);
assertFrom_BuildStages(compute("FROM node AS js", 0, 15), 2);
assertFrom_BuildStages(compute("FROM node AS js", 0, 10), 2);
assertFrom_BuildStages(compute("FROM node AS js", 0, 11), 2);
assertFrom_BuildStages(compute("FROM node AS js", 0, 12), 2);
assertFrom_BuildStages(compute("FROM node AS js", 0, 13), 3);
assertFrom_BuildStages(compute("FROM node AS js", 0, 14), 3);
assertFrom_BuildStages(compute("FROM node AS js", 0, 15), 3);
});

it("tags and stages", function () {
Expand Down

0 comments on commit c47abd2

Please sign in to comment.