extensionHostMain.ts ×11

Frontier kind: Code frontier

unlabeled · c_c4ca77aa9d2c

7 tests · 82556 LOC · 303 files · introduces 0 tests · 164 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges164 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5791 ranges82556 lines · 303 files · Browse complete extent
All tests (intent)
7 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.

4 files ranked by introduced lines: 164 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/api/common/extensionHostMain.ts 119 introduced LOC · 11 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- extensionHostMain.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import * as errors from '../../../base/common/errors.js';
7 > import * as performance from '../../../base/common/performance.js';
8 > import { URI } from '../../../base/common/uri.js';
9 > import { IURITransformer } from '../../../base/common/uriIpc.js';
10 > import { IMessagePassingProtocol } from '../../../base/parts/ipc/common/ipc.js';
11 > import { MainContext, MainThreadConsoleShape } from './extHost.protocol.js';
12 > import { IExtensionHostInitData } from '../../services/extensions/common/extensionHostProtocol.js';
13 > import { RPCProtocol } from '../../services/extensions/common/rpcProtocol.js';
14 > import { ExtensionError, ExtensionIdentifier, IExtensionDescription } from '../../../platform/extensions/common/extensions.js';
15 > import { ILogService } from '../../../platform/log/common/log.js';
16 > import { getSingletonServiceDescriptors } from '../../../platform/instantiation/common/extensions.js';
17 > import { ServiceCollection } from '../../../platform/instantiation/common/serviceCollection.js';
18 > import { IExtHostInitDataService } from './extHostInitDataService.js';
19 > import { InstantiationService } from '../../../platform/instantiation/common/instantiationService.js';
20 > import { IInstantiationService, ServicesAccessor } from '../../../platform/instantiation/common/instantiation.js';
21 > import { IExtHostRpcService, ExtHostRpcService } from './extHostRpcService.js';
22 > import { IURITransformerService, URITransformerService } from './extHostUriTransformerService.js';
23 > import { IExtHostExtensionService, IHostUtils } from './extHostExtensionService.js';
24 > import { IExtHostTelemetry } from './extHostTelemetry.js';
25 > import { Mutable } from '../../../base/common/types.js';
26 > import { IExtHostApiDeprecationService } from './extHostApiDeprecationService.js';
27 >
28 > export interface IExitFn {
29 > (code?: number): any;
30 > }
31 >
32 > export interface IConsolePatchFn {
33 > (mainThreadConsole: MainThreadConsoleShape): any;
34 > }
35 >
36 > export abstract class ErrorHandler {
37 >
38 > static async installEarlyHandler(accessor: ServicesAccessor): Promise<void> {
39
40 // increase number of stack frames (from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
53 });
54 }
56 > static async installFullHandler(accessor: ServicesAccessor): Promise<void> {
57 > // uses extension knowledges to correlate errors with extensions
58 >
59 > const logService = accessor.get(ILogService);
60 > const rpcService = accessor.get(IExtHostRpcService);
61 > const extensionService = accessor.get(IExtHostExtensionService);
62 > const extensionTelemetry = accessor.get(IExtHostTelemetry);
63 > const apiDeprecationService = accessor.get(IExtHostApiDeprecationService);
64 >
65 > const mainThreadExtensions = rpcService.getProxy(MainContext.MainThreadExtensionService);
66 > const mainThreadErrors = rpcService.getProxy(MainContext.MainThreadErrors);
67 >
68 > const extensionsRegistry = await extensionService.getExtensionRegistry();
69 > const extensionsMap = await extensionService.getExtensionPathIndex();
70 > const extensionErrors = new WeakMap<Error, { extensionIdentifier: ExtensionIdentifier | undefined; stack: string }>();
71 >
72 > // PART 1
73 > // set the prepareStackTrace-handle and use it as a side-effect to associate errors
74 > // with extensions - this works by looking up callsites in the extension path index
75 > function prepareStackTraceAndFindExtension(error: Error, stackTrace: errors.V8CallSite[]) {
76 > if (extensionErrors.has(error)) {
77 return extensionErrors.get(error)!.stack;
78 }
79 > let stackTraceMessage = ''; extensionHostMain.ts
80 > let extension: IExtensionDescription | undefined;
81 > let fileName: string | null;
82 > for (const call of stackTrace) {
83 > stackTraceMessage += `\n\tat ${call.toString()}`;
84 > fileName = call.getFileName();
85 > if (!extension && fileName) {
86 > extension = extensionsMap.findSubstr(URI.file(fileName));
87 > }
88 > }
89 > const result = `${error.name || 'Error'}: ${error.message || ''}${stackTraceMessage}`;
90 > extensionErrors.set(error, { extensionIdentifier: extension?.identifier, stack: result });
91 > return result;
92 > }
93 >
94 > const _wasWrapped = Symbol('prepareStackTrace wrapped');
95 > let _prepareStackTrace = prepareStackTraceAndFindExtension;
96 >
97 > Object.defineProperty(Error, 'prepareStackTrace', {
98 > configurable: false,
99 > get() {
100 > return _prepareStackTrace;
101 > },
102 > set(v) {
103 > if (v === prepareStackTraceAndFindExtension || !v || v[_wasWrapped]) {
104 _prepareStackTrace = v || prepareStackTraceAndFindExtension;
105 return;
106 }
108 > _prepareStackTrace = function (error, stackTrace) {
109 prepareStackTraceAndFindExtension(error, stackTrace);
110 return v.call(Error, error, stackTrace);
111 };
113 > Object.assign(_prepareStackTrace, { [_wasWrapped]: true });
114 > },
115 > });
116 >
117 > // PART 2
118 > // set the unexpectedErrorHandler and check for extensions that have been identified as
119 > // having caused the error. Note that the runtime order is actually reversed, the code
120 > // below accesses the stack-property which triggers the code above
121 > errors.setUnexpectedErrorHandler(err => {
122
123 if (!errors.PendingMigrationError.is(err)) {
151 logService.trace('forwarded error to extension?', reported, extension);
152 }
154 >
155 > errors.errorHandler.addListener(err => {
156 mainThreadErrors.$onUnexpectedError(err);
158 > }
159 > }
160 >
161 > export class ExtensionHostMain {
162 >
163 > private readonly _hostUtils: IHostUtils;
164 > private readonly _rpcProtocol: RPCProtocol;
165 > private readonly _extensionService: IExtHostExtensionService;
166 > private readonly _logService: ILogService;
167 >
168 > constructor(
169 protocol: IMessagePassingProtocol,
170 initData: IExtensionHostInitData,
210 instaService.invokeFunction(ErrorHandler.installFullHandler);
211 }
213 > async asBrowserUri(uri: URI): Promise<URI> {
214 const mainThreadExtensionsProxy = this._rpcProtocol.getProxy(MainContext.MainThreadExtensionService);
215 return URI.revive(await mainThreadExtensionsProxy.$asBrowserUri(uri));
216 }
218 > terminate(reason: string): void {
219 this._extensionService.terminate(reason);
220 }
222 > private static _transform(initData: IExtensionHostInitData, rpcProtocol: RPCProtocol): IExtensionHostInitData {
223 initData.extensions.allExtensions.forEach((ext) => {
224 (<Mutable<IExtensionDescription>>ext).extensionLocation = URI.revive(rpcProtocol.transformIncomingURIs(ext.extensionLocation));
src/vs/workbench/api/common/extHostApiDeprecationService.ts 39 introduced LOC · 5 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- extHostApiDeprecationService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { IExtensionDescription } from '../../../platform/extensions/common/extensions.js';
7 > import { createDecorator } from '../../../platform/instantiation/common/instantiation.js';
8 > import { ILogService } from '../../../platform/log/common/log.js';
9 > import * as extHostProtocol from './extHost.protocol.js';
10 > import { IExtHostRpcService } from './extHostRpcService.js';
11 >
12 > export interface IExtHostApiDeprecationService {
13 > readonly _serviceBrand: undefined;
14 >
15 > report(apiId: string, extension: IExtensionDescription, migrationSuggestion: string, options?: { usageId?: string }): void;
16 > }
17 >
18 > export const IExtHostApiDeprecationService = createDecorator<IExtHostApiDeprecationService>('IExtHostApiDeprecationService');
19 >
20 > export class ExtHostApiDeprecationService implements IExtHostApiDeprecationService {
21 >
22 > declare readonly _serviceBrand: undefined;
23 >
24 > private readonly _reportedUsages = new Set<string>();
25 > private readonly _telemetryShape: extHostProtocol.MainThreadTelemetryShape;
26 >
27 > constructor(
28 @IExtHostRpcService rpc: IExtHostRpcService,
29 @ILogService private readonly _extHostLogService: ILogService,
31 this._telemetryShape = rpc.getProxy(extHostProtocol.MainContext.MainThreadTelemetry);
32 }
34 > public report(apiId: string, extension: IExtensionDescription, migrationSuggestion: string, options?: { usageId?: string }): void {
35 const key = this.getUsageKey(apiId, extension, options?.usageId);
36 if (this._reportedUsages.has(key)) {
61 });
62 }
64 > private getUsageKey(apiId: string, extension: IExtensionDescription, usageId?: string): string {
65 const rootKey = `${apiId}-${extension.identifier.value}`;
66 return usageId ? `${rootKey}-${usageId}` : rootKey;
67 }
69 >
70 >
71 > export const NullApiDeprecationService = Object.freeze(new class implements IExtHostApiDeprecationService {
72 > declare readonly _serviceBrand: undefined;
73 >
74 > public report(_apiId: string, _extension: IExtensionDescription, _warningMessage: string): void {
75 // noop
76 }
src/vs/base/common/errors.ts 4 introduced LOC · 2 ranges

Open complete file

37
38 addListener(listener: ErrorListenerCallback): ErrorListenerUnbind {
39 > this.listeners.push(listener); errors.ts
40 >
41 > return () => {
42 this._removeListener(listener);
43 };
44 > } errors.ts
45
46 private emit(e: any): void {
src/vs/workbench/api/common/extHostExtensionService.ts 2 introduced LOC · 1 range

Open complete file

1244
1245 constructor(
1246 > private _searchTree: TernarySearchTree<URI, IExtensionDescription> extHostExtensionService.ts
1247 > ) { }
1248
1249 setSearchTree(searchTree: TernarySearchTree<URI, IExtensionDescription>): void {