Skip to content

Commit

Permalink
Convert to using yaml-language-server as a library
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Aug 6, 2022
1 parent 8345e77 commit 40e8716
Show file tree
Hide file tree
Showing 37 changed files with 4,379 additions and 3,544 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"name": "Launch Extension",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceRoot}"
],
"env": {
Expand Down
77 changes: 7 additions & 70 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ permissions and limitations under the License.

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

let previews: { [index: string]: WebviewPanel } = {};
let languageClient: LanguageClient;
Expand All @@ -41,58 +40,20 @@ export async function activate(context: ExtensionContext) {
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [
{ scheme: 'file', language: 'yaml' },
{ scheme: 'file', language: 'json' }
{ scheme: 'file', language: 'yaml'},
{ 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')
fileEvents: [
workspace.createFileSystemWatcher('**/.clientrc'),
workspace.createFileSystemWatcher('**/*.?(e)y?(a)ml'),
]
}
};

let enableAutocomplete: boolean = workspace.getConfiguration().get('cfnLint.enableAutocomplete');
if (enableAutocomplete) {
let currentTags: Array<string> = workspace.getConfiguration().get('yaml.customTags');
let cloudFormationTags = [
"!And",
"!And sequence",
"!If",
"!If sequence",
"!Not",
"!Not sequence",
"!Equals",
"!Equals sequence",
"!Or",
"!Or sequence",
"!FindInMap",
"!FindInMap sequence",
"!Base64",
"!Join",
"!Join sequence",
"!Cidr",
"!Ref",
"!Sub",
"!Sub sequence",
"!GetAtt",
"!GetAZs",
"!ImportValue",
"!ImportValue sequence",
"!Select",
"!Select sequence",
"!Split",
"!Split sequence"
];
let updateTags = currentTags.concat(cloudFormationTags.filter((item) => currentTags.indexOf(item) < 0));

workspace.getConfiguration().update('yaml.customTags', updateTags, ConfigurationTarget.Global);

yamlLangaugeServerValidation();

registerYamlSchemaSupport();
}

// Create the language client and start the client.
languageClient = new LanguageClient('cfnLint', 'CloudFormation linter Language Server', serverOptions, clientOptions);
await languageClient.start();
Expand Down Expand Up @@ -181,30 +142,6 @@ function getPreviewContent(content: String): string {
`;
}

export async function yamlLangaugeServerValidation(): Promise<void> {
let validateYaml: boolean = workspace.getConfiguration().get('yaml.validate');
let cfnValidateYamlInspect = workspace.getConfiguration().inspect('cfnLint.validateUsingJsonSchema');
let cfnValidateYaml: boolean = workspace.getConfiguration().get('cfnLint.validateUsingJsonSchema');

if (validateYaml) {
if (cfnValidateYamlInspect.globalValue === null || cfnValidateYamlInspect.workspaceFolderValue === null || cfnValidateYamlInspect.workspaceValue === null) {
let selection: string = await window
.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?',
...['yes', 'no']);
if (selection === 'yes') {
workspace.getConfiguration().update('cfnLint.validateUsingJsonSchema', false, ConfigurationTarget.Global);
} else if (selection === 'no') {
workspace.getConfiguration().update('cfnLint.validateUsingJsonSchema', true, ConfigurationTarget.Global);
cfnValidateYaml = true;
}

}
if (cfnValidateYaml === false) {
workspace.getConfiguration().update('yaml.validate', false, ConfigurationTarget.Global);
}
}
}

export function deactivate(): Thenable<void> | undefined {
if (!languageClient) {
return undefined;
Expand Down
11 changes: 1 addition & 10 deletions client/src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as path from 'path';
import * as cp from 'child_process';
import * as os from "os";
import { downloadAndUnzipVSCode,
resolveCliArgsFromVSCodeExecutablePath,
runTests,
} from '@vscode/test-electron';

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

const vscodeExecutablePath = await downloadAndUnzipVSCode('1.69.1');
const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);

// Use cp.spawn / cp.exec for custom setup
cp.spawnSync(cli, [...args, '--install-extension', 'redhat.vscode-yaml'], {
encoding: 'utf-8',
stdio: 'inherit'
});

// Download VS Code, unzip it and run the integration test
await runTests({
vscodeExecutablePath,
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: ['--user-data-dir', `${os.tmpdir()}`],
launchArgs: ['--disable-extensions', '--user-data-dir', `${os.tmpdir()}`],
});
} catch (err) {
console.error(`Failed to run tests: ${err}`);
Expand Down
128 changes: 0 additions & 128 deletions client/src/test/suite/cfnlint.test.ts

This file was deleted.

Loading

0 comments on commit 40e8716

Please sign in to comment.