Skip to content

Commit

Permalink
WIP #162 Add signature help support for EXPOSE
Browse files Browse the repository at this point in the history
Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Aug 23, 2017
1 parent bef6839 commit 4c41fdb
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
- HEALTHCHECK CMD flags
- instructions ([#162](https://github.com/rcjsuen/dockerfile-language-server-nodejs/issues/162))
- ARG
- EXPOSE
- SHELL
- STOPSIGNAL
- USER
Expand Down
5 changes: 5 additions & 0 deletions src/dockerPlainText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class PlainTextDocumentation {
"signatureArg_Signature1_Param1": "The default value of the variable.",
"signatureCopyFlagFrom": "Set the build stage to use as the source location of this copy instruction instead of the build's context.",
"signatureCopyFlagFrom_Param": "The build stage or image name to use as the source. Also may be a numeric index.",
"signatureExpose": "Define network ports for this container to listen on at runtime.",
"signatureExpose_Param0": "The port that this container should listen on.",
"signatureHealthcheck": "Define how Docker should test the container to check that it is still working.",
"signatureShell": "Override default shell used for the shell form of commands.",
"signatureShell_Param1": "The shell executable to use.",
Expand Down Expand Up @@ -191,6 +193,9 @@ export class PlainTextDocumentation {
signatureArg_Signature1_Param1: this.dockerMessages["signatureArg_Signature1_Param1"],
signatureCopyFlagFrom: this.dockerMessages["signatureCopyFlagFrom"],
signatureCopyFlagFrom_Param: this.dockerMessages["signatureCopyFlagFrom_Param"],
signatureExpose: this.dockerMessages["signatureExpose"],
signatureExpose_Param0: this.dockerMessages["signatureExpose_Param0"],
signatureExpose_Param1: this.dockerMessages["signatureExpose_Param0"],
signatureHealthcheck: this.dockerMessages["signatureHealthcheck"],
signatureHealthcheckFlagInterval_Param: this.dockerMessages["hoverHealthcheckFlagInterval"],
signatureHealthcheckFlagRetries_Param: this.dockerMessages["hoverHealthcheckFlagRetries"],
Expand Down
26 changes: 26 additions & 0 deletions src/dockerSignatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@ export class DockerSignatures {
}
}
break;
case "EXPOSE":
let exposeSignatureHelp = {
signatures: [
{
label: "EXPOSE port ...",
documentation: this.documentation.getDocumentation("signatureExpose"),
parameters: [
{
label: "port",
documentation: this.documentation.getDocumentation("signatureExpose_Param0")
},
{
label: "...",
documentation: this.documentation.getDocumentation("signatureExpose_Param1")
}
]
}
],
activeSignature: 0,
activeParameter: 0
};
let exposeArgs = instruction.getArguments();
if (exposeArgs.length > 0 && document.offsetAt(position) > document.offsetAt(exposeArgs[0].getRange().end)) {
exposeSignatureHelp.activeParameter = 1;
}
return exposeSignatureHelp;
case "HEALTHCHECK":
let flags = (instruction as Healthcheck).getFlags();
for (let flag of flags) {
Expand Down
74 changes: 74 additions & 0 deletions test/dockerSignatures.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ function assertArg_NameDefaultValue(signatureHelp: SignatureHelp, activeParamete
assert.equal(signatureHelp.signatures[0].parameters[1].documentation, docs.getDocumentation("signatureArg_Signature1_Param1"));
}

function assertExpose(signatureHelp: SignatureHelp, activeParameter: number) {
assert.equal(signatureHelp.activeSignature, 0);
assert.equal(signatureHelp.activeParameter, activeParameter);
assert.equal(signatureHelp.signatures.length, 1);
assert.equal(signatureHelp.signatures[0].label, "EXPOSE port ...");
assert.notEqual(signatureHelp.signatures[0].documentation, null);
assert.equal(signatureHelp.signatures[0].documentation, docs.getDocumentation("signatureExpose"));
assert.equal(signatureHelp.signatures[0].parameters.length, 2);
assert.equal(signatureHelp.signatures[0].parameters[0].label, "port");
assert.notEqual(signatureHelp.signatures[0].parameters[0].documentation, null);
assert.equal(signatureHelp.signatures[0].parameters[0].documentation, docs.getDocumentation("signatureExpose_Param0"));
assert.equal(signatureHelp.signatures[0].parameters[1].label, "...");
assert.notEqual(signatureHelp.signatures[0].parameters[1].documentation, null);
assert.equal(signatureHelp.signatures[0].parameters[1].documentation, docs.getDocumentation("signatureExpose_Param1"));
}

function assertShell(signatureHelp: SignatureHelp, activeParameter: number) {
assert.equal(signatureHelp.activeSignature, 0);
assert.equal(signatureHelp.activeParameter, activeParameter);
Expand Down Expand Up @@ -403,6 +419,63 @@ describe("Dockerfile Signature Tests", function() {

testCopy(false);

function testExpose(trigger: boolean) {
let onbuild = trigger ? "ONBUILD " : "";
let triggerOffset = trigger ? 8 : 0;

describe("EXPOSE", function() {
it("port", function() {
let signatureHelp = compute(onbuild + "EXPOSE ", 0, triggerOffset + 7);
assertExpose(signatureHelp, 0);

signatureHelp = compute(onbuild + "EXPOSE 8080", 0, triggerOffset + 7);
assertExpose(signatureHelp, 0);

signatureHelp = compute(onbuild + "EXPOSE 8080", 0, triggerOffset + 9);
assertExpose(signatureHelp, 0);

signatureHelp = compute(onbuild + "EXPOSE 8080 ", 0, triggerOffset + 11);
assertExpose(signatureHelp, 0);
});

it("...", function() {
let signatureHelp = compute(onbuild + "EXPOSE 8080 ", 0, triggerOffset + 12);
assertExpose(signatureHelp, 1);

signatureHelp = compute(onbuild + "EXPOSE 8080 8081", 0, triggerOffset + 12);
assertExpose(signatureHelp, 1);

signatureHelp = compute(onbuild + "EXPOSE 8080 8081", 0, triggerOffset + 14);
assertExpose(signatureHelp, 1);

signatureHelp = compute(onbuild + "EXPOSE 8080 8081", 0, triggerOffset + 14);
assertExpose(signatureHelp, 1);

signatureHelp = compute(onbuild + "EXPOSE 8080 8081", 0, triggerOffset + 16);
assertExpose(signatureHelp, 1);

signatureHelp = compute(onbuild + "EXPOSE 8080 8081 ", 0, triggerOffset + 16);
assertExpose(signatureHelp, 1);

signatureHelp = compute(onbuild + "EXPOSE 8080 8081 8082", 0, triggerOffset + 18);
assertExpose(signatureHelp, 1);
});

it("invalid", function() {
let signatureHelp = compute(onbuild + "EXPOSE 8080", 0, triggerOffset + 0);
assertNoSignatures(signatureHelp);

signatureHelp = compute(onbuild + "EXPOSE 8080", 0, triggerOffset + 3);
assertNoSignatures(signatureHelp);

signatureHelp = compute(onbuild + "EXPOSE 8080", 0, triggerOffset + 6);
assertNoSignatures(signatureHelp);
});
});
}

testExpose(false);

function testHealthcheck(trigger: boolean) {
let onbuild = trigger ? "ONBUILD " : "";
let triggerOffset = trigger ? 8 : 0;
Expand Down Expand Up @@ -723,6 +796,7 @@ describe("Dockerfile Signature Tests", function() {
describe("ONBUILD triggers", function() {
testArg(true);
testCopy(true);
testExpose(true);
testHealthcheck(true);
testShell(true);
testStopsignal(true);
Expand Down

0 comments on commit 4c41fdb

Please sign in to comment.