Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/markdown-language-features/src/extension.ts
3291 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as vscode from 'vscode';
7
import { LanguageClient, ServerOptions, TransportKind } from 'vscode-languageclient/node';
8
import { MdLanguageClient, startClient } from './client/client';
9
import { activateShared } from './extension.shared';
10
import { VsCodeOutputLogger } from './logging';
11
import { IMdParser, MarkdownItEngine } from './markdownEngine';
12
import { getMarkdownExtensionContributions } from './markdownExtensions';
13
import { githubSlugifier } from './slugify';
14
15
export async function activate(context: vscode.ExtensionContext) {
16
const contributions = getMarkdownExtensionContributions(context);
17
context.subscriptions.push(contributions);
18
19
const logger = new VsCodeOutputLogger();
20
context.subscriptions.push(logger);
21
22
const engine = new MarkdownItEngine(contributions, githubSlugifier, logger);
23
24
const client = await startServer(context, engine);
25
context.subscriptions.push(client);
26
activateShared(context, client, engine, logger, contributions);
27
}
28
29
function startServer(context: vscode.ExtensionContext, parser: IMdParser): Promise<MdLanguageClient> {
30
const isDebugBuild = context.extension.packageJSON.main.includes('/out/');
31
32
const serverModule = context.asAbsolutePath(
33
isDebugBuild
34
// For local non bundled version of vscode-markdown-languageserver
35
// ? './node_modules/vscode-markdown-languageserver/out/node/workerMain'
36
? './node_modules/vscode-markdown-languageserver/dist/node/workerMain'
37
: './dist/serverWorkerMain'
38
);
39
40
// The debug options for the server
41
const debugOptions = { execArgv: ['--nolazy', '--inspect=' + (7000 + Math.round(Math.random() * 999))] };
42
43
// If the extension is launch in debug mode the debug server options are use
44
// Otherwise the run options are used
45
const serverOptions: ServerOptions = {
46
run: { module: serverModule, transport: TransportKind.ipc },
47
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
48
};
49
50
// pass the location of the localization bundle to the server
51
process.env['VSCODE_L10N_BUNDLE_LOCATION'] = vscode.l10n.uri?.toString() ?? '';
52
53
return startClient((id, name, clientOptions) => {
54
return new LanguageClient(id, name, serverOptions, clientOptions);
55
}, parser);
56
}
57
58