Skip to content

Commit

Permalink
Add check for validating cfn-lint version (#360)
Browse files Browse the repository at this point in the history
* Add check for validating cfn-lint version
* Update variable names to be camelCase
  • Loading branch information
kddejong authored Dec 13, 2023
1 parent d2d8569 commit 95c618b
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 35 deletions.
41 changes: 17 additions & 24 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
},
"dependencies": {
"@types/lodash": "^4.14.202",
"@types/semver": "^7.5.6",
"lodash": "^4.17.21",
"node-yaml-parser": "^0.0.9",
"semver": "^7.5.4",
"vscode-languageclient": "~8.1.0",
"vscode-languageclient": "~9.0.1",
"vscode-uri": "^3.0.8"
}
}
67 changes: 65 additions & 2 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
A copy of the License is located at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
or in the "license" file accompanying this file. This file is distributed
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
Expand All @@ -31,6 +31,12 @@ import {
LanguageClientOptions,
ServerOptions,
TransportKind,
ErrorHandler,
Message,
ErrorAction,
CloseAction,
CloseHandlerResult,
ErrorHandlerResult,
} from "vscode-languageclient/node";

let previews: { [index: string]: WebviewPanel } = {};
Expand Down Expand Up @@ -63,14 +69,14 @@ export async function activate(context: ExtensionContext) {
{ scheme: "file", language: "json" },
],
synchronize: {
// Synchronize the setting section 'languageServerExample' to the server
configurationSection: "cfnLint",
// Notify the server about file changes to '.clientrc files contain in the workspace
fileEvents: [
workspace.createFileSystemWatcher("**/.clientrc"),
workspace.createFileSystemWatcher("**/*.?(e)y?(a)ml"),
],
},
errorHandler: new ClientErrorHandler(4),
};

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

languageClient.onNotification("cfn/cfnLintUpgradeNeeded", (params) => {
window.showInformationMessage(
`You are using an outdated version of cfn-lint (${params["cli_version"]}). The latest version is ${params["latest_version"]}.`
);
});

languageClient.sendNotification("cfn/validateCfnLintVersion");

let previewDisposable = commands.registerCommand(
"extension.sidePreview",
() => {
Expand Down Expand Up @@ -177,3 +191,52 @@ export function deactivate(): Thenable<void> | undefined {
}
return languageClient.stop();
}

export class ClientErrorHandler implements ErrorHandler {
private restarts: number[] = [];
constructor(private readonly maxRestartCount: number) {}

//@ts-ignore
error(error: Error, message: Message, count: number): ErrorHandlerResult {
if (count && count <= 3) {
return {
action: ErrorAction.Continue,
message: error.message,
handled: true,
};
}
return {
action: ErrorAction.Shutdown,
message: error.message,
handled: true,
};
}

closed(): CloseHandlerResult {
this.restarts.push(Date.now());
if (this.restarts.length <= this.maxRestartCount) {
return {
action: CloseAction.Restart,
message: "Restarting cfn-lint extension",
};
} else {
const diff = this.restarts[this.restarts.length - 1] - this.restarts[0];
if (diff <= 3 * 60 * 1000) {
const message = `The cfn-lint server crashed ${
this.maxRestartCount + 1
} times in the last 3 minutes. The server will not be restarted.`;
window.showErrorMessage(message);
return {
action: CloseAction.DoNotRestart,
message: message,
};
} else {
this.restarts.shift();
return {
action: CloseAction.Restart,
message: "Restart cfn-lint extension",
};
}
}
}
}
2 changes: 1 addition & 1 deletion client/src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function main() {
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, "./suite/index");

const vscodeExecutablePath = await downloadAndUnzipVSCode("1.77.1");
const vscodeExecutablePath = await downloadAndUnzipVSCode("1.85.0");

// Download VS Code, unzip it and run the integration test
await runTests({
Expand Down
Loading

0 comments on commit 95c618b

Please sign in to comment.