Fix reference to worker session (#198820)

This commit is contained in:
Matt Bierner 2023-11-21 16:06:33 -08:00 committed by GitHub
parent fbbdb7912e
commit aab5c69c79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 11 deletions

View file

@ -2,7 +2,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved. * Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
/// <reference lib='webworker.importscripts' />
/// <reference lib='webworker' /> /// <reference lib='webworker' />
import ts from 'typescript/lib/tsserverlibrary'; import ts from 'typescript/lib/tsserverlibrary';
@ -12,14 +11,10 @@ import { Logger, parseLogLevel } from './logging';
import { PathMapper } from './pathMapper'; import { PathMapper } from './pathMapper';
import { createSys } from './serverHost'; import { createSys } from './serverHost';
import { findArgument, findArgumentStringArray, hasArgument, parseServerMode } from './util/args'; import { findArgument, findArgumentStringArray, hasArgument, parseServerMode } from './util/args';
import { StartSessionOptions, createWorkerSession } from './workerSession'; import { StartSessionOptions, startWorkerSession } from './workerSession';
const setSys: (s: ts.System) => void = (ts as any).setSys; const setSys: (s: ts.System) => void = (ts as any).setSys;
// GLOBALS
let session: WorkerSession | undefined;
// END GLOBALS
async function initializeSession( async function initializeSession(
args: readonly string[], args: readonly string[],
extensionUri: URI, extensionUri: URI,
@ -46,8 +41,7 @@ async function initializeSession(
removeEventListener('message', listener); removeEventListener('message', listener);
}); });
setSys(sys); setSys(sys);
session = createWorkerSession(ts, sys, fs, sessionOptions, ports.tsserver, pathMapper, logger); startWorkerSession(ts, sys, fs, sessionOptions, ports.tsserver, pathMapper, logger);
session.listen();
} }
function parseSessionOptions(args: readonly string[], serverMode: ts.LanguageServiceMode | undefined): StartSessionOptions { function parseSessionOptions(args: readonly string[], serverMode: ts.LanguageServiceMode | undefined): StartSessionOptions {

View file

@ -22,7 +22,7 @@ export interface StartSessionOptions {
readonly disableAutomaticTypingAcquisition: boolean; readonly disableAutomaticTypingAcquisition: boolean;
} }
export function createWorkerSession( export function startWorkerSession(
ts: typeof import('typescript/lib/tsserverlibrary'), ts: typeof import('typescript/lib/tsserverlibrary'),
host: ts.server.ServerHost, host: ts.server.ServerHost,
fs: FileSystem | undefined, fs: FileSystem | undefined,
@ -30,10 +30,10 @@ export function createWorkerSession(
port: MessagePort, port: MessagePort,
pathMapper: PathMapper, pathMapper: PathMapper,
logger: Logger, logger: Logger,
) { ): void {
const indent: (str: string) => string = (ts as any).server.indent; const indent: (str: string) => string = (ts as any).server.indent;
return new class WorkerSession extends ts.server.Session<{}> { const worker = new class WorkerSession extends ts.server.Session<{}> {
private readonly wasmCancellationToken: WasmCancellationToken; private readonly wasmCancellationToken: WasmCancellationToken;
private readonly listener: (message: any) => void; private readonly listener: (message: any) => void;
@ -121,4 +121,6 @@ export function createWorkerSession(
port.onmessage = this.listener; port.onmessage = this.listener;
} }
}(); }();
worker.listen();
} }