Skip to content

Commit e5f98b7

Browse files
authored
Update dependencies (#226)
* Release v0.21.0 * Npm update to increase our dependencies * Update package versions 2022/07/12 * Update major version of dependencies to keep modern * Improve testing
1 parent cb52cac commit e5f98b7

File tree

16 files changed

+4054
-4995
lines changed

16 files changed

+4054
-4995
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
},
1414
"ignorePatterns": ["server/node_modules/", "client/node_modules/"],
1515
"rules": {
16-
"@typescript-eslint/class-name-casing": "warn",
16+
"@typescript-eslint/naming-convention": "warn",
1717
"@typescript-eslint/member-delimiter-style": [
1818
"warn",
1919
{

.vscode/launch.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"args": [
1010
"--extensionDevelopmentPath=${workspaceRoot}"
1111
],
12+
"env": {
13+
"PATH": "${env:PATH}"
14+
},
1215
"stopOnEntry": false,
1316
"sourceMaps": true,
1417
"outFiles": [

client/package-lock.json

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

client/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
"scripts": {},
1919
"devDependencies": {
2020
"@types/glob": "^7.1.3",
21-
"@types/vscode": "1.52.0",
22-
"mocha": "^6.2.3",
23-
"vscode-test": "^1.5.1"
21+
"@types/vscode": "1.69.0",
22+
"mocha": "^10.0.0",
23+
"@vscode/test-electron": "^2.1.5"
2424
},
2525
"dependencies": {
2626
"@types/lodash": "^4.14.168",
2727
"@types/semver": "^5.5.0",
2828
"lodash": "^4.17.21",
2929
"node-yaml-parser": "~0.0.9",
30-
"semver": "^5.5.1",
31-
"vscode-languageclient": "~5.2.1",
32-
"vscode-uri": "^1.0.1"
30+
"semver": "^7.3.7",
31+
"vscode-languageclient": "~8.0.1",
32+
"vscode-uri": "^3.0.3"
3333
}
3434
}

client/src/extension.ts

Lines changed: 38 additions & 35 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
@@ -17,12 +17,13 @@ permissions and limitations under the License.
1717
import * as path from 'path';
1818
import * as fs from 'fs';
1919
import { workspace, ExtensionContext, ConfigurationTarget, window, WebviewPanel, Uri, commands, ViewColumn, window as VsCodeWindow } from 'vscode';
20-
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient';
20+
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node';
2121
import { registerYamlSchemaSupport } from './yaml-support/yaml-schema';
2222

2323
let previews: { [index: string]: WebviewPanel } = {};
24+
let languageClient: LanguageClient;
2425

25-
export function activate(context: ExtensionContext) {
26+
export async function activate(context: ExtensionContext) {
2627

2728
// The server is implemented in node
2829
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'server.js'));
@@ -93,45 +94,40 @@ export function activate(context: ExtensionContext) {
9394
}
9495

9596
// Create the language client and start the client.
96-
let languageClient = new LanguageClient('cfnLint', 'CloudFormation linter Language Server', serverOptions, clientOptions);
97-
let clientDisposable = languageClient.start();
97+
languageClient = new LanguageClient('cfnLint', 'CloudFormation linter Language Server', serverOptions, clientOptions);
98+
await languageClient.start();
9899

99-
languageClient.onReady().then(() => {
100-
languageClient.onNotification('cfn/busy', () => {
101-
window.showInformationMessage("Linter is already running. Please try again.");
102-
});
103-
languageClient.onNotification('cfn/previewIsAvailable', (uri) => {
104-
reloadSidePreview(uri, languageClient);
105-
});
106-
languageClient.onNotification('cfn/isPreviewable', (value) => {
107-
commands.executeCommand('setContext', 'isPreviewable', value);
108-
});
109-
languageClient.onNotification('cfn/fileclosed', (uri) => {
110-
// if the user closed the template itself, we close the preview
111-
if (previews[uri]) {
112-
previews[uri].dispose();
113-
}
114-
});
115-
116-
let previewDisposable = commands.registerCommand('extension.sidePreview', () => {
100+
languageClient.onNotification('cfn/busy', () => {
101+
window.showInformationMessage("Linter is already running. Please try again.");
102+
});
103+
languageClient.onNotification('cfn/previewIsAvailable', (uri) => {
104+
reloadSidePreview(uri, languageClient);
105+
});
106+
languageClient.onNotification('cfn/isPreviewable', (value) => {
107+
commands.executeCommand('setContext', 'isPreviewable', value);
108+
});
109+
languageClient.onNotification('cfn/fileclosed', (uri) => {
110+
// if the user closed the template itself, we close the preview
111+
if (previews[uri]) {
112+
previews[uri].dispose();
113+
}
114+
});
117115

118-
if (window.activeTextEditor.document) {
119-
let uri = Uri.file(window.activeTextEditor.document.fileName).toString();
116+
let previewDisposable = commands.registerCommand('extension.sidePreview', () => {
120117

121-
languageClient.sendNotification('cfn/requestPreview', uri);
122-
}
118+
if (window.activeTextEditor.document) {
119+
let uri = Uri.file(window.activeTextEditor.document.fileName).toString();
123120

124-
});
121+
languageClient.sendNotification('cfn/requestPreview', uri);
122+
}
125123

126-
context.subscriptions.push(previewDisposable);
127124
});
128125

129-
// Push the disposable to the context's subscriptions so that the
130-
// client can be deactivated on extension deactivation
131-
context.subscriptions.push(clientDisposable);
126+
context.subscriptions.push(previewDisposable);
127+
132128
}
133129

134-
function reloadSidePreview(file:string, languageClient:LanguageClient) {
130+
function reloadSidePreview(file: string, languageClient: LanguageClient) {
135131
let uri = Uri.parse(file);
136132
let stringifiedUri = uri.toString();
137133
let dotFile = uri.fsPath + ".dot";
@@ -145,7 +141,7 @@ function reloadSidePreview(file:string, languageClient:LanguageClient) {
145141
if (!previews[stringifiedUri]) {
146142
previews[stringifiedUri] = VsCodeWindow.createWebviewPanel(
147143
'cfnLintPreview', // Identifies the type of the webview. Used internally
148-
'Template: ' + dotFile.slice(0,-4), // Title of the panel displayed to the user
144+
'Template: ' + dotFile.slice(0, -4), // Title of the panel displayed to the user
149145
ViewColumn.Two, // Editor column to show the new webview panel in.
150146
{
151147
enableScripts: true,
@@ -163,7 +159,7 @@ function reloadSidePreview(file:string, languageClient:LanguageClient) {
163159
panel.webview.html = getPreviewContent(content);
164160
}
165161

166-
function getPreviewContent(content: String) : string {
162+
function getPreviewContent(content: String): string {
167163

168164
let multilineString = "`" + content + "`";
169165
// FIXME is there a better way of converting from dot to svg that is not using cdn urls?
@@ -207,4 +203,11 @@ export async function yamlLangaugeServerValidation(): Promise<void> {
207203
workspace.getConfiguration().update('yaml.validate', false, ConfigurationTarget.Global);
208204
}
209205
}
206+
}
207+
208+
export function deactivate(): Thenable<void> | undefined {
209+
if (!languageClient) {
210+
return undefined;
211+
}
212+
return languageClient.stop();
210213
}

client/src/test/runTest.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as path from 'path';
2-
import { runTests } from 'vscode-test';
2+
import * as cp from 'child_process';
3+
import * as os from "os";
4+
import { downloadAndUnzipVSCode,
5+
resolveCliArgsFromVSCodeExecutablePath,
6+
runTests,
7+
} from '@vscode/test-electron';
38

49
async function main() {
510
try {
@@ -11,13 +16,11 @@ async function main() {
1116
// Passed to --extensionTestsPath
1217
const extensionTestsPath = path.resolve(__dirname, './suite/index');
1318

14-
const cp = require('child_process');
15-
const { downloadAndUnzipVSCode, resolveCliPathFromVSCodeExecutablePath } = require('vscode-test');
16-
const vscodeExecutablePath = await downloadAndUnzipVSCode('1.61.0');
17-
const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath);
19+
const vscodeExecutablePath = await downloadAndUnzipVSCode('1.69.1');
20+
const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
1821

1922
// Use cp.spawn / cp.exec for custom setup
20-
cp.spawnSync(cliPath, ['--install-extension', 'redhat.vscode-yaml'], {
23+
cp.spawnSync(cli, [...args, '--install-extension', 'redhat.vscode-yaml'], {
2124
encoding: 'utf-8',
2225
stdio: 'inherit'
2326
});
@@ -27,9 +30,10 @@ async function main() {
2730
vscodeExecutablePath,
2831
extensionDevelopmentPath,
2932
extensionTestsPath,
33+
launchArgs: ['--user-data-dir', `${os.tmpdir()}`],
3034
});
3135
} catch (err) {
32-
console.error('Failed to run tests');
36+
console.error(`Failed to run tests: ${err}`);
3337
process.exit(1);
3438
}
3539
}

client/src/test/suite/cfnlint.test.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@
22
import * as vscode from 'vscode';
33
import * as assert from 'assert';
44
import * as fs from 'fs';
5-
import { getDocUri, activate, activateAndPreview, getDocPath } from './helper';
5+
import { getDocUri, activate, activateAndPreview, getDocPath, sleep, testDiagnostics } from './helper';
66

7-
suite('A test to create some better spacing for activation', () => {
8-
const docUri = getDocUri('good.yaml');
9-
10-
test('A more elaborate sleep', async () => {
11-
await activate(docUri);
12-
13-
const actualDiagnostics = vscode.languages.getDiagnostics(docUri);
14-
console.log(actualDiagnostics);
15-
});
16-
});
177

188
suite('Should have failures with a bad template', () => {
199
const docUri = getDocUri('bad.yaml');
2010

2111
test('Diagnose bad template', async () => {
12+
await activate(docUri);
13+
await sleep(2000); // Wait for the diagnostics to compute on this file
14+
2215
await testDiagnostics(docUri, [
2316
{
2417
severity: vscode.DiagnosticSeverity.Error,
@@ -43,6 +36,8 @@ suite('Should not have failures on a good template', () => {
4336
const docUri = getDocUri('good.yaml');
4437

4538
test('Diagnose good template', async () => {
39+
await activate(docUri);
40+
await sleep(2000); // Wait for the diagnostics to compute on this file
4641
await testDiagnostics(docUri, []);
4742
});
4843
});
@@ -51,6 +46,8 @@ suite('Should not have failures a non CloudFormation Template', () => {
5146
const docUri = getDocUri('not_template.yaml');
5247

5348
test('Diagnose good template', async () => {
49+
await activate(docUri);
50+
await sleep(2000); // Wait for the diagnostics to compute on this file
5451
await testDiagnostics(docUri, []);
5552
});
5653
});
@@ -59,6 +56,8 @@ suite('Should have failures even though AWSTemplateFormatVersion isn\'t in the f
5956
const docUri = getDocUri('still_a_template.yaml');
6057

6158
test('Diagnoses a bad template without AWSTemplateFormatVersion', async () => {
59+
await activate(docUri);
60+
await sleep(2000); // Wait for the diagnostics to compute on this file
6261
await testDiagnostics(docUri, [
6362
{
6463
severity: vscode.DiagnosticSeverity.Error,
@@ -73,6 +72,8 @@ suite('Should have failures even though AWSTemplateFormatVersion isn\'t in the f
7372
const docUri = getDocUri('still_a_template_2.yaml');
7473

7574
test('Diagnoses a bad template without AWSTemplateFormatVersion', async () => {
75+
await activate(docUri);
76+
await sleep(2000); // Wait for the diagnostics to compute on this file
7677
await testDiagnostics(docUri, [
7778
{
7879
severity: vscode.DiagnosticSeverity.Error,
@@ -87,6 +88,8 @@ suite('Should have failures even with a space in the filename', () => {
8788
const docUri = getDocUri('a template.yaml');
8889

8990
test('Diagnoses a bad template with spaces in the name', async () => {
91+
await activate(docUri);
92+
await sleep(2000); // Wait for the diagnostics to compute on this file
9093
await testDiagnostics(docUri, [
9194
{
9295
severity: vscode.DiagnosticSeverity.Error,
@@ -123,17 +126,3 @@ function toRange(sLine: number, sChar: number, eLine: number, eChar: number) {
123126
return new vscode.Range(start, end);
124127
}
125128

126-
async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) {
127-
await activate(docUri);
128-
129-
const actualDiagnostics = vscode.languages.getDiagnostics(docUri);
130-
assert.equal(actualDiagnostics.length, expectedDiagnostics.length);
131-
132-
expectedDiagnostics.forEach((expectedDiagnostic, i) => {
133-
const actualDiagnostic = actualDiagnostics[i];
134-
assert.equal(actualDiagnostic.message, expectedDiagnostic.message);
135-
assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range);
136-
assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity);
137-
});
138-
}
139-

client/src/test/suite/helper.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* ------------------------------------------------------------------------------------------ */
55

66
import * as vscode from 'vscode';
7+
import * as assert from 'assert';
78
import * as path from 'path';
89

910
export let doc: vscode.TextDocument;
@@ -14,20 +15,29 @@ export let platformEol: string;
1415
/**
1516
* Activates the kddejong.vscode-cfn-lint extension
1617
*/
17-
export async function activate(docUri: vscode.Uri) {
18-
const ext = vscode.extensions.getExtension('kddejong.vscode-cfn-lint')!;
19-
await ext.activate();
20-
await vscode.workspace.getConfiguration().update('yaml.validate', false, vscode.ConfigurationTarget.Global);
18+
export async function activate(docUri: vscode.Uri): Promise<any> {
19+
const extension = vscode.extensions.getExtension("kddejong.vscode-cfn-lint");
20+
const activation = await extension?.activate();
21+
2122
try {
2223
doc = await vscode.workspace.openTextDocument(docUri);
23-
editor = await vscode.window.showTextDocument(doc);
24-
await sleep(4000); // Wait for server activation
24+
editor = await vscode.window.showTextDocument(doc, {
25+
preview: true,
26+
preserveFocus: false,
27+
});
28+
29+
await reinitializeExtension();
30+
return activation;
2531
} catch (e) {
26-
console.error(e);
27-
throw(e);
32+
console.error("Error from activation -> ", e);
2833
}
2934
}
3035

36+
async function reinitializeExtension(): Promise<void> {
37+
await vscode.languages.setTextDocumentLanguage(doc, 'yaml');
38+
await sleep(20000); // Wait for server activation
39+
}
40+
3141
export async function activateAndPreview(docUri: vscode.Uri) {
3242
await activate(docUri);
3343

@@ -36,13 +46,14 @@ export async function activateAndPreview(docUri: vscode.Uri) {
3646
await sleep(4000); // Wait for preview to become available
3747
}
3848

39-
async function sleep(ms: number) {
49+
export async function sleep(ms: number) {
4050
return new Promise(resolve => setTimeout(resolve, ms));
4151
}
4252

4353
export const getDocPath = (p: string) => {
4454
return path.resolve(__dirname, '../../../src/test/suite/fixtures', p);
4555
};
56+
4657
export const getDocUri = (p: string) => {
4758
return vscode.Uri.file(getDocPath(p));
4859
};
@@ -53,4 +64,20 @@ export async function setTestContent(content: string): Promise<boolean> {
5364
doc.positionAt(doc.getText().length)
5465
);
5566
return editor.edit(eb => eb.replace(all, content));
56-
}
67+
}
68+
69+
export async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) {
70+
await activate(docUri);
71+
72+
const actualDiagnostics = vscode.languages.getDiagnostics(docUri);
73+
74+
assert.equal(actualDiagnostics.length, expectedDiagnostics.length);
75+
76+
expectedDiagnostics.forEach((expectedDiagnostic, i) => {
77+
const actualDiagnostic = actualDiagnostics[i];
78+
assert.equal(actualDiagnostic.message, expectedDiagnostic.message);
79+
assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range);
80+
assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity);
81+
});
82+
}
83+

0 commit comments

Comments
 (0)