Skip to content
This repository was archived by the owner on Sep 17, 2021. It is now read-only.

Commit df2e937

Browse files
committed
intial work
1 parent f8a5027 commit df2e937

File tree

4 files changed

+66
-27
lines changed

4 files changed

+66
-27
lines changed

package-lock.json

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"@types/node": "^10.5.2",
127127
"@types/shelljs": "^0.8.0",
128128
"@types/ws": "^6.0.1",
129+
"@types/applicationinsights": "^0.20.0",
129130
"shelljs": "^0.8.2",
130131
"ts-node": "^7.0.1",
131132
"tslint": "^5.11.0",

src/extension.ts

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface IPackageInfo {
1212
}
1313

1414
const debuggerType: string = 'devtools-for-chrome';
15+
const defaultUrl: string = 'about:blank';
1516
let telemetryReporter: TelemetryReporter;
1617

1718
export function activate(context: vscode.ExtensionContext) {
@@ -31,7 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
3132
}));
3233

3334
context.subscriptions.push(vscode.commands.registerCommand('devtools-for-chrome.attach', async () => {
34-
attach(context, /* viaConfig= */ false);
35+
attach(context, /* viaConfig= */ false, defaultUrl);
3536
}));
3637

3738
vscode.debug.registerDebugConfigurationProvider(debuggerType, {
@@ -46,18 +47,11 @@ export function activate(context: vscode.ExtensionContext) {
4647

4748
resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
4849
if (config && config.type == debuggerType) {
50+
let targetUri: string = utils.getUrlFromConfig(folder, config);
4951
if (config.request && config.request.localeCompare('attach', 'en', { sensitivity: 'base' }) == 0) {
50-
attach(context, /* viaConfig= */ true);
51-
} else {
52-
let launchUri: string = '';
53-
if (folder.uri.scheme == 'file') {
54-
const baseUrl: string = config.file || config.url;
55-
const replacedUri: string = baseUrl.replace('${workspaceFolder}', folder.uri.path);
56-
launchUri = utils.pathToFileURL(replacedUri);
57-
} else {
58-
launchUri = config.url;
59-
}
60-
launch(context, launchUri, config.chromePath);
52+
attach(context, /* viaConfig= */ true, defaultUrl);
53+
} else if (config.request && config.request.localeCompare('launch', 'en', { sensitivity: 'base' }) == 0) {
54+
launch(context, targetUri, config.chromePath);
6155
}
6256
} else {
6357
vscode.window.showErrorMessage('No supported launch config was found.');
@@ -84,21 +78,21 @@ async function launch(context: vscode.ExtensionContext, launchUrl?: string, chro
8478
return;
8579
}
8680

87-
utils.launchLocalChrome(pathToChrome, port, 'about:blank');
81+
utils.launchLocalChrome(pathToChrome, port, defaultUrl);
8882
}
8983

9084
const target = JSON.parse(await utils.getURL(`http://${hostname}:${port}/json/new?${launchUrl}`));
9185

9286
if (!target || !target.webSocketDebuggerUrl || target.webSocketDebuggerUrl == '') {
9387
vscode.window.showErrorMessage(`Could not find the launched Chrome tab: (${launchUrl}).`);
9488
telemetryReporter.sendTelemetryEvent('launch/error/tab_not_found', telemetryProps);
95-
attach(context, viaConfig);
89+
attach(context, viaConfig, defaultUrl);
9690
} else {
9791
DevToolsPanel.createOrShow(context, target.webSocketDebuggerUrl);
9892
}
9993
}
10094

101-
async function attach(context: vscode.ExtensionContext, viaConfig: boolean) {
95+
async function attach(context: vscode.ExtensionContext, viaConfig: boolean, targetUrl: string) {
10296
const telemetryProps = { viaConfig: `${viaConfig}` };
10397
telemetryReporter.sendTelemetryEvent('attach', telemetryProps);
10498

@@ -111,14 +105,34 @@ async function attach(context: vscode.ExtensionContext, viaConfig: boolean) {
111105

112106
responseArray.forEach(i => {
113107
i = utils.fixRemoteUrl(hostname, port, i);
114-
items.push({ label: i.title, description: i.url, detail: i.webSocketDebuggerUrl });
108+
items.push({
109+
label: i.title,
110+
description: i.url,
111+
detail: i.webSocketDebuggerUrl
112+
});
115113
});
116114

117-
vscode.window.showQuickPick(items).then((selection) => {
118-
if (selection) {
119-
DevToolsPanel.createOrShow(context, selection.detail as string);
115+
let targetUrl: string = '';
116+
let targetMatch:boolean = false;
117+
if (typeof targetUrl === 'string' && targetUrl.length > 0 && targetUrl != defaultUrl) {
118+
const matches = items.filter(i => i.description == defaultUrl);
119+
if(matches && matches.length > 0 ){
120+
targetUrl = matches[0].description;
121+
targetMatch = true;
122+
} else {
123+
vscode.window.showErrorMessage(`Couldn't attach to ${targetUrl}.`);
120124
}
121-
});
125+
}
126+
127+
if(targetMatch){
128+
DevToolsPanel.createOrShow(context, targetUrl as string);
129+
} else {
130+
vscode.window.showQuickPick(items).then((selection) => {
131+
if (selection) {
132+
DevToolsPanel.createOrShow(context, selection.detail as string);
133+
}
134+
});
135+
}
122136
} else {
123137
telemetryReporter.sendTelemetryEvent('attach/error/no_json_array', telemetryProps);
124138
}
@@ -331,10 +345,10 @@ class DevToolsPanel {
331345
private _getDevtoolsState() {
332346
const allPrefsKey = 'devtools-preferences';
333347
const allPrefs: any = this._context.workspaceState.get(allPrefsKey) ||
334-
{
335-
uiTheme: '"dark"',
336-
screencastEnabled: false
337-
};
348+
{
349+
uiTheme: '"dark"',
350+
screencastEnabled: false
351+
};
338352
this._panel.webview.postMessage(`preferences:${JSON.stringify(allPrefs)}`);
339353
}
340354

@@ -359,7 +373,7 @@ class DevToolsPanel {
359373
content = '';
360374
}
361375

362-
this._panel.webview.postMessage(`setUrl:${JSON.stringify({id: request.id, content})}`);
376+
this._panel.webview.postMessage(`setUrl:${JSON.stringify({ id: request.id, content })}`);
363377
}
364378

365379
private _update() {

src/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as net from 'net';
66
import * as os from 'os';
77
import * as path from 'path';
88
import * as url from 'url';
9+
import * as vscode from 'vscode';
910

1011
export function getURL(aUrl: string, options: https.RequestOptions = {}): Promise<string> {
1112
return new Promise((resolve, reject) => {
@@ -140,4 +141,18 @@ export function forceForwardSlashes(aUrl: string): string {
140141
return aUrl
141142
.replace(/\\\//g, '/') // Replace \/ (unnecessarily escaped forward slash)
142143
.replace(/\\/g, '/');
144+
}
145+
146+
export function getUrlFromConfig(folder: vscode.WorkspaceFolder, config: vscode.DebugConfiguration): string {
147+
let outUrlString:string = '';
148+
149+
if (config.file) {
150+
outUrlString = config.file;
151+
outUrlString = outUrlString.replace('${workspaceFolder}', folder.uri.path);
152+
outUrlString = pathToFileURL(outUrlString);
153+
} else if(config.url){
154+
outUrlString = config.url;
155+
}
156+
157+
return outUrlString;
143158
}

0 commit comments

Comments
 (0)