From 2ae090cdf65c192247eed35bb0d3dc775ff8d60f Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Mon, 4 Sep 2017 14:08:40 -0700 Subject: [PATCH] Introduce a --inspect-search CLI argument, and enter debug mode by default when built locally --- .vscode/launch.json | 11 ++++- .../environment/common/environment.ts | 16 +++++- src/vs/platform/environment/node/argv.ts | 4 ++ .../environment/node/environmentService.ts | 25 +++++++--- .../services/search/node/searchService.ts | 49 +++++++++++-------- 5 files changed, 74 insertions(+), 31 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8c42acc6037..7c31e06bd36 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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" ] @@ -177,6 +177,13 @@ "Launch VS Code", "Attach to Main Process" ] + }, + { + "name": "Search and Renderer processes", + "configurations": [ + "Launch VS Code", + "Attach to Search Process" + ] } ] } \ No newline at end of file diff --git a/src/vs/platform/environment/common/environment.ts b/src/vs/platform/environment/common/environment.ts index b37a0f4c6a9..b4ee3dfcca3 100644 --- a/src/vs/platform/environment/common/environment.ts +++ b/src/vs/platform/environment/common/environment.ts @@ -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[]; @@ -42,6 +44,15 @@ export interface ParsedArgs { export const IEnvironmentService = createDecorator('environmentService'); +export interface IDebugParams { + port: number; + break: boolean; +} + +export interface IExtensionHostDebugParams extends IDebugParams { + debugId: string; +} + export interface IEnvironmentService { _serviceBrand: any; @@ -71,7 +82,8 @@ export interface IEnvironmentService { extensionDevelopmentPath: string; extensionTestsPath: string; - debugExtensionHost: { port: number; break: boolean; debugId: string }; + debugExtensionHost: IExtensionHostDebugParams; + debugSearch: IDebugParams; logExtensionHostCommunication: boolean; diff --git a/src/vs/platform/environment/node/argv.ts b/src/vs/platform/environment/node/argv.ts index 939d445c291..7f81ffa9d2f 100644 --- a/src/vs/platform/environment/node/argv.ts +++ b/src/vs/platform/environment/node/argv.ts @@ -23,6 +23,8 @@ const options: minimist.Opts = { 'debugId', 'debugPluginHost', 'debugBrkPluginHost', + 'debugSearch', + 'debugBrkSearch', 'open-url', 'enable-proposed-api' ], @@ -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', } }; diff --git a/src/vs/platform/environment/node/environmentService.ts b/src/vs/platform/environment/node/environmentService.ts index 8823268a00a..9ba9802831a 100644 --- a/src/vs/platform/environment/node/environmentService.ts +++ b/src/vs/platform/environment/node/environmentService.ts @@ -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'; @@ -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; } @@ -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 { diff --git a/src/vs/workbench/services/search/node/searchService.ts b/src/vs/workbench/services/search/node/searchService.ts index 860a1fdc7ba..1ff0178c591 100644 --- a/src/vs/workbench/services/search/node/searchService.ts +++ b/src/vs/workbench/services/search/node/searchService.ts @@ -10,7 +10,7 @@ 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'; @@ -18,7 +18,7 @@ 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'; @@ -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); } @@ -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('search')); this.raw = new SearchChannelClient(channel);