Skip to content

Commit 37cae2b

Browse files
Open browser after launching (#214)
* Add autoStartBrowser and serverReady * add tests * fix lint * fix tests * remove only in test * send telemetry * fix lint
1 parent 25e00ca commit 37cae2b

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@
327327
"description": "Path (fully qualified) to the Python debug adapter executable.",
328328
"type": "string"
329329
},
330+
"autoStartBrowser": {
331+
"default": false,
332+
"description": "Open external browser to launch the application",
333+
"type": "boolean"
334+
},
330335
"django": {
331336
"default": false,
332337
"description": "Django debugging.",

src/extension/debugger/configuration/resolvers/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
245245
stopOnEntry: !!debugConfiguration.stopOnEntry,
246246
showReturnValue: !!debugConfiguration.showReturnValue,
247247
subProcess: !!debugConfiguration.subProcess,
248+
autoStartBrowser: !!debugConfiguration,
248249
watson: name.toLowerCase().indexOf('watson') >= 0,
249250
pyspark: name.toLowerCase().indexOf('pyspark') >= 0,
250251
gevent: name.toLowerCase().indexOf('gevent') >= 0,

src/extension/debugger/configuration/resolvers/launch.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
140140
}
141141
const isFastAPI = LaunchConfigurationResolver.isDebuggingFastAPI(debugConfiguration);
142142
const isFlask = LaunchConfigurationResolver.isDebuggingFlask(debugConfiguration);
143+
if (debugConfiguration.autoStartBrowser && (debugConfiguration.django || isFlask)) {
144+
debugConfiguration.serverReadyAction = {
145+
pattern: '.*(https?:\\/\\/\\S+:[0-9]+\\/?).*',
146+
uriFormat: '%s',
147+
action: 'openExternally',
148+
};
149+
}
143150
if (
144151
(debugConfiguration.pyramid || isFlask || isFastAPI) &&
145152
debugOptions.indexOf(DebugOptions.Jinja) === -1 &&

src/extension/telemetry/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,12 @@ export interface IEventNamePropertyMapping {
570570
* @type {boolean}
571571
*/
572572
scrapy: boolean;
573+
/**
574+
* Whether degbugging with autoStartBrowser.
575+
*
576+
* @type {boolean}
577+
*/
578+
autoStartBrowser: boolean;
573579
};
574580
/**
575581
* Telemetry event sent when attaching to child process

src/test/unittest/configuration/resolvers/launch.unit.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,37 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
922922
expect((debugConfig as DebugConfiguration).debugOptions).contains(DebugOptions.Jinja);
923923
});
924924

925+
const testsForautoStartBrowser = [
926+
{
927+
autoStartBrowser: true,
928+
module: 'flask',
929+
},
930+
{
931+
autoStartBrowser: true,
932+
django: true,
933+
},
934+
];
935+
936+
test('Add serverReadyAction for Django and Flask', async () => {
937+
const pythonPath = `PythonPath_${new Date().toString()}`;
938+
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
939+
const pythonFile = 'xyz.py';
940+
setupIoc(pythonPath);
941+
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
942+
const expectedServerReadyAction = {
943+
pattern: '.*(https?:\\/\\/\\S+:[0-9]+\\/?).*',
944+
uriFormat: '%s',
945+
action: 'openExternally',
946+
};
947+
testsForautoStartBrowser.forEach(async (testParams) => {
948+
const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
949+
...launch,
950+
...testParams,
951+
});
952+
expect(debugConfig).to.have.property('serverReadyAction', expectedServerReadyAction);
953+
});
954+
});
955+
925956
async function testSetting(
926957
requestType: 'launch' | 'attach',
927958
settings: Record<string, boolean>,

0 commit comments

Comments
 (0)