rpcProtocol.ts ×47

Frontier kind: Code frontier

unlabeled · c_0b3c93838632

12 tests · 8297 LOC · 37 files · introduces 0 tests · 161 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
52 ranges161 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1327 ranges8297 lines · 37 files · Browse complete extent
All tests (intent)
12 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

2 files ranked by introduced lines: 161 introduced LOC across 52 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/services/extensions/common/rpcProtocol.ts 139 introduced LOC · 47 ranges

Open complete file

183
184 private _onWillSendRequest(req: number): void {
185 > if (this._unacknowledgedCount === 0) { rpcProtocol.ts
186 > // Since this is the first request we are sending in a while,
187 > // mark this moment as the start for the countdown to unresponsive time
188 > this._unresponsiveTime = Date.now() + RPCProtocol.UNRESPONSIVE_TIME;
189 > }
190 > this._unacknowledgedCount++;
191 > if (!this._asyncCheckUresponsive.isScheduled()) {
192 > this._asyncCheckUresponsive.schedule();
193 > }
194 > }
195
196 private _onDidReceiveAcknowledge(req: number): void {
197 > // The next possible unresponsive time is now + delta. rpcProtocol.ts
198 > this._unresponsiveTime = Date.now() + RPCProtocol.UNRESPONSIVE_TIME;
199 > this._unacknowledgedCount--;
200 > if (this._unacknowledgedCount === 0) {
201 > // No more need to check for unresponsive
202 > this._asyncCheckUresponsive.cancel();
203 > }
204 > // The ext host is responsive!
205 > this._setResponsiveState(ResponsiveState.Responsive);
206 > }
207
208 private _checkUnresponsive(): void {
222
223 private _setResponsiveState(newResponsiveState: ResponsiveState): void {
224 > if (this._responsiveState === newResponsiveState) { rpcProtocol.ts
225 > // no change
226 > return;
227 > }
228 this._responsiveState = newResponsiveState;
229 this._onDidChangeResponsiveState.fire(this._responsiveState);
230 > } rpcProtocol.ts
231
232 public get responsiveState(): ResponsiveState {
281
282 private _receiveOneMessage(rawmsg: VSBuffer): void {
283 > if (this._isDisposed) { rpcProtocol.ts
284 return;
285 }
287 > const msgLength = rawmsg.byteLength;
288 > const buff = MessageBuffer.read(rawmsg, 0);
289 > const messageType = <MessageType>buff.readUInt8();
290 > const req = buff.readUInt32();
291 >
292 > switch (messageType) {
293 > case MessageType.RequestJSONArgs:
294 > case MessageType.RequestJSONArgsWithCancellation: {
295 let { rpcId, method, args } = MessageIO.deserializeRequestJSONArgs(buff);
296 if (this._uriTransformer) {
300 break;
301 }
302 > case MessageType.RequestMixedArgs: rpcProtocol.ts
303 > case MessageType.RequestMixedArgsWithCancellation: {
304 let { rpcId, method, args } = MessageIO.deserializeRequestMixedArgs(buff);
305 if (this._uriTransformer) {
309 break;
310 }
311 > case MessageType.Acknowledged: { rpcProtocol.ts
312 > this._logger?.logIncoming(msgLength, req, RequestInitiator.LocalSide, `ack`);
313 > this._onDidReceiveAcknowledge(req);
314 > break;
315 > }
316 > case MessageType.Cancel: {
317 this._receiveCancel(msgLength, req);
318 break;
319 }
320 > case MessageType.ReplyOKEmpty: { rpcProtocol.ts
321 this._receiveReply(msgLength, req, undefined);
322 break;
323 }
324 > case MessageType.ReplyOKJSON: { rpcProtocol.ts
325 let value = MessageIO.deserializeReplyOKJSON(buff);
326 if (this._uriTransformer) {
330 break;
331 }
332 > case MessageType.ReplyOKJSONWithBuffers: { rpcProtocol.ts
333 const value = MessageIO.deserializeReplyOKJSONWithBuffers(buff, this._uriTransformer);
334 this._receiveReply(msgLength, req, value);
335 break;
336 }
337 > case MessageType.ReplyOKVSBuffer: { rpcProtocol.ts
338 const value = MessageIO.deserializeReplyOKVSBuffer(buff);
339 this._receiveReply(msgLength, req, value);
340 break;
341 }
342 > case MessageType.ReplyErrError: { rpcProtocol.ts
343 let err = MessageIO.deserializeReplyErrError(buff);
344 if (this._uriTransformer) {
348 break;
349 }
350 > case MessageType.ReplyErrEmpty: { rpcProtocol.ts
351 this._receiveReplyErr(msgLength, req, undefined);
352 break;
353 }
354 > default: rpcProtocol.ts
355 console.error(`received unexpected message`);
356 console.error(rawmsg);
357 > } rpcProtocol.ts
358 > }
359
360 private _receiveRequest(msgLength: number, req: number, rpcId: number, method: string, args: any[], usesCancellationToken: boolean): void {
361 > this._logger?.logIncoming(msgLength, req, RequestInitiator.OtherSide, `receiveRequest ${getStringIdentifierForProxy(rpcId)}.${method}(`, args); rpcProtocol.ts
362 > const callId = String(req);
363 >
364 > let promise: Promise<any>;
365 > let cancel: () => void;
366 > if (usesCancellationToken) {
367 const cancellationTokenSource = new CancellationTokenSource();
368 args.push(cancellationTokenSource.token);
369 promise = this._invokeHandler(rpcId, method, args);
370 cancel = () => cancellationTokenSource.cancel();
371 > } else { rpcProtocol.ts
372 // cannot be cancelled
373 promise = this._invokeHandler(rpcId, method, args);
374 cancel = noop;
375 }
377 > this._cancelInvokedHandlers[callId] = cancel;
378 >
379 > // Acknowledge the request
380 > const msg = MessageIO.serializeAcknowledged(req);
381 > this._logger?.logOutgoing(msg.byteLength, req, RequestInitiator.OtherSide, `ack`);
382 > this._protocol.send(msg);
383 >
384 > promise.then((r) => {
385 delete this._cancelInvokedHandlers[callId];
386 const msg = MessageIO.serializeReplyOK(req, r, this._uriReplacer);
387 this._logger?.logOutgoing(msg.byteLength, req, RequestInitiator.OtherSide, `reply:`, r);
388 this._protocol.send(msg);
389 > }, (err) => { rpcProtocol.ts
390 delete this._cancelInvokedHandlers[callId];
391 const msg = MessageIO.serializeReplyErr(req, err);
392 this._logger?.logOutgoing(msg.byteLength, req, RequestInitiator.OtherSide, `replyErr:`, err);
393 this._protocol.send(msg);
394 > }); rpcProtocol.ts
395 > }
396
397 private _receiveCancel(msgLength: number, req: number): void {
440
441 private _invokeHandler(rpcId: number, methodName: string, args: any[]): Promise<any> {
442 > try { rpcProtocol.ts
443 > return Promise.resolve(this._doInvokeHandler(rpcId, methodName, args));
444 > } catch (err) {
445 return Promise.reject(err);
446 }
447 > } rpcProtocol.ts
448
449 private _doInvokeHandler(rpcId: number, methodName: string, args: any[]): any {
450 > const actor = this._locals[rpcId]; rpcProtocol.ts
451 > if (!actor) {
452 throw new Error('Unknown actor ' + getStringIdentifierForProxy(rpcId));
453 }
454 > const method = actor[methodName]; rpcProtocol.ts
455 > if (typeof method !== 'function') {
456 throw new Error('Unknown method ' + methodName + ' on actor ' + getStringIdentifierForProxy(rpcId));
457 }
458 > return method.apply(actor, args); rpcProtocol.ts
459 > }
460
461 private _remoteCall(rpcId: number, methodName: string, args: any[]): Promise<any> {
487 }));
488 }
490 > this._pendingRPCReplies[callId] = new PendingRPCReply(result, disposable);
491 > this._onWillSendRequest(req);
492 > const msg = MessageIO.serializeRequest(req, rpcId, methodName, serializedRequestArguments, !!cancellationToken);
493 this._logger?.logOutgoing(msg.byteLength, req, RequestInitiator.LocalSide, `request: ${getStringIdentifierForProxy(rpcId)}.${methodName}(`, args);
494 this._protocol.send(msg);
499 class PendingRPCReply {
500 constructor(
501 > private readonly _promise: LazyPromise, rpcProtocol.ts
502 > private readonly _disposable: IDisposable
503 > ) { }
504
505 public resolveOk(value: any): void {
517
518 public static alloc(type: MessageType, req: number, messageSize: number): MessageBuffer {
519 > const result = new MessageBuffer(VSBuffer.alloc(messageSize + 1 /* type */ + 4 /* req */), 0); rpcProtocol.ts
520 > result.writeUInt8(type);
521 > result.writeUInt32(req);
522 > return result;
523 > }
524
525 public static read(buff: VSBuffer, offset: number): MessageBuffer {
526 > return new MessageBuffer(buff, offset); rpcProtocol.ts
527 > }
528
529 private _buff: VSBuffer;
531
532 public get buffer(): VSBuffer {
533 > return this._buff; rpcProtocol.ts
534 > }
535
536 private constructor(buff: VSBuffer, offset: number) {
537 > this._buff = buff; rpcProtocol.ts
538 > this._offset = offset;
539 > }
540
541 public static sizeUInt8(): number {
542 > return 1; rpcProtocol.ts
543 > }
544
545 public static readonly sizeUInt32 = 4;
546
547 public writeUInt8(n: number): void {
548 > this._buff.writeUInt8(n, this._offset); this._offset += 1; rpcProtocol.ts
549 > }
550
551 public readUInt8(): number {
552 > const n = this._buff.readUInt8(this._offset); this._offset += 1; rpcProtocol.ts
553 > return n;
554 > }
555
556 public writeUInt32(n: number): void {
557 > this._buff.writeUInt32BE(n, this._offset); this._offset += 4; rpcProtocol.ts
558 > }
559
560 public readUInt32(): number {
561 > const n = this._buff.readUInt32BE(this._offset); this._offset += 4; rpcProtocol.ts
562 > return n;
563 > }
564
565 public static sizeShortString(str: VSBuffer): number {
566 > return 1 /* string length */ + str.byteLength /* actual string */; rpcProtocol.ts
567 > }
568
569 public writeShortString(str: VSBuffer): void {
570 > this._buff.writeUInt8(str.byteLength, this._offset); this._offset += 1; rpcProtocol.ts
571 > this._buff.set(str, this._offset); this._offset += str.byteLength;
572 > }
573
574 public readShortString(): string {
575 > const strByteLength = this._buff.readUInt8(this._offset); this._offset += 1; rpcProtocol.ts
576 > const strBuff = this._buff.slice(this._offset, this._offset + strByteLength);
577 > const str = strBuff.toString(); this._offset += strByteLength;
578 > return str;
579 > }
580
581 public static sizeLongString(str: VSBuffer): number {
582 > return 4 /* string length */ + str.byteLength /* actual string */; rpcProtocol.ts
583 > }
584
585 public writeLongString(str: VSBuffer): void {
586 > this._buff.writeUInt32BE(str.byteLength, this._offset); this._offset += 4; rpcProtocol.ts
587 > this._buff.set(str, this._offset); this._offset += str.byteLength;
588 > }
589
590 public readLongString(): string {
591 > const strByteLength = this._buff.readUInt32BE(this._offset); this._offset += 4; rpcProtocol.ts
592 > const strBuff = this._buff.slice(this._offset, this._offset + strByteLength);
593 > const str = strBuff.toString(); this._offset += strByteLength;
594 > return str;
595 > }
596
597 public writeBuffer(buff: VSBuffer): void {
757
758 public static serializeRequest(req: number, rpcId: number, method: string, serializedArgs: SerializedRequestArguments, usesCancellationToken: boolean): VSBuffer {
759 > switch (serializedArgs.type) { rpcProtocol.ts
760 > case SerializedRequestArgumentType.Simple:
761 return this._requestJSONArgs(req, rpcId, method, serializedArgs.args, usesCancellationToken);
762 > case SerializedRequestArgumentType.Mixed: rpcProtocol.ts
763 return this._requestMixedArgs(req, rpcId, method, serializedArgs.args, usesCancellationToken);
764 > } rpcProtocol.ts
765 > }
766
767 private static _requestJSONArgs(req: number, rpcId: number, method: string, args: string, usesCancellationToken: boolean): VSBuffer {
828
829 public static serializeAcknowledged(req: number): VSBuffer {
830 > return MessageBuffer.alloc(MessageType.Acknowledged, req, 0).buffer; rpcProtocol.ts
831 > }
832
833 public static serializeCancel(req: number): VSBuffer {
src/vs/workbench/services/extensions/common/lazyPromise.ts 22 introduced LOC · 5 ranges

Open complete file

19
20 constructor() {
21 > this._actual = null; lazyPromise.ts
22 > this._actualOk = null;
23 > this._actualErr = null;
24 > this._hasValue = false;
25 > this._value = null;
26 > this._hasErr = false;
27 > this._err = null;
28 > }
29
30 get [Symbol.toStringTag](): string {
33
34 private _ensureActual(): Promise<any> {
35 > if (!this._actual) { lazyPromise.ts
36 > this._actual = new Promise<any>((c, e) => {
37 > this._actualOk = c;
38 > this._actualErr = e;
39 >
40 > if (this._hasValue) {
41 this._actualOk(this._value);
42 }
44 > if (this._hasErr) {
45 this._actualErr(this._err);
46 }
47 > }); lazyPromise.ts
48 > }
49 > return this._actual;
50 > }
51
52 public resolveOk(value: any): void {
81
82 public then(success: any, error: any): any {
83 > return this._ensureActual().then(success, error); lazyPromise.ts
84 > }
85
86 public catch(error: any): any {