-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathdynamicdebugConfigurationService.ts
More file actions
89 lines (79 loc) · 3.21 KB
/
Copy pathdynamicdebugConfigurationService.ts
File metadata and controls
89 lines (79 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* eslint-disable @typescript-eslint/naming-convention */
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as path from 'path';
import { CancellationToken, DebugConfiguration, WorkspaceFolder } from 'vscode';
import { IDynamicDebugConfigurationService } from '../types';
import { DebuggerTypeName } from '../../constants';
import { getDjangoPaths, getFastApiPaths, getFlaskPaths, tryResolveFastApiArgs } from './utils/configuration';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
const workspaceFolderToken = '${workspaceFolder}';
export class DynamicPythonDebugConfigurationService implements IDynamicDebugConfigurationService {
// eslint-disable-next-line class-methods-use-this
public async provideDebugConfigurations(
folder: WorkspaceFolder,
_token?: CancellationToken,
): Promise<DebugConfiguration[] | undefined> {
const providers = [];
providers.push({
name: 'Python Debugger: Python File',
type: DebuggerTypeName,
request: 'launch',
program: '${file}',
});
const djangoManagePaths = await getDjangoPaths(folder);
const djangoManagePath = djangoManagePaths?.length
? path.relative(folder.uri.fsPath, djangoManagePaths[0].fsPath)
: null;
if (djangoManagePath) {
providers.push({
name: 'Python Debugger: Django',
type: DebuggerTypeName,
request: 'launch',
program: `${workspaceFolderToken}${path.sep}${djangoManagePath}`,
args: ['runserver'],
django: true,
});
}
const flaskPaths = await getFlaskPaths(folder);
const flaskPath = flaskPaths?.length ? flaskPaths[0].fsPath : null;
if (flaskPath) {
providers.push({
name: 'Python Debugger: Flask',
type: DebuggerTypeName,
request: 'launch',
module: 'flask',
env: {
FLASK_APP: path.relative(folder.uri.fsPath, flaskPath),
FLASK_DEBUG: '1',
},
args: ['run', '--no-debugger', '--no-reload'],
jinja: true,
});
}
const fastApiPaths = await getFastApiPaths(folder);
if (fastApiPaths?.length) {
const fastApiArgs = tryResolveFastApiArgs(folder, fastApiPaths) ?? ['run'];
providers.push({
name: 'Python Debugger: FastAPI',
type: DebuggerTypeName,
request: 'launch',
module: 'fastapi',
args: fastApiArgs,
jinja: true,
});
providers.push({
name: 'Python Debugger: FastAPI File',
type: DebuggerTypeName,
request: 'launch',
module: 'fastapi',
args: ['run', '${file}'],
jinja: true,
});
}
sendTelemetryEvent(EventName.DEBUGGER_DYNAMIC_CONFIGURATION, undefined, { providers: providers });
return providers;
}
}