Path: blob/main/extensions/markdown-language-features/src/extension.ts
3291 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import * as vscode from 'vscode';6import { LanguageClient, ServerOptions, TransportKind } from 'vscode-languageclient/node';7import { MdLanguageClient, startClient } from './client/client';8import { activateShared } from './extension.shared';9import { VsCodeOutputLogger } from './logging';10import { IMdParser, MarkdownItEngine } from './markdownEngine';11import { getMarkdownExtensionContributions } from './markdownExtensions';12import { githubSlugifier } from './slugify';1314export async function activate(context: vscode.ExtensionContext) {15const contributions = getMarkdownExtensionContributions(context);16context.subscriptions.push(contributions);1718const logger = new VsCodeOutputLogger();19context.subscriptions.push(logger);2021const engine = new MarkdownItEngine(contributions, githubSlugifier, logger);2223const client = await startServer(context, engine);24context.subscriptions.push(client);25activateShared(context, client, engine, logger, contributions);26}2728function startServer(context: vscode.ExtensionContext, parser: IMdParser): Promise<MdLanguageClient> {29const isDebugBuild = context.extension.packageJSON.main.includes('/out/');3031const serverModule = context.asAbsolutePath(32isDebugBuild33// For local non bundled version of vscode-markdown-languageserver34// ? './node_modules/vscode-markdown-languageserver/out/node/workerMain'35? './node_modules/vscode-markdown-languageserver/dist/node/workerMain'36: './dist/serverWorkerMain'37);3839// The debug options for the server40const debugOptions = { execArgv: ['--nolazy', '--inspect=' + (7000 + Math.round(Math.random() * 999))] };4142// If the extension is launch in debug mode the debug server options are use43// Otherwise the run options are used44const serverOptions: ServerOptions = {45run: { module: serverModule, transport: TransportKind.ipc },46debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }47};4849// pass the location of the localization bundle to the server50process.env['VSCODE_L10N_BUNDLE_LOCATION'] = vscode.l10n.uri?.toString() ?? '';5152return startClient((id, name, clientOptions) => {53return new LanguageClient(id, name, serverOptions, clientOptions);54}, parser);55}565758