mirror of
https://github.com/coder/code-server.git
synced 2026-05-17 17:57:26 +02:00
chore(vscode): update to 1.53.2
These conflicts will be resolved in the following commits. We do it this way so that PR review is possible.
This commit is contained in:
@@ -11,6 +11,11 @@ export interface Sender {
|
||||
send(channel: string, msg: unknown): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Electron `Protocol` leverages Electron style IPC communication (`ipcRenderer`, `ipcMain`)
|
||||
* for the implementation of the `IMessagePassingProtocol`. That style of API requires a channel
|
||||
* name for sending data.
|
||||
*/
|
||||
export class Protocol implements IMessagePassingProtocol {
|
||||
|
||||
constructor(private sender: Sender, readonly onMessage: Event<VSBuffer>) { }
|
||||
@@ -23,7 +28,7 @@ export class Protocol implements IMessagePassingProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
disconnect(): void {
|
||||
this.sender.send('vscode:disconnect', null);
|
||||
}
|
||||
}
|
||||
|
||||
78
lib/vscode/src/vs/base/parts/ipc/common/ipc.mp.ts
Normal file
78
lib/vscode/src/vs/base/parts/ipc/common/ipc.mp.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IMessagePassingProtocol, IPCClient } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
|
||||
/**
|
||||
* Declare minimal `MessageEvent` and `MessagePort` interfaces here
|
||||
* so that this utility can be used both from `browser` and
|
||||
* `electron-main` namespace where message ports are available.
|
||||
*/
|
||||
|
||||
export interface MessageEvent {
|
||||
|
||||
/**
|
||||
* For our use we only consider `Uint8Array` a valid data transfer
|
||||
* via message ports because our protocol implementation is buffer based.
|
||||
*/
|
||||
data: Uint8Array;
|
||||
}
|
||||
|
||||
export interface MessagePort {
|
||||
|
||||
addEventListener(type: 'message', listener: (this: MessagePort, e: MessageEvent) => unknown): void;
|
||||
removeEventListener(type: 'message', listener: (this: MessagePort, e: MessageEvent) => unknown): void;
|
||||
|
||||
postMessage(message: Uint8Array): void;
|
||||
|
||||
start(): void;
|
||||
close(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* The MessagePort `Protocol` leverages MessagePort style IPC communication
|
||||
* for the implementation of the `IMessagePassingProtocol`. That style of API
|
||||
* is a simple `onmessage` / `postMessage` pattern.
|
||||
*/
|
||||
export class Protocol implements IMessagePassingProtocol {
|
||||
|
||||
readonly onMessage = Event.fromDOMEventEmitter<VSBuffer>(this.port, 'message', (e: MessageEvent) => VSBuffer.wrap(e.data));
|
||||
|
||||
constructor(private port: MessagePort) {
|
||||
|
||||
// we must call start() to ensure messages are flowing
|
||||
port.start();
|
||||
}
|
||||
|
||||
send(message: VSBuffer): void {
|
||||
this.port.postMessage(message.buffer);
|
||||
}
|
||||
|
||||
disconnect(): void {
|
||||
this.port.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An implementation of a `IPCClient` on top of MessagePort style IPC communication.
|
||||
*/
|
||||
export class Client extends IPCClient implements IDisposable {
|
||||
|
||||
private protocol: Protocol;
|
||||
|
||||
constructor(port: MessagePort, clientId: string) {
|
||||
const protocol = new Protocol(port);
|
||||
super(protocol, clientId);
|
||||
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.protocol.disconnect();
|
||||
}
|
||||
}
|
||||
@@ -365,8 +365,8 @@ export class Protocol extends Disposable implements IMessagePassingProtocol {
|
||||
private readonly _onMessage = new Emitter<VSBuffer>();
|
||||
readonly onMessage: Event<VSBuffer> = this._onMessage.event;
|
||||
|
||||
private readonly _onClose = new Emitter<void>();
|
||||
readonly onClose: Event<void> = this._onClose.event;
|
||||
private readonly _onDidDispose = new Emitter<void>();
|
||||
readonly onDidDispose: Event<void> = this._onDidDispose.event;
|
||||
|
||||
constructor(socket: ISocket) {
|
||||
super();
|
||||
@@ -380,7 +380,7 @@ export class Protocol extends Disposable implements IMessagePassingProtocol {
|
||||
}
|
||||
}));
|
||||
|
||||
this._register(this._socket.onClose(() => this._onClose.fire()));
|
||||
this._register(this._socket.onClose(() => this._onDidDispose.fire()));
|
||||
}
|
||||
|
||||
drain(): Promise<void> {
|
||||
@@ -406,7 +406,7 @@ export class Client<TContext = string> extends IPCClient<TContext> {
|
||||
return new Client(new Protocol(socket), id);
|
||||
}
|
||||
|
||||
get onClose(): Event<void> { return this.protocol.onClose; }
|
||||
get onDidDispose(): Event<void> { return this.protocol.onDidDispose; }
|
||||
|
||||
constructor(private protocol: Protocol | PersistentProtocol, id: TContext, ipcLogger: IIPCLogger | null = null) {
|
||||
super(protocol, id, ipcLogger);
|
||||
@@ -621,8 +621,8 @@ export class PersistentProtocol implements IMessagePassingProtocol {
|
||||
private readonly _onMessage = new BufferedEmitter<VSBuffer>();
|
||||
readonly onMessage: Event<VSBuffer> = this._onMessage.event;
|
||||
|
||||
private readonly _onClose = new BufferedEmitter<void>();
|
||||
readonly onClose: Event<void> = this._onClose.event;
|
||||
private readonly _onDidDispose = new BufferedEmitter<void>();
|
||||
readonly onDidDispose: Event<void> = this._onDidDispose.event;
|
||||
|
||||
private readonly _onSocketClose = new BufferedEmitter<void>();
|
||||
readonly onSocketClose: Event<void> = this._onSocketClose.event;
|
||||
@@ -747,6 +747,10 @@ export class PersistentProtocol implements IMessagePassingProtocol {
|
||||
return this._socket;
|
||||
}
|
||||
|
||||
public getMillisSinceLastIncomingData(): number {
|
||||
return Date.now() - this._socketReader.lastReadTime;
|
||||
}
|
||||
|
||||
public beginAcceptReconnection(socket: ISocket, initialDataChunk: VSBuffer | null): void {
|
||||
this._isReconnecting = true;
|
||||
|
||||
@@ -783,7 +787,7 @@ export class PersistentProtocol implements IMessagePassingProtocol {
|
||||
}
|
||||
|
||||
public acceptDisconnect(): void {
|
||||
this._onClose.fire();
|
||||
this._onDidDispose.fire();
|
||||
}
|
||||
|
||||
private _receiveMessage(msg: ProtocolMessage): void {
|
||||
@@ -820,7 +824,7 @@ export class PersistentProtocol implements IMessagePassingProtocol {
|
||||
} else if (msg.type === ProtocolMessageType.Control) {
|
||||
this._onControlMessage.fire(msg.data);
|
||||
} else if (msg.type === ProtocolMessageType.Disconnect) {
|
||||
this._onClose.fire();
|
||||
this._onDidDispose.fire();
|
||||
} else if (msg.type === ProtocolMessageType.ReplayRequest) {
|
||||
// Send again all unacknowledged messages
|
||||
const toSend = this._outgoingUnackMsg.toArray();
|
||||
|
||||
@@ -505,6 +505,7 @@ export interface IIPCLogger {
|
||||
|
||||
export class ChannelClient implements IChannelClient, IDisposable {
|
||||
|
||||
private isDisposed: boolean = false;
|
||||
private state: State = State.Uninitialized;
|
||||
private activeRequests = new Set<IDisposable>();
|
||||
private handlers = new Map<number, IHandler>();
|
||||
@@ -525,9 +526,15 @@ export class ChannelClient implements IChannelClient, IDisposable {
|
||||
|
||||
return {
|
||||
call(command: string, arg?: any, cancellationToken?: CancellationToken) {
|
||||
if (that.isDisposed) {
|
||||
return Promise.reject(errors.canceled());
|
||||
}
|
||||
return that.requestPromise(channelName, command, arg, cancellationToken);
|
||||
},
|
||||
listen(event: string, arg: any) {
|
||||
if (that.isDisposed) {
|
||||
return Promise.reject(errors.canceled());
|
||||
}
|
||||
return that.requestEvent(channelName, event, arg);
|
||||
}
|
||||
} as T;
|
||||
@@ -725,6 +732,7 @@ export class ChannelClient implements IChannelClient, IDisposable {
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.isDisposed = true;
|
||||
if (this.protocolListener) {
|
||||
this.protocolListener.dispose();
|
||||
this.protocolListener = null;
|
||||
|
||||
Reference in New Issue
Block a user