-
Notifications
You must be signed in to change notification settings - Fork 109
Use fastapi run for FastAPI debug configs, with file and project variants
#1048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
dcd8b80
06fc5bb
f855c11
94c97b0
dbe5c81
78d8e1c
8679707
e8179ca
46a83ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,6 @@ | |
|
|
||
| 'use strict'; | ||
|
|
||
| import * as path from 'path'; | ||
| import * as fs from 'fs-extra'; | ||
| import { WorkspaceFolder } from 'vscode'; | ||
| import { MultiStepInput } from '../../../common/multiStepInput'; | ||
| import { DebugConfigStrings } from '../../../common/utils/localize'; | ||
| import { sendTelemetryEvent } from '../../../telemetry'; | ||
|
|
@@ -15,54 +12,37 @@ import { LaunchRequestArguments } from '../../../types'; | |
| import { DebugConfigurationState, DebugConfigurationType } from '../../types'; | ||
|
|
||
| export async function buildFastAPILaunchDebugConfiguration( | ||
| input: MultiStepInput<DebugConfigurationState>, | ||
| _input: MultiStepInput<DebugConfigurationState>, | ||
| state: DebugConfigurationState, | ||
| ): Promise<void> { | ||
| const application = await getApplicationPath(state.folder); | ||
| let manuallyEnteredAValue: boolean | undefined; | ||
| const config: Partial<LaunchRequestArguments> = { | ||
|
savannahostrowski marked this conversation as resolved.
|
||
| name: DebugConfigStrings.fastapi.snippet.name, | ||
| type: DebuggerTypeName, | ||
| request: 'launch', | ||
| module: 'uvicorn', | ||
| args: ['main:app', '--reload'], | ||
| module: 'fastapi', | ||
| args: ['run'], | ||
| jinja: true, | ||
| }; | ||
|
|
||
| if (!application) { | ||
|
savannahostrowski marked this conversation as resolved.
|
||
| const selectedPath = await input.showInputBox({ | ||
| title: DebugConfigStrings.fastapi.enterAppPathOrNamePath.title, | ||
| value: 'main.py', | ||
| prompt: DebugConfigStrings.fastapi.enterAppPathOrNamePath.prompt, | ||
| validate: (value) => | ||
| Promise.resolve( | ||
| value && value.trim().length > 0 | ||
| ? undefined | ||
| : DebugConfigStrings.fastapi.enterAppPathOrNamePath.invalid, | ||
| ), | ||
| }); | ||
| if (selectedPath) { | ||
| manuallyEnteredAValue = true; | ||
| config.args = [`${path.basename(selectedPath, '.py').replace('/', '.')}:app`, '--reload']; | ||
| } else { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, { | ||
| configurationType: DebugConfigurationType.launchFastAPI, | ||
| autoDetectedFastAPIMainPyPath: !!application, | ||
| manuallyEnteredAValue, | ||
| }); | ||
| Object.assign(state.config, config); | ||
| } | ||
| export async function getApplicationPath(folder: WorkspaceFolder | undefined): Promise<string | undefined> { | ||
| if (!folder) { | ||
| return undefined; | ||
| } | ||
| const defaultLocationOfManagePy = path.join(folder.uri.fsPath, 'main.py'); | ||
| if (await fs.pathExists(defaultLocationOfManagePy)) { | ||
| return 'main.py'; | ||
| } | ||
| return undefined; | ||
|
|
||
| export async function buildFastAPIWithFileLaunchDebugConfiguration( | ||
| _input: MultiStepInput<DebugConfigurationState>, | ||
| state: DebugConfigurationState, | ||
| ): Promise<void> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot generated: [verified]
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this but extracting |
||
| const config: Partial<LaunchRequestArguments> = { | ||
| name: DebugConfigStrings.fastapi.snippetFile.name, | ||
| type: DebuggerTypeName, | ||
| request: 'launch', | ||
| module: 'fastapi', | ||
| args: ['run', '${file}'], | ||
| jinja: true, | ||
| }; | ||
| sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, { | ||
| configurationType: DebugConfigurationType.launchFastAPIWithFile, | ||
| }); | ||
| Object.assign(state.config, config); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.