export function activate()

in client/src/extension.ts [25:132]


export function activate(context: ExtensionContext) {

	// The server is implemented in node
	let serverModule = context.asAbsolutePath(path.join('server', 'out', 'server.js'));
	// The debug options for the server
	let debugOptions = { execArgv: ["--nolazy", "--inspect=6010"] };

	// If the extension is launched in debug mode then the debug server options are used
	// Otherwise the run options are used
	let serverOptions: ServerOptions = {
		run: { module: serverModule, transport: TransportKind.ipc },
		debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
	};

	// Options to control the language client
	let clientOptions: LanguageClientOptions = {
		// Register the server for plain text documents
		documentSelector: [
			{ 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')
		}
	};

	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.
	let languageClient = new LanguageClient('cfnLint', 'CloudFormation linter Language Server', serverOptions, clientOptions);
	let clientDisposable = languageClient.start();

	languageClient.onReady().then(() => {
		languageClient.onNotification('cfn/busy', () => {
			window.showInformationMessage("Linter is already running. Please try again.");
		});
		languageClient.onNotification('cfn/previewIsAvailable', (uri) => {
			reloadSidePreview(uri, languageClient);
		});
		languageClient.onNotification('cfn/isPreviewable', (value) => {
			commands.executeCommand('setContext', 'isPreviewable', value);
		});
		languageClient.onNotification('cfn/fileclosed', (uri) => {
			// if the user closed the template itself, we close the preview
			if (previews[uri]) {
				previews[uri].dispose();
			}
		});

		let previewDisposable = commands.registerCommand('extension.sidePreview', () => {

			if (window.activeTextEditor.document) {
				let uri = Uri.file(window.activeTextEditor.document.fileName).toString();

				languageClient.sendNotification('cfn/requestPreview', uri);
			}

		});

		context.subscriptions.push(previewDisposable);
	});

	// Push the disposable to the context's subscriptions so that the
	// client can be deactivated on extension deactivation
	context.subscriptions.push(clientDisposable);
}