Skip to content

Commit

Permalink
debug: try to wait for a debugger before running extensions (#108141)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 authored Oct 7, 2020
1 parent 920fefb commit 8085054
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/vs/platform/debug/electron-main/extensionHostDebugIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class ElectronExtensionHostDebugBroadcastChannel<TContext> extends Extens

private async openExtensionDevelopmentHostWindow(args: string[], env: IProcessEnvironment, debugRenderer: boolean): Promise<IOpenExtensionWindowResult> {
const pargs = parseArgs(args, OPTIONS);
pargs.debugRenderer = debugRenderer;

const extDevPaths = pargs.extensionDevelopmentPath;
if (!extDevPaths) {
return {};
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/environment/common/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface NativeParsedArgs {
'inspect-extensions'?: string;
'inspect-brk-extensions'?: string;
debugId?: string;
debugRenderer?: boolean; // whether we expect a debugger (js-debug) to attach to the renderer, incl webviews+webworker
'inspect-search'?: string;
'inspect-brk-search'?: string;
'disable-extensions'?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/environment/node/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const OPTIONS: OptionDescriptions<Required<NativeParsedArgs>> = {
'extensionDevelopmentPath': { type: 'string[]' },
'extensionTestsPath': { type: 'string' },
'debugId': { type: 'string' },
'debugRenderer': { type: 'boolean' },
'inspect-search': { type: 'string', deprecates: 'debugSearch' },
'inspect-brk-search': { type: 'string', deprecates: 'debugBrkSearch' },
'export-default-configuration': { type: 'string' },
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/environment/node/environmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export class NativeEnvironmentService implements INativeEnvironmentService {

@memoize
get debugExtensionHost(): IExtensionHostDebugParams { return parseExtensionHostPort(this._args, this.isBuilt); }
get debugRenderer(): boolean { return !!this._args.debugRenderer; }

get isBuilt(): boolean { return !process.env['VSCODE_DEV']; }
get verbose(): boolean { return !!this._args.verbose; }
Expand Down
14 changes: 14 additions & 0 deletions src/vs/workbench/api/worker/extHostExtensionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { URI } from 'vs/base/common/uri';
import { RequireInterceptor } from 'vs/workbench/api/common/extHostRequireInterceptor';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { ExtensionRuntime } from 'vs/workbench/api/common/extHostTypes';
import { timeout } from 'vs/base/common/async';

class WorkerRequireInterceptor extends RequireInterceptor {

Expand Down Expand Up @@ -41,6 +42,7 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
const apiFactory = this._instaService.invokeFunction(createApiFactoryAndRegisterActors);
this._fakeModules = this._instaService.createInstance(WorkerRequireInterceptor, apiFactory, this._registry);
await this._fakeModules.install();
await this._waitForDebuggerAttachment();
}

protected _getEntryPoint(extensionDescription: IExtensionDescription): string | undefined {
Expand Down Expand Up @@ -86,6 +88,18 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
async $setRemoteEnvironment(_env: { [key: string]: string | null }): Promise<void> {
throw new Error('Not supported');
}

private async _waitForDebuggerAttachment(waitTimeout = 5000) {
// debugger attaches async, waiting for it fixes #106698 and #99222
if (!this._initData.environment.isExtensionDevelopmentDebug) {
return;
}

const deadline = Date.now() + waitTimeout;
while (Date.now() < deadline && !('__jsDebugIsReady' in globalThis)) {
await timeout(10);
}
}
}

function ensureSuffix(path: string, suffix: string): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class SimpleNativeWorkbenchEnvironmentService implements INativeWorkbench
keyboardLayoutResource: URI = undefined!;
sync: 'on' | 'off' | undefined;
debugExtensionHost: IExtensionHostDebugParams = undefined!;
debugRenderer = false;
isExtensionDevelopment: boolean = false;
disableExtensions: boolean | string[] = [];
extensionDevelopmentLocationURI?: URI[] | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ interface IBrowserWorkbenchOptions extends IWorkbenchOptions {

interface IExtensionHostDebugEnvironment {
params: IExtensionHostDebugParams;
debugRenderer: boolean;
isExtensionDevelopment: boolean;
extensionDevelopmentLocationURI?: URI[];
extensionTestsLocationURI?: URI;
Expand Down Expand Up @@ -206,6 +207,14 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
return this._extensionHostDebugEnvironment.extensionEnabledProposedApi;
}

get debugRenderer(): boolean {
if (!this._extensionHostDebugEnvironment) {
this._extensionHostDebugEnvironment = this.resolveExtensionHostDebugEnvironment();
}

return this._extensionHostDebugEnvironment.debugRenderer;
}

get disableExtensions() { return this.payload?.get('disableExtensions') === 'true'; }

private get webviewEndpoint(): string {
Expand Down Expand Up @@ -257,6 +266,7 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
port: null,
break: false
},
debugRenderer: false,
isExtensionDevelopment: false,
extensionDevelopmentLocationURI: undefined
};
Expand All @@ -272,6 +282,9 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
case 'extensionTestsPath':
extensionHostDebugEnvironment.extensionTestsLocationURI = URI.parse(value);
break;
case 'debugRenderer':
extensionHostDebugEnvironment.debugRenderer = value === 'true';
break;
case 'debugId':
extensionHostDebugEnvironment.params.debugId = value;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface IWorkbenchEnvironmentService extends IEnvironmentService {

readonly skipReleaseNotes: boolean;

readonly debugRenderer: boolean;

/**
* @deprecated this property will go away eventually as it
* duplicates many properties of the environment service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class WebWorkerExtensionHost extends Disposable implements IExtensionHost
version: this._productService.version,
parentPid: -1,
environment: {
isExtensionDevelopmentDebug: false, //todo@jrieken web
isExtensionDevelopmentDebug: this._environmentService.debugRenderer,
appName: this._productService.nameLong,
appUriScheme: this._productService.urlProtocol,
appLanguage: platform.language,
Expand Down

0 comments on commit 8085054

Please sign in to comment.