Skip to content

Commit

Permalink
fix type errors from merge
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Sep 18, 2024
1 parent f66f05c commit f7d2ada
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
10 changes: 5 additions & 5 deletions packages/pyright-internal/src/backgroundAnalysisBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ import { Host, HostKind } from './common/host';
import { LogTracker } from './common/logTracker';
import { ServiceProvider } from './common/serviceProvider';
import { Range } from './common/textRange';
import { createMessageChannel, MessagePort, MessageSourceSink, threadId } from './common/workersHost';
import { createMessageChannel, MessagePort, threadId, MessageChannel, Worker } from './common/workersHost';
import { Uri } from './common/uri/uri';
import { ProgramView } from './common/extensibility';
import { TestFileSystem } from './tests/harness/vfs/filesystem';

export class BackgroundAnalysisBase {
private _worker: MessageSourceSink | undefined;
private _worker: Worker | undefined;
private _onAnalysisCompletion: AnalysisCompleteCallback = nullCallback;
private _analysisCancellationToken: CancellationToken | undefined = undefined;
private _messageChannel: MessageChannel;
Expand All @@ -59,7 +59,7 @@ export class BackgroundAnalysisBase {

// Create a message channel for handling 'analysis' or 'background' type results.
// The other side of this channel will be sent to the BG thread for sending responses.
this._messageChannel = new MessageChannel();
this._messageChannel = createMessageChannel();
this._messageChannel.port1.on('message', (msg: BackgroundResponse) => this.handleBackgroundResponse(msg));
}

Expand Down Expand Up @@ -244,7 +244,7 @@ export class BackgroundAnalysisBase {
}
}

protected setup(worker: MessageSourceSink) {
protected setup(worker: Worker) {
this._worker = worker;

// global channel to communicate from BG channel to main thread.
Expand Down Expand Up @@ -808,7 +808,7 @@ function convertDiagnostics(diagnostics: Diagnostic[]) {
});
}

export type AnalysisRequestKind =
export type BackgroundRequestKind =
// Browser usecase
| 'initializeFileSystem'
| 'createFile'
Expand Down
14 changes: 4 additions & 10 deletions packages/pyright-internal/src/common/nodeWorkersHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ import {
MessageChannel as WorkerThreadsMessageChannel,
threadId,
} from 'worker_threads';
import {
MessageChannel,
MessagePort,
MessageSourceSink,
shallowReplace,
Transferable,
WorkersHost,
} from './workersHost';
import { MessageChannel, MessagePort, shallowReplace, Transferable, Worker, WorkersHost } from './workersHost';

export class NodeWorkersHost implements WorkersHost {
threadId(): string {
Expand All @@ -23,7 +16,7 @@ export class NodeWorkersHost implements WorkersHost {
return parentPort ? new NodeMessagePort(parentPort) : null;
}

createWorker(initialData?: any): MessageSourceSink {
createWorker(initialData?: any): Worker {
// this will load this same file in BG thread and start listener
const worker = new WorkerThreadsWorker(__filename, { workerData: initialData });
return new NodeWorker(worker);
Expand Down Expand Up @@ -61,7 +54,7 @@ class NodeMessagePort implements MessagePort {
}
}

class NodeWorker implements MessageSourceSink {
class NodeWorker implements Worker {
constructor(private _delegate: WorkerThreadsWorker) {}
postMessage(value: any, transferList?: Transferable[]): void {
if (transferList) {
Expand All @@ -73,6 +66,7 @@ class NodeWorker implements MessageSourceSink {
on(type: 'message' | 'error' | 'exit', listener: (data: any) => void): void {
this._delegate.on(type, (data) => listener(wrapOnReceive(data)));
}
terminate = () => this._delegate.terminate();
}

function unwrapForSend(value: any): any {
Expand Down
8 changes: 6 additions & 2 deletions packages/pyright-internal/src/common/workersHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export interface MessageSourceSink {
on(type: 'message' | 'error' | 'exit', listener: (data: any) => void): void;
}

export interface Worker extends MessageSourceSink {
terminate(): Promise<number>;
}

export interface MessagePort extends MessageSourceSink {
start(): void;
close(): void;
Expand All @@ -25,7 +29,7 @@ export interface MessageChannel {

export interface WorkersHost {
parentPort(): MessagePort | null;
createWorker(initialData?: any): MessageSourceSink;
createWorker(initialData?: any): Worker;
createMessageChannel(): MessageChannel;
threadId(): string;
}
Expand All @@ -48,7 +52,7 @@ export function createMessageChannel(): MessageChannel {
return host().createMessageChannel();
}

export function createWorker(initialData?: any): MessageSourceSink {
export function createWorker(initialData?: any): Worker {
return host().createWorker(initialData);
}

Expand Down

0 comments on commit f7d2ada

Please sign in to comment.