diff options
author | bscan <10503608+bscan@users.noreply.github.com> | 2023-01-15 17:09:29 -0500 |
---|---|---|
committer | bscan <10503608+bscan@users.noreply.github.com> | 2023-01-15 17:09:29 -0500 |
commit | 2c17a5096fa5c9310ffea8d478e30c7175b0b125 (patch) | |
tree | c82c5eacfc4d6213eca7bc49b75263c047c34d94 /client | |
parent | d8b9250e26f5e86037d401de523478353413564d (diff) | |
download | PerlNavigator-2c17a5096fa5c9310ffea8d478e30c7175b0b125.zip |
First version of Web Extension. Currently only offers syntax highlighting.
Diffstat (limited to 'client')
-rw-r--r-- | client/src/browserClientMain.ts | 49 | ||||
-rw-r--r-- | client/tsconfig.json | 24 |
2 files changed, 61 insertions, 12 deletions
diff --git a/client/src/browserClientMain.ts b/client/src/browserClientMain.ts new file mode 100644 index 0000000..3452528 --- /dev/null +++ b/client/src/browserClientMain.ts @@ -0,0 +1,49 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { ExtensionContext, Uri } from 'vscode'; +import { LanguageClientOptions } from 'vscode-languageclient'; + +import { LanguageClient } from 'vscode-languageclient/browser'; + +// this method is called when vs code is activated +export function activate(context: ExtensionContext) { + + console.log('Perl Navigator web client activated!'); + + /* + * all except the code to create the language client in not browser specific + * and could be shared with a regular (Node) extension + */ + const documentSelector = [ + { scheme: 'file', language: 'perl' }, + { scheme: 'untitled', language: 'perl' } + ] + + // Options to control the language client + const clientOptions: LanguageClientOptions = { + documentSelector, + synchronize: {}, + initializationOptions: {} + }; + + const client = createWorkerLanguageClient(context, clientOptions); + + const disposable = client.start(); + context.subscriptions.push(disposable); + + client.onReady().then(() => { + console.log('Perl Navigator web client is now ready!'); + }); +} + +function createWorkerLanguageClient(context: ExtensionContext, clientOptions: LanguageClientOptions) { + // Create a worker. The worker main file implements the language server. + const serverMain = Uri.joinPath(context.extensionUri, 'browser-ext/dist/browserServerMain.js'); + const worker = new Worker(serverMain.toString(true)); + + // create the language server client to communicate with the server running in the worker + return new LanguageClient('perlnavigator-web', 'Perl Navigator Web', clientOptions, worker); +}
\ No newline at end of file diff --git a/client/tsconfig.json b/client/tsconfig.json index c197bb6..2642d8b 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -1,12 +1,12 @@ -{
- "compilerOptions": {
- "module": "commonjs",
- "target": "es2019",
- "lib": ["ES2019"],
- "outDir": "out",
- "rootDir": "src",
- "sourceMap": true
- },
- "include": ["src"],
- "exclude": ["node_modules", ".vscode-test"]
-}
+{ + "compilerOptions": { + "module": "commonjs", + "target": "es2019", + "lib": ["ES2019", "WebWorker"], + "outDir": "out", + "rootDir": "src", + "sourceMap": true + }, + "include": ["src"], + "exclude": ["node_modules", ".vscode-test"] +} |