Skip to content

Commit

Permalink
Fix #117 Suggest --start-interval as a completion item
Browse files Browse the repository at this point in the history
--start-interval will now be included in the list of completion items
for HEALTHCHECK instructions.

Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Sep 9, 2023
1 parent 7c4d459 commit c6972a1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- support parsing the new `--keep-git-dir` flag for ADD instructions ([rcjsuen/dockerfile-utils#117](https://github.com/rcjsuen/dockerfile-utils/issues/117))
- support parsing the new `--start-interval` flag for HEALTHCHECK instructions ([rcjsuen/dockerfile-utils#115](https://github.com/rcjsuen/dockerfile-utils/issues/115))
- allow some diagnostics to be ignored if a `# dockerfile-utils: ignore` comment precedes the originating line of the error ([rcjsuen/dockerfile-utils#106](https://github.com/rcjsuen/dockerfile-utils/issues/106))
- suggest the new `--start-interval` flag for HEALTHCHECK instructions when calculating completion items ([#117](https://github.com/rcjsuen/dockerfile-language-service/issues/117))

## [0.10.2] - 2023-06-01
### Fixed
Expand Down
10 changes: 10 additions & 0 deletions src/dockerAssist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ export class DockerAssist {
if ("--retries".indexOf(prefix) === 0) {
items.push(this.createHEALTHCHECK_FlagRetries(prefix.length, offset));
}
if ("--start-interval".indexOf(prefix) === 0) {
items.push(this.createHEALTHCHECK_FlagStartInterval(prefix.length, offset));
}
if ("--start-period".indexOf(prefix) === 0) {
items.push(this.createHEALTHCHECK_FlagStartPeriod(prefix.length, offset));
}
Expand Down Expand Up @@ -775,6 +778,13 @@ export class DockerAssist {
return this.createFlagCompletionItem("--retries=", prefixLength, offset, "--retries=", "HEALTHCHECK_FlagRetries");
}

private createHEALTHCHECK_FlagStartInterval(prefixLength: number, offset: number): CompletionItem {
if (this.snippetSupport) {
return this.createFlagCompletionItem("--start-interval=5s", prefixLength, offset, "--start-interval=${1:5s}", "HEALTHCHECK_FlagStartInterval");
}
return this.createFlagCompletionItem("--start-interval=", prefixLength, offset, "--start-interval=", "HEALTHCHECK_FlagStartInterval");
}

private createHEALTHCHECK_FlagStartPeriod(prefixLength: number, offset: number): CompletionItem {
if (this.snippetSupport) {
return this.createFlagCompletionItem("--start-period=5s", prefixLength, offset, "--start-period=${1:5s}", "HEALTHCHECK_FlagStartPeriod");
Expand Down
5 changes: 5 additions & 0 deletions src/dockerMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class MarkdownDocumentation {
"hoverFromFlagPlatform": "The platform of the image if referencing a multi-platform image.\n\nSince Docker CE 18.04.",
"hoverHealthcheckFlagInterval": "The seconds to wait for the health check to run after the container has started, and then again the number of seconds to wait before running again after the previous check has completed.",
"hoverHealthcheckFlagRetries": "The number of consecutive failures of this health check before the container is considered to be `unhealthy`.",
"hoverHealthcheckFlagStartInterval": "The number of seconds to wait between health checks during the start period.",
"hoverHealthcheckFlagStartPeriod": "The number of seconds to wait for the container to startup. Failures during this grace period will not count towards the maximum number of retries. However, should a health check succeed during this period then any subsequent failures will count towards the maximum number of retries.\n\nSince Docker 17.05.0-ce.",
"hoverHealthcheckFlagTimeout": "The number of seconds to wait for the check to complete before considering it to have failed.",

Expand Down Expand Up @@ -182,6 +183,10 @@ export class MarkdownDocumentation {
contents: this.dockerMessages["hoverHealthcheckFlagRetries"]
},

HEALTHCHECK_FlagStartInterval: {
contents: this.dockerMessages["hoverHealthcheckFlagStartInterval"]
},

HEALTHCHECK_FlagStartPeriod: {
contents: this.dockerMessages["hoverHealthcheckFlagStartPeriod"]
},
Expand Down
3 changes: 3 additions & 0 deletions src/dockerPlainText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class PlainTextDocumentation {
"hoverFromFlagPlatform": "The platform of the image if referencing a multi-platform image.\n\nSince Docker CE 18.04.",
"hoverHealthcheckFlagInterval": "The seconds to wait for the health check to run after the container has started, and then again the number of seconds to wait before running again after the previous check has completed.",
"hoverHealthcheckFlagRetries": "The number of consecutive failures of this health check before the container is considered to be `unhealthy`.",
"hoverHealthcheckFlagStartInterval": "The number of seconds to wait between health checks during the start period.",
"hoverHealthcheckFlagStartPeriod": "The number of seconds to wait for the container to startup. Failures during this grace period will not count towards the maximum number of retries. However, should a health check succeed during this period then any subsequent failures will count towards the maximum number of retries.\n\nSince Docker 17.05.0-ce.",
"hoverHealthcheckFlagTimeout": "The number of seconds to wait for the check to complete before considering it to have failed.",

Expand Down Expand Up @@ -185,6 +186,8 @@ export class PlainTextDocumentation {

HEALTHCHECK_FlagRetries: this.dockerMessages["hoverHealthcheckFlagRetries"],

HEALTHCHECK_FlagStartInterval: this.dockerMessages["hoverHealthcheckFlagStartInterval"],

HEALTHCHECK_FlagStartPeriod: this.dockerMessages["hoverHealthcheckFlagStartPeriod"],

HEALTHCHECK_FlagTimeout: this.dockerMessages["hoverHealthcheckFlagTimeout"],
Expand Down
48 changes: 40 additions & 8 deletions test/dockerAssist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,30 @@ function assertHEALTHCHECK_FlagInterval(item: CompletionItem, startLine: number,
assertResolvedDocumentation(item);
}

function assertHEALTHCHECK_FlagStartInterval(item: CompletionItem, startLine: number, startCharacter: number, endLine: number, endCharacter: number, snippetSupport?: boolean) {
if (snippetSupport === undefined || snippetSupport) {
assert.strictEqual(item.label, "--start-interval=5s");
} else {
assert.strictEqual(item.label, "--start-interval=");
}
assert.strictEqual(item.kind, CompletionItemKind.Field);
if (snippetSupport === undefined || snippetSupport) {
assert.strictEqual(item.insertTextFormat, InsertTextFormat.Snippet);
assert.strictEqual(item.textEdit.newText, "--start-interval=${1:5s}");
} else {
assert.strictEqual(item.insertTextFormat, InsertTextFormat.PlainText);
assert.strictEqual(item.textEdit.newText, "--start-interval=");
}
assert.strictEqual(item.data, "HEALTHCHECK_FlagStartInterval");
assert.strictEqual(item.deprecated, undefined);
assert.strictEqual(item.documentation, undefined);
assert.strictEqual((item.textEdit as TextEdit).range.start.line, startLine);
assert.strictEqual((item.textEdit as TextEdit).range.start.character, startCharacter);
assert.strictEqual((item.textEdit as TextEdit).range.end.line, endLine);
assert.strictEqual((item.textEdit as TextEdit).range.end.character, endCharacter);
assertResolvedDocumentation(item);
}

function assertHEALTHCHECK_FlagTimeout(item: CompletionItem, startLine: number, startCharacter: number, endLine: number, endCharacter: number, snippetSupport?: boolean) {
if (snippetSupport === undefined || snippetSupport) {
assert.strictEqual(item.label, "--timeout=30s");
Expand Down Expand Up @@ -1056,36 +1080,40 @@ function assertFromFlags(items: CompletionItem[], startLine: number, startCharac
}

function assertHealthcheckItems(items: CompletionItem[], startLine: number, startCharacter: number, endLine: number, endCharacter: number, snippetSupport?: boolean) {
assert.strictEqual(items.length, 6);
assert.strictEqual(items.length, 7);
// CMD and NONE first
assertHEALTHCHECK_CMD_Subcommand(items[0], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_NONE_Subcommand(items[1], startLine, startCharacter, endLine, endCharacter);
// flags in alphabetical order next
assertHEALTHCHECK_FlagInterval(items[2], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagRetries(items[3], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagStartPeriod(items[4], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagTimeout(items[5], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagStartInterval(items[4], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagStartPeriod(items[5], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagTimeout(items[6], startLine, startCharacter, endLine, endCharacter, snippetSupport);

assert.strictEqual(items[0].sortText, "0");
assert.strictEqual(items[1].sortText, "1");
assert.strictEqual(items[2].sortText, "2");
assert.strictEqual(items[3].sortText, "3");
assert.strictEqual(items[4].sortText, "4");
assert.strictEqual(items[5].sortText, "5");
assert.strictEqual(items[6].sortText, "6");
}

function assertHealthcheckFlags(items: CompletionItem[], startLine: number, startCharacter: number, endLine: number, endCharacter: number, snippetSupport?: boolean) {
assert.strictEqual(items.length, 4);
assert.strictEqual(items.length, 5);
// alphabetical order
assertHEALTHCHECK_FlagInterval(items[0], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagRetries(items[1], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagStartPeriod(items[2], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagTimeout(items[3], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagStartInterval(items[2], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagStartPeriod(items[3], startLine, startCharacter, endLine, endCharacter, snippetSupport);
assertHEALTHCHECK_FlagTimeout(items[4], startLine, startCharacter, endLine, endCharacter, snippetSupport);

assert.strictEqual(items[0].sortText, "0");
assert.strictEqual(items[1].sortText, "1");
assert.strictEqual(items[2].sortText, "2");
assert.strictEqual(items[3].sortText, "3");
assert.strictEqual(items[4].sortText, "4");
}

function assertONBUILDProposals(proposals: CompletionItem[], offset: number, prefix: number, prefixLength: number) {
Expand Down Expand Up @@ -2622,9 +2650,13 @@ describe('Docker Content Assist Tests', function () {
assert.strictEqual(items.length, 1);
assertHEALTHCHECK_FlagRetries(items[0], 1, triggerOffset + 12, 1, triggerOffset + 17, snippetSupport);

items = computePosition("FROM busybox\n" + onbuild + "HEALTHCHECK --start", 1, triggerOffset + 19, snippetSupport);
items = computePosition("FROM busybox\n" + onbuild + "HEALTHCHECK --start-i", 1, triggerOffset + 21, snippetSupport);
assert.strictEqual(items.length, 1);
assertHEALTHCHECK_FlagStartInterval(items[0], 1, triggerOffset + 12, 1, triggerOffset + 21, snippetSupport);

items = computePosition("FROM busybox\n" + onbuild + "HEALTHCHECK --start-p", 1, triggerOffset + 21, snippetSupport);
assert.strictEqual(items.length, 1);
assertHEALTHCHECK_FlagStartPeriod(items[0], 1, triggerOffset + 12, 1, triggerOffset + 19, snippetSupport);
assertHEALTHCHECK_FlagStartPeriod(items[0], 1, triggerOffset + 12, 1, triggerOffset + 21, snippetSupport);

items = computePosition("FROM busybox\n" + onbuild + "HEALTHCHECK --time", 1, triggerOffset + 18, snippetSupport);
assert.strictEqual(items.length, 1);
Expand Down

0 comments on commit c6972a1

Please sign in to comment.