Skip to content

Commit 95c618b

Browse files
authored
Add check for validating cfn-lint version (#360)
* Add check for validating cfn-lint version * Update variable names to be camelCase
1 parent d2d8569 commit 95c618b

File tree

9 files changed

+355
-35
lines changed

9 files changed

+355
-35
lines changed

client/package-lock.json

Lines changed: 17 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
},
2525
"dependencies": {
2626
"@types/lodash": "^4.14.202",
27-
"@types/semver": "^7.5.6",
2827
"lodash": "^4.17.21",
2928
"node-yaml-parser": "^0.0.9",
30-
"semver": "^7.5.4",
31-
"vscode-languageclient": "~8.1.0",
29+
"vscode-languageclient": "~9.0.1",
3230
"vscode-uri": "^3.0.8"
3331
}
3432
}

client/src/extension.ts

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License").
55
You may not use this file except in compliance with the License.
66
A copy of the License is located at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
1010
or in the "license" file accompanying this file. This file is distributed
1111
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
@@ -31,6 +31,12 @@ import {
3131
LanguageClientOptions,
3232
ServerOptions,
3333
TransportKind,
34+
ErrorHandler,
35+
Message,
36+
ErrorAction,
37+
CloseAction,
38+
CloseHandlerResult,
39+
ErrorHandlerResult,
3440
} from "vscode-languageclient/node";
3541

3642
let previews: { [index: string]: WebviewPanel } = {};
@@ -63,14 +69,14 @@ export async function activate(context: ExtensionContext) {
6369
{ scheme: "file", language: "json" },
6470
],
6571
synchronize: {
66-
// Synchronize the setting section 'languageServerExample' to the server
6772
configurationSection: "cfnLint",
6873
// Notify the server about file changes to '.clientrc files contain in the workspace
6974
fileEvents: [
7075
workspace.createFileSystemWatcher("**/.clientrc"),
7176
workspace.createFileSystemWatcher("**/*.?(e)y?(a)ml"),
7277
],
7378
},
79+
errorHandler: new ClientErrorHandler(4),
7480
};
7581

7682
// Create the language client and start the client.
@@ -100,6 +106,14 @@ export async function activate(context: ExtensionContext) {
100106
}
101107
});
102108

109+
languageClient.onNotification("cfn/cfnLintUpgradeNeeded", (params) => {
110+
window.showInformationMessage(
111+
`You are using an outdated version of cfn-lint (${params["cli_version"]}). The latest version is ${params["latest_version"]}.`
112+
);
113+
});
114+
115+
languageClient.sendNotification("cfn/validateCfnLintVersion");
116+
103117
let previewDisposable = commands.registerCommand(
104118
"extension.sidePreview",
105119
() => {
@@ -177,3 +191,52 @@ export function deactivate(): Thenable<void> | undefined {
177191
}
178192
return languageClient.stop();
179193
}
194+
195+
export class ClientErrorHandler implements ErrorHandler {
196+
private restarts: number[] = [];
197+
constructor(private readonly maxRestartCount: number) {}
198+
199+
//@ts-ignore
200+
error(error: Error, message: Message, count: number): ErrorHandlerResult {
201+
if (count && count <= 3) {
202+
return {
203+
action: ErrorAction.Continue,
204+
message: error.message,
205+
handled: true,
206+
};
207+
}
208+
return {
209+
action: ErrorAction.Shutdown,
210+
message: error.message,
211+
handled: true,
212+
};
213+
}
214+
215+
closed(): CloseHandlerResult {
216+
this.restarts.push(Date.now());
217+
if (this.restarts.length <= this.maxRestartCount) {
218+
return {
219+
action: CloseAction.Restart,
220+
message: "Restarting cfn-lint extension",
221+
};
222+
} else {
223+
const diff = this.restarts[this.restarts.length - 1] - this.restarts[0];
224+
if (diff <= 3 * 60 * 1000) {
225+
const message = `The cfn-lint server crashed ${
226+
this.maxRestartCount + 1
227+
} times in the last 3 minutes. The server will not be restarted.`;
228+
window.showErrorMessage(message);
229+
return {
230+
action: CloseAction.DoNotRestart,
231+
message: message,
232+
};
233+
} else {
234+
this.restarts.shift();
235+
return {
236+
action: CloseAction.Restart,
237+
message: "Restart cfn-lint extension",
238+
};
239+
}
240+
}
241+
}
242+
}

client/src/test/runTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function main() {
1212
// Passed to --extensionTestsPath
1313
const extensionTestsPath = path.resolve(__dirname, "./suite/index");
1414

15-
const vscodeExecutablePath = await downloadAndUnzipVSCode("1.77.1");
15+
const vscodeExecutablePath = await downloadAndUnzipVSCode("1.85.0");
1616

1717
// Download VS Code, unzip it and run the integration test
1818
await runTests({

0 commit comments

Comments
 (0)