Skip to content

Commit

Permalink
Open browser after launching (#214)
Browse files Browse the repository at this point in the history
* Add autoStartBrowser and serverReady

* add tests

* fix lint

* fix tests

* remove only in test

* send telemetry

* fix lint
  • Loading branch information
paulacamargo25 authored Feb 16, 2024
1 parent 25e00ca commit 37cae2b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@
"description": "Path (fully qualified) to the Python debug adapter executable.",
"type": "string"
},
"autoStartBrowser": {
"default": false,
"description": "Open external browser to launch the application",
"type": "boolean"
},
"django": {
"default": false,
"description": "Django debugging.",
Expand Down
1 change: 1 addition & 0 deletions src/extension/debugger/configuration/resolvers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export abstract class BaseConfigurationResolver<T extends DebugConfiguration>
stopOnEntry: !!debugConfiguration.stopOnEntry,
showReturnValue: !!debugConfiguration.showReturnValue,
subProcess: !!debugConfiguration.subProcess,
autoStartBrowser: !!debugConfiguration,
watson: name.toLowerCase().indexOf('watson') >= 0,
pyspark: name.toLowerCase().indexOf('pyspark') >= 0,
gevent: name.toLowerCase().indexOf('gevent') >= 0,
Expand Down
7 changes: 7 additions & 0 deletions src/extension/debugger/configuration/resolvers/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ export class LaunchConfigurationResolver extends BaseConfigurationResolver<Launc
}
const isFastAPI = LaunchConfigurationResolver.isDebuggingFastAPI(debugConfiguration);
const isFlask = LaunchConfigurationResolver.isDebuggingFlask(debugConfiguration);
if (debugConfiguration.autoStartBrowser && (debugConfiguration.django || isFlask)) {
debugConfiguration.serverReadyAction = {
pattern: '.*(https?:\\/\\/\\S+:[0-9]+\\/?).*',
uriFormat: '%s',
action: 'openExternally',
};
}
if (
(debugConfiguration.pyramid || isFlask || isFastAPI) &&
debugOptions.indexOf(DebugOptions.Jinja) === -1 &&
Expand Down
6 changes: 6 additions & 0 deletions src/extension/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@ export interface IEventNamePropertyMapping {
* @type {boolean}
*/
scrapy: boolean;
/**
* Whether degbugging with autoStartBrowser.
*
* @type {boolean}
*/
autoStartBrowser: boolean;
};
/**
* Telemetry event sent when attaching to child process
Expand Down
31 changes: 31 additions & 0 deletions src/test/unittest/configuration/resolvers/launch.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,37 @@ getInfoPerOS().forEach(([osName, osType, path]) => {
expect((debugConfig as DebugConfiguration).debugOptions).contains(DebugOptions.Jinja);
});

const testsForautoStartBrowser = [
{
autoStartBrowser: true,
module: 'flask',
},
{
autoStartBrowser: true,
django: true,
},
];

test('Add serverReadyAction for Django and Flask', async () => {
const pythonPath = `PythonPath_${new Date().toString()}`;
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
const expectedServerReadyAction = {
pattern: '.*(https?:\\/\\/\\S+:[0-9]+\\/?).*',
uriFormat: '%s',
action: 'openExternally',
};
testsForautoStartBrowser.forEach(async (testParams) => {
const debugConfig = await resolveDebugConfiguration(workspaceFolder, {
...launch,
...testParams,
});
expect(debugConfig).to.have.property('serverReadyAction', expectedServerReadyAction);
});
});

async function testSetting(
requestType: 'launch' | 'attach',
settings: Record<string, boolean>,
Expand Down

0 comments on commit 37cae2b

Please sign in to comment.