Use nullable `targetTypes` property for advanced debugging configurations.

This commit is contained in:
Sasha Joseph 2018-09-04 18:21:50 -07:00
Родитель 63aa1276d8
Коммит 4c59042cf1
10 изменённых файлов: 53 добавлений и 10 удалений

Просмотреть файл

@ -133,6 +133,7 @@ See our wiki page for some configured example apps: [Examples](https://github.co
* `userDataDir`: Normally, if Chrome is already running when you start debugging with a launch config, then the new instance won't start in remote debugging mode. So by default, the extension launches Chrome with a separate user profile in a temp folder. Use this option to set a different path to use, or set to false to launch with your default user profile.
* `url`: On a 'launch' config, it will launch Chrome at this URL.
* `urlFilter`: On an 'attach' config, or a 'launch' config with no 'url' set, search for a page with this url and attach to it. It can also contain wildcards, for example, `"localhost:*/app"` will match either `"http://localhost:123/app"` or `"http://localhost:456/app"`, but not `"https://stackoverflow.com"`.
* `targetTypes`: On an 'attach' config, or a 'launch' config with no 'url' set, set a list of acceptable target types from the default `["page"]`. For example, if you are attaching to an Electron app, you might want to set this to `["page", "webview"]`. A value of `null` disables filtering by target type.
* `sourceMaps`: By default, the adapter will use sourcemaps and your original sources whenever possible. You can disable this by setting `sourceMaps` to false.
* `pathMapping`: This property takes a mapping of URL paths to local paths, to give you more flexibility in how URLs are resolved to local files. `"webRoot": "${workspaceFolder}"` is just shorthand for a pathMapping like `{ "/": "${workspaceFolder}" }`.
* `smartStep`: Automatically steps over code that doesn't map to source files. Especially useful for debugging with async/await.

Просмотреть файл

@ -381,6 +381,11 @@
"description": "%chrome.urlFilter.description%",
"default": ""
},
"targetTypes": {
"type": ["array", "null"],
"description": "%chrome.targetTypes.description%",
"default": ["page"]
},
"showAsyncStacks": {
"type": "boolean",
"description": "%chrome.showAsyncStacks.description%",

Просмотреть файл

@ -25,6 +25,7 @@
"chrome.timeout.description": "Retry for this number of milliseconds to connect to Chrome. Default is 10000 ms.",
"chrome.disableNetworkCache.description": "Controls whether to skip the network cache for each request",
"chrome.urlFilter.description": "Will search for a page with this url and attach to it, if found. Can have * wildcards.",
"chrome.targetTypes.description": "An array of acceptable target types. The default is `[\"page\"]`.",
"chrome.showAsyncStacks.description": "Show the async calls that led to the current call stack",
"chrome.breakOnLoad.description": "Experimental feature - If true, the debug adapter will attempt to set breakpoints in scripts before they are loaded, so it can hit breakpoints at the beginnings of those scripts. Has a perf impact.",
"chrome.breakOnLoadStrategy.description": "The strategy to use for breakOnLoad.",

Просмотреть файл

@ -5,7 +5,7 @@
import { ChromeDebugSession, logger, UrlPathTransformer, BaseSourceMapTransformer, telemetry } from 'vscode-chrome-debug-core';
import * as path from 'path';
import * as os from 'os';
import { targetFilter } from './utils';
import { defaultTargetFilter } from './utils';
import { ChromeDebugAdapter } from './chromeDebugAdapter';
@ -18,7 +18,7 @@ ChromeDebugSession.run(ChromeDebugSession.getSession(
adapter: ChromeDebugAdapter,
extensionName: EXTENSION_NAME,
logFilePath: path.resolve(os.tmpdir(), 'vscode-chrome-debug.txt'),
targetFilter,
targetFilter: defaultTargetFilter,
pathTransformer: UrlPathTransformer,
sourceMapTransformer: BaseSourceMapTransformer,

Просмотреть файл

@ -206,6 +206,12 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
args.sourceMapPathOverrides = getSourceMapPathOverrides(args.webRoot, args.sourceMapPathOverrides);
args.skipFileRegExps = ['^chrome-extension:.*'];
if (args.targetTypes === undefined) {
args.targetFilter = utils.defaultTargetFilter;
} else {
args.targetFilter = utils.getTargetFilter(args.targetTypes);
}
super.commonArgs(args);
}

2
src/chromeDebugInterfaces.d.ts поставляемый
Просмотреть файл

@ -8,6 +8,8 @@ import { DebugProtocol } from 'vscode-debugprotocol';
export interface ICommonRequestArgs extends Core.ICommonRequestArgs {
webRoot?: string;
disableNetworkCache?: boolean;
targetTypes?: string[];
targetFilter?: Core.chromeConnection.ITargetFilter;
urlFilter?: string;
}

Просмотреть файл

@ -4,10 +4,10 @@
import * as vscode from 'vscode';
import * as Core from 'vscode-chrome-debug-core';
import { targetFilter } from './utils';
import * as nls from 'vscode-nls';
import { defaultTargetFilter } from './utils';
const localize = nls.loadMessageBundle();
export function activate(context: vscode.ExtensionContext) {
@ -50,7 +50,7 @@ export class ChromeConfigurationProvider implements vscode.DebugConfigurationPro
let targets;
try {
targets = await discovery.getAllTargets(config.address || '127.0.0.1', config.port, targetFilter, config.url || config.urlFilter);
targets = await discovery.getAllTargets(config.address || '127.0.0.1', config.port, defaultTargetFilter, config.url || config.urlFilter);
} catch (e) {
// Target not running?
}

Просмотреть файл

@ -3,7 +3,7 @@
*--------------------------------------------------------*/
import * as path from 'path';
import {utils as coreUtils, chromeConnection } from 'vscode-chrome-debug-core';
import { utils as coreUtils, chromeConnection } from 'vscode-chrome-debug-core';
const WIN_APPDATA = process.env.LOCALAPPDATA || '/';
const DEFAULT_CHROME_PATH = {
@ -64,5 +64,12 @@ export class DebounceHelper {
}
}
export const targetFilter: chromeConnection.ITargetFilter =
target => target && (!target.type || target.type === 'page');
export const getTargetFilter = (targetTypes?: string[]): chromeConnection.ITargetFilter => {
if (targetTypes) {
return target => target && (!target.type || targetTypes.indexOf(target.type) !== -1);
}
return () => true;
};
export const defaultTargetFilter = getTargetFilter(['page']);

Просмотреть файл

@ -46,6 +46,9 @@ suite('ChromeDebugAdapter', () => {
.setup(x => x.sendRequest(It.isAnyString(), It.isAny(), It.isAnyNumber(), It.isAny()))
.verifiable(Times.atLeast(0));
mockChromeConnection
.setup(x => x.setTargetFilter(It.isAny()))
.verifiable(Times.atLeast(0));
mockChromeConnection
.setup(x => x.api)
.returns(() => mockChrome.apiObjects)

Просмотреть файл

@ -79,4 +79,22 @@ suite('Utils', () => {
'/usr/bin/google-chrome');
});
});
});
suite('getTargetFilter()', () => {
test('defaultTargetFilter', () => {
const {defaultTargetFilter} = getUtils();
const targets = [{type: 'page'}, {type: 'webview'}];
assert.deepEqual(targets.filter(defaultTargetFilter), [{type: 'page'}]);
});
test('getTargetFilter', () => {
const {getTargetFilter} = getUtils();
const targets = [{type: 'page'}, {type: 'webview'}];
assert.deepEqual(targets.filter(getTargetFilter(['page'])), [{type: 'page'}]);
assert.deepEqual(targets.filter(getTargetFilter(['webview'])), [{type: 'webview'}]);
assert.deepEqual(targets.filter(getTargetFilter(['page', 'webview'])), targets);
// Falsy targetTypes should effectively disable filtering.
assert.deepEqual(targets.filter(getTargetFilter()), targets);
});
});
});