Skip to content

Commit f07127f

Browse files
authored
Convert to using yaml-language-server as a library (#228)
1 parent 8345e77 commit f07127f

37 files changed

+4367
-3545
lines changed

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"name": "Launch Extension",
88
"runtimeExecutable": "${execPath}",
99
"args": [
10+
"--disable-extensions",
1011
"--extensionDevelopmentPath=${workspaceRoot}"
1112
],
1213
"env": {

client/src/extension.ts

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ permissions and limitations under the License.
1616

1717
import * as path from 'path';
1818
import * as fs from 'fs';
19-
import { workspace, ExtensionContext, ConfigurationTarget, window, WebviewPanel, Uri, commands, ViewColumn, window as VsCodeWindow } from 'vscode';
19+
import { workspace, ExtensionContext, window, WebviewPanel, Uri, commands, ViewColumn, window as VsCodeWindow } from 'vscode';
2020
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node';
21-
import { registerYamlSchemaSupport } from './yaml-support/yaml-schema';
2221

2322
let previews: { [index: string]: WebviewPanel } = {};
2423
let languageClient: LanguageClient;
@@ -41,58 +40,20 @@ export async function activate(context: ExtensionContext) {
4140
let clientOptions: LanguageClientOptions = {
4241
// Register the server for plain text documents
4342
documentSelector: [
44-
{ scheme: 'file', language: 'yaml' },
45-
{ scheme: 'file', language: 'json' }
43+
{ scheme: 'file', language: 'yaml'},
44+
{ scheme: 'file', language: 'json'},
4645
],
4746
synchronize: {
4847
// Synchronize the setting section 'languageServerExample' to the server
4948
configurationSection: 'cfnLint',
5049
// Notify the server about file changes to '.clientrc files contain in the workspace
51-
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
50+
fileEvents: [
51+
workspace.createFileSystemWatcher('**/.clientrc'),
52+
workspace.createFileSystemWatcher('**/*.?(e)y?(a)ml'),
53+
]
5254
}
5355
};
5456

55-
let enableAutocomplete: boolean = workspace.getConfiguration().get('cfnLint.enableAutocomplete');
56-
if (enableAutocomplete) {
57-
let currentTags: Array<string> = workspace.getConfiguration().get('yaml.customTags');
58-
let cloudFormationTags = [
59-
"!And",
60-
"!And sequence",
61-
"!If",
62-
"!If sequence",
63-
"!Not",
64-
"!Not sequence",
65-
"!Equals",
66-
"!Equals sequence",
67-
"!Or",
68-
"!Or sequence",
69-
"!FindInMap",
70-
"!FindInMap sequence",
71-
"!Base64",
72-
"!Join",
73-
"!Join sequence",
74-
"!Cidr",
75-
"!Ref",
76-
"!Sub",
77-
"!Sub sequence",
78-
"!GetAtt",
79-
"!GetAZs",
80-
"!ImportValue",
81-
"!ImportValue sequence",
82-
"!Select",
83-
"!Select sequence",
84-
"!Split",
85-
"!Split sequence"
86-
];
87-
let updateTags = currentTags.concat(cloudFormationTags.filter((item) => currentTags.indexOf(item) < 0));
88-
89-
workspace.getConfiguration().update('yaml.customTags', updateTags, ConfigurationTarget.Global);
90-
91-
yamlLangaugeServerValidation();
92-
93-
registerYamlSchemaSupport();
94-
}
95-
9657
// Create the language client and start the client.
9758
languageClient = new LanguageClient('cfnLint', 'CloudFormation linter Language Server', serverOptions, clientOptions);
9859
await languageClient.start();
@@ -181,30 +142,6 @@ function getPreviewContent(content: String): string {
181142
`;
182143
}
183144

184-
export async function yamlLangaugeServerValidation(): Promise<void> {
185-
let validateYaml: boolean = workspace.getConfiguration().get('yaml.validate');
186-
let cfnValidateYamlInspect = workspace.getConfiguration().inspect('cfnLint.validateUsingJsonSchema');
187-
let cfnValidateYaml: boolean = workspace.getConfiguration().get('cfnLint.validateUsingJsonSchema');
188-
189-
if (validateYaml) {
190-
if (cfnValidateYamlInspect.globalValue === null || cfnValidateYamlInspect.workspaceFolderValue === null || cfnValidateYamlInspect.workspaceValue === null) {
191-
let selection: string = await window
192-
.showInformationMessage('The installed Red Hat YAML extension is also configured to validate YAML templates. This may result in duplicate lint errors with cfn-lint. Disabling the YAML extensions validation will disable it completely. Would you like to only use cfn-lint to lint CloudFormation templates?',
193-
...['yes', 'no']);
194-
if (selection === 'yes') {
195-
workspace.getConfiguration().update('cfnLint.validateUsingJsonSchema', false, ConfigurationTarget.Global);
196-
} else if (selection === 'no') {
197-
workspace.getConfiguration().update('cfnLint.validateUsingJsonSchema', true, ConfigurationTarget.Global);
198-
cfnValidateYaml = true;
199-
}
200-
201-
}
202-
if (cfnValidateYaml === false) {
203-
workspace.getConfiguration().update('yaml.validate', false, ConfigurationTarget.Global);
204-
}
205-
}
206-
}
207-
208145
export function deactivate(): Thenable<void> | undefined {
209146
if (!languageClient) {
210147
return undefined;

client/src/test/runTest.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as path from 'path';
2-
import * as cp from 'child_process';
32
import * as os from "os";
43
import { downloadAndUnzipVSCode,
5-
resolveCliArgsFromVSCodeExecutablePath,
64
runTests,
75
} from '@vscode/test-electron';
86

@@ -17,20 +15,13 @@ async function main() {
1715
const extensionTestsPath = path.resolve(__dirname, './suite/index');
1816

1917
const vscodeExecutablePath = await downloadAndUnzipVSCode('1.69.1');
20-
const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
21-
22-
// Use cp.spawn / cp.exec for custom setup
23-
cp.spawnSync(cli, [...args, '--install-extension', 'redhat.vscode-yaml'], {
24-
encoding: 'utf-8',
25-
stdio: 'inherit'
26-
});
2718

2819
// Download VS Code, unzip it and run the integration test
2920
await runTests({
3021
vscodeExecutablePath,
3122
extensionDevelopmentPath,
3223
extensionTestsPath,
33-
launchArgs: ['--user-data-dir', `${os.tmpdir()}`],
24+
launchArgs: ['--disable-extensions', '--user-data-dir', `${os.tmpdir()}`],
3425
});
3526
} catch (err) {
3627
console.error(`Failed to run tests: ${err}`);

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

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)