1/*
2 * Copyright (C) 2019 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17var path = require('path');
18var vscode = require('vscode');
19var langClient = require('vscode-languageclient');
20
21var LanguageClient = langClient.LanguageClient;
22
23// this method is called when your extension is activated
24// your extension is activated the very first time the command is executed
25function activate(context) {
26	let serverModule = path.join(context.extensionPath, 'langsvr');
27	let debugOptions = {};
28
29	// If the extension is launched in debug mode then the debug server options are used
30	// Otherwise the run options are used
31	let serverOptions = {
32		run: { command: serverModule, transport: langClient.stdio },
33		debug: { command: serverModule, transport: langClient.stdio, options: debugOptions }
34	}
35
36	// Options to control the language client
37	let clientOptions = {
38		documentSelector: ['spirv'],
39		synchronize: {
40			// Synchronize the setting section 'spirv' to the server
41			configurationSection: 'spirv',
42			// Notify the server about file changes to .spvasm files contained in the workspace
43			fileEvents: vscode.workspace.createFileSystemWatcher('**/*.spvasm')
44		}
45	}
46
47	// Create the language client and start the client.
48	let disposable = new LanguageClient('spirv', serverOptions, clientOptions).start();
49
50	// Push the disposable to the context's subscriptions so that the
51	// client can be deactivated on extension deactivation
52	context.subscriptions.push(disposable);
53
54	// Set the language configuration here instead of a language configuration
55	// file to work around https://github.com/microsoft/vscode/issues/42649.
56	vscode.languages.setLanguageConfiguration("spirv", {
57		comments: { "lineComment": ";" },
58		wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
59	});
60}
61exports.activate = activate;
62
63// this method is called when your extension is deactivated
64function deactivate() {
65}
66exports.deactivate = deactivate;
67