Skip to content

Commit

Permalink
Introduce a --inspect-search CLI argument, and enter debug mode by de…
Browse files Browse the repository at this point in the history
…fault when built locally
  • Loading branch information
roblourens committed Sep 4, 2017
1 parent 3e23c21 commit 2ae090c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 31 deletions.
11 changes: 9 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"type": "node",
"request": "attach",
"protocol": "inspector",
"name": "Attach to Search process",
"port": 7890,
"name": "Attach to Search Process",
"port": 5876,
"outFiles": [
"${workspaceRoot}/out/**/*.js"
]
Expand Down Expand Up @@ -177,6 +177,13 @@
"Launch VS Code",
"Attach to Main Process"
]
},
{
"name": "Search and Renderer processes",
"configurations": [
"Launch VS Code",
"Attach to Search Process"
]
}
]
}
16 changes: 14 additions & 2 deletions src/vs/platform/environment/common/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export interface ParsedArgs {
'extensions-dir'?: string;
extensionDevelopmentPath?: string;
extensionTestsPath?: string;
debugPluginHost?: string;
debugBrkPluginHost?: string;
debugId?: string;
debugPluginHost?: string;
debugSearch?: string;
debugBrkSearch?: string;
'list-extensions'?: boolean;
'show-versions'?: boolean;
'install-extension'?: string | string[];
Expand All @@ -42,6 +44,15 @@ export interface ParsedArgs {

export const IEnvironmentService = createDecorator<IEnvironmentService>('environmentService');

export interface IDebugParams {
port: number;
break: boolean;
}

export interface IExtensionHostDebugParams extends IDebugParams {
debugId: string;
}

export interface IEnvironmentService {
_serviceBrand: any;

Expand Down Expand Up @@ -71,7 +82,8 @@ export interface IEnvironmentService {
extensionDevelopmentPath: string;
extensionTestsPath: string;

debugExtensionHost: { port: number; break: boolean; debugId: string };
debugExtensionHost: IExtensionHostDebugParams;
debugSearch: IDebugParams;


logExtensionHostCommunication: boolean;
Expand Down
4 changes: 4 additions & 0 deletions src/vs/platform/environment/node/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const options: minimist.Opts = {
'debugId',
'debugPluginHost',
'debugBrkPluginHost',
'debugSearch',
'debugBrkSearch',
'open-url',
'enable-proposed-api'
],
Expand Down Expand Up @@ -60,6 +62,8 @@ const options: minimist.Opts = {
'extensions-dir': 'extensionHomePath',
'debugPluginHost': 'inspect-extensions',
'debugBrkPluginHost': 'inspect-brk-extensions',
'debugSearch': 'inspect-search',
'debugBrkSearch': 'inspect-brk-search',
}
};

Expand Down
25 changes: 18 additions & 7 deletions src/vs/platform/environment/node/environmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
import { IEnvironmentService, ParsedArgs, IDebugParams, IExtensionHostDebugParams } from 'vs/platform/environment/common/environment';
import * as crypto from 'crypto';
import * as paths from 'vs/base/node/paths';
import * as os from 'os';
Expand Down Expand Up @@ -111,7 +111,10 @@ export class EnvironmentService implements IEnvironmentService {
get skipGettingStarted(): boolean { return this._args['skip-getting-started']; }

@memoize
get debugExtensionHost(): { port: number; break: boolean; debugId: string } { return parseExtensionHostPort(this._args, this.isBuilt); }
get debugExtensionHost(): IExtensionHostDebugParams { return parseExtensionHostPort(this._args, this.isBuilt); }

@memoize
get debugSearch(): IDebugParams { return parseSearchPort(this._args, this.isBuilt); }

get isBuilt(): boolean { return !process.env['VSCODE_DEV']; }
get verbose(): boolean { return this._args.verbose; }
Expand Down Expand Up @@ -160,11 +163,19 @@ export class EnvironmentService implements IEnvironmentService {
}
}

export function parseExtensionHostPort(args: ParsedArgs, isBuild: boolean): { port: number; break: boolean; debugId: string } {
const portStr = args.debugBrkPluginHost || args.debugPluginHost;
const port = Number(portStr) || (!isBuild ? 5870 : null);
const brk = port ? Boolean(!!args.debugBrkPluginHost) : false;
return { port, break: brk, debugId: args.debugId };
export function parseExtensionHostPort(args: ParsedArgs, isBuild: boolean): IExtensionHostDebugParams {
return parseDebugPort(args.debugPluginHost, args.debugBrkPluginHost, 5870, isBuild, args.debugId);
}

export function parseSearchPort(args: ParsedArgs, isBuild: boolean): IDebugParams {
return parseDebugPort(args.debugSearch, args.debugBrkSearch, 5876, isBuild);
}

export function parseDebugPort(debugArg: string, debugBrkArg: string, defaultBuildPort: number, isBuild: boolean, debugId?: string): IExtensionHostDebugParams {
const portStr = debugBrkArg || debugArg;
const port = Number(portStr) || (!isBuild ? defaultBuildPort : null);
const brk = port ? Boolean(!!debugBrkArg) : false;
return { port, break: brk, debugId };
}

function parsePathArg(arg: string, process: NodeJS.Process): string {
Expand Down
49 changes: 29 additions & 20 deletions src/vs/workbench/services/search/node/searchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import objects = require('vs/base/common/objects');
import scorer = require('vs/base/common/scorer');
import strings = require('vs/base/common/strings');
import { getNextTickChannel } from 'vs/base/parts/ipc/common/ipc';
import { Client } from 'vs/base/parts/ipc/node/ipc.cp';
import { Client, IIPCOptions } from 'vs/base/parts/ipc/node/ipc.cp';
import { IProgress, LineMatch, FileMatch, ISearchComplete, ISearchProgressItem, QueryType, IFileMatch, ISearchQuery, ISearchConfiguration, ISearchService, pathIncludedInQuery, ISearchResultProvider } from 'vs/platform/search/common/search';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IRawSearch, IFolderSearch, ISerializedSearchComplete, ISerializedSearchProgressItem, ISerializedFileMatch, IRawSearchService } from './search';
import { ISearchChannel, SearchChannelClient } from './searchIpc';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IEnvironmentService, IDebugParams } from 'vs/platform/environment/common/environment';
import { ResourceMap } from 'vs/base/common/map';
import { IDisposable } from 'vs/base/common/lifecycle';

Expand All @@ -35,7 +35,7 @@ export class SearchService implements ISearchService {
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IConfigurationService private configurationService: IConfigurationService
) {
this.diskSearch = new DiskSearch(!environmentService.isBuilt || environmentService.verbose);
this.diskSearch = new DiskSearch(!environmentService.isBuilt || environmentService.verbose, /*timeout=*/undefined, environmentService.debugSearch);
this.registerSearchResultProvider(this.diskSearch);
}

Expand Down Expand Up @@ -212,25 +212,34 @@ export class DiskSearch implements ISearchResultProvider {

private raw: IRawSearchService;

constructor(verboseLogging: boolean, timeout: number = 60 * 60 * 1000) {
constructor(verboseLogging: boolean, timeout: number = 60 * 60 * 1000, searchDebug?: IDebugParams) {
const opts: IIPCOptions = {
serverName: 'Search',
timeout: timeout,
args: ['--type=searchService'],
// See https://github.com/Microsoft/vscode/issues/27665
// Pass in fresh execArgv to the forked process such that it doesn't inherit them from `process.execArgv`.
// e.g. Launching the extension host process with `--inspect-brk=xxx` and then forking a process from the extension host
// results in the forked process inheriting `--inspect-brk=xxx`.
freshExecArgv: true,
env: {
AMD_ENTRYPOINT: 'vs/workbench/services/search/node/searchApp',
PIPE_LOGGING: 'true',
VERBOSE_LOGGING: verboseLogging
}
};

if (searchDebug) {
if (searchDebug.break && searchDebug.port) {
opts.debugBrk = searchDebug.port;
} else if (!searchDebug.break && searchDebug.port) {
opts.debug = searchDebug.port;
}
}

const client = new Client(
uri.parse(require.toUrl('bootstrap')).fsPath,
{
serverName: 'Search',
timeout: timeout,
args: ['--type=searchService'],
// See https://github.com/Microsoft/vscode/issues/27665
// Pass in fresh execArgv to the forked process such that it doesn't inherit them from `process.execArgv`.
// e.g. Launching the extension host process with `--inspect-brk=xxx` and then forking a process from the extension host
// results in the forked process inheriting `--inspect-brk=xxx`.
freshExecArgv: true,
env: {
AMD_ENTRYPOINT: 'vs/workbench/services/search/node/searchApp',
PIPE_LOGGING: 'true',
VERBOSE_LOGGING: verboseLogging
}
}
);
opts);

const channel = getNextTickChannel(client.getChannel<ISearchChannel>('search'));
this.raw = new SearchChannelClient(channel);
Expand Down

0 comments on commit 2ae090c

Please sign in to comment.