85
}
86
}
88
>
type IRawInitializeResponse = { type: ResponseType.Initialize };
89
>
type IRawPromiseSuccessResponse = { type: ResponseType.PromiseSuccess; id: number; data: any };
90
>
type IRawPromiseErrorResponse = { type: ResponseType.PromiseError; id: number; data: { message: string; name: string; stack: string[] | undefined } };
91
>
type IRawPromiseErrorObjResponse = { type: ResponseType.PromiseErrorObj; id: number; data: any };
92
>
type IRawEventFireResponse = { type: ResponseType.EventFire; id: number; data: any };
93
>
type IRawResponse = IRawInitializeResponse | IRawPromiseSuccessResponse | IRawPromiseErrorResponse | IRawPromiseErrorObjResponse | IRawEventFireResponse;
94
>
95
>
interface IHandler {
96
>
(response: IRawResponse): void;
97
>
}
98
>
99
>
export interface IMessagePassingProtocol {
100
>
send(buffer: VSBuffer): void;
101
>
readonly onMessage: Event<VSBuffer>;
102
>
/**
103
>
* Wait for the write buffer (if applicable) to become empty.
104
>
*/
105
>
drain?(): Promise<void>;
106
>
}
107
>
108
>
enum State {
109
>
Uninitialized,
110
>
Idle
111
>
}
112
>
113
>
/**
114
>
* An `IChannelServer` hosts a collection of channels. You are
115
>
* able to register channels onto it, provided a channel name.
116
>
*/
117
>
export interface IChannelServer<TContext = string> {
118
>
registerChannel(channelName: string, channel: IServerChannel<TContext>): void;
119
>
}
120
>
121
>
/**
122
>
* An `IChannelClient` has access to a collection of channels. You
123
>
* are able to get those channels, given their channel name.
124
>
*/
125
>
export interface IChannelClient {
126
>
getChannel<T extends IChannel>(channelName: string): T;
127
>
}
128
>
129
>
export interface Client<TContext> {
130
>
readonly ctx: TContext;
131
>
}
132
>
133
>
export interface IConnectionHub<TContext> {
134
>
readonly connections: Connection<TContext>[];
135
>
readonly onDidAddConnection: Event<Connection<TContext>>;
136
>
readonly onDidRemoveConnection: Event<Connection<TContext>>;
137
>
}
138
>
139
>
/**
140
>
* An `IClientRouter` is responsible for routing calls to specific
141
>
* channels, in scenarios in which there are multiple possible
142
>
* channels (each from a separate client) to pick from.
143
>
*/
144
>
export interface IClientRouter<TContext = string> {
145
>
routeCall(hub: IConnectionHub<TContext>, command: string, arg?: any, cancellationToken?: CancellationToken): Promise<Client<TContext>>;
146
>
routeEvent(hub: IConnectionHub<TContext>, event: string, arg?: any): Promise<Client<TContext>>;
147
>
}
148
>
149
>
/**
150
>
* Similar to the `IChannelClient`, you can get channels from this
151
>
* collection of channels. The difference being that in the
152
>
* `IRoutingChannelClient`, there are multiple clients providing
153
>
* the same channel. You'll need to pass in an `IClientRouter` in
154
>
* order to pick the right one.
155
>
*/
156
>
export interface IRoutingChannelClient<TContext = string> {
157
>
getChannel<T extends IChannel>(channelName: string, router?: IClientRouter<TContext>): T;
158
>
}
159
>
160
>
interface IReader {
161
>
read(bytes: number): VSBuffer;
162
>
}
163
>
164
>
interface IWriter {
165
>
write(buffer: VSBuffer): void;
166
>
}
167
>
168
>
169
>
/**
170
>
* @see https://en.wikipedia.org/wiki/Variable-length_quantity
171
>
*/
172
function readIntVQL(reader: IReader) {
173
let value = 0;