(documentUri: Uri, fileType: string)
| 32 | } |
| 33 | |
| 34 | export function getTemplatedLaunchConfigs(documentUri: Uri, fileType: string): TemplatedLaunchConfig[] { |
| 35 | const runConfigs: TemplatedLaunchConfig[] = workspace.getConfiguration("launch", documentUri).get<any[]>("configurations") || []; |
| 36 | const wantedTemplateTypes = [`run-${fileType}`, `debug-${fileType}`]; |
| 37 | const filePath = fsPath(documentUri); |
| 38 | const workspaceUri = workspace.getWorkspaceFolder(documentUri)?.uri; |
| 39 | const workspacePath = workspaceUri ? fsPath(workspaceUri) : undefined; |
| 40 | |
| 41 | // Loop through each launch config and add the relevant templates. Configs may be |
| 42 | // added multiple times if they have multiple template types. |
| 43 | const runFileTemplates: TemplatedLaunchConfig[] = []; |
| 44 | for (const templateType of wantedTemplateTypes) { |
| 45 | const relevantLaunchConfigs = runConfigs |
| 46 | .filter((c) => c.type === "dart" && isTemplateOfType(c, templateType)) |
| 47 | .filter((c) => codeLensIsValidForFile(c.codeLens, workspacePath, filePath)); |
| 48 | for (const launchConfig of relevantLaunchConfigs) { |
| 49 | runFileTemplates.push({ |
| 50 | ...launchConfig, |
| 51 | name: (launchConfig.codeLens?.title || launchConfig.name || "${debugType}").replace(debugTypeTokenRegex, templateType.startsWith("run-") ? "Run" : "Debug"), |
| 52 | noDebug: templateType.startsWith("run-"), |
| 53 | }); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // If we didn't find any, try the defaults. |
| 58 | if (!runFileTemplates.length) { |
| 59 | const defaultRunTemplate = getLaunchConfigDefaultTemplate(documentUri, false); |
| 60 | const defaultDebugTemplate = getLaunchConfigDefaultTemplate(documentUri, true); |
| 61 | if (defaultRunTemplate) |
| 62 | runFileTemplates.push({ ...defaultRunTemplate, name: "Run" }); |
| 63 | if (defaultDebugTemplate) |
| 64 | runFileTemplates.push({ ...defaultDebugTemplate, name: "Debug" }); |
| 65 | } |
| 66 | |
| 67 | return runFileTemplates; |
| 68 | } |
| 69 | |
| 70 | function codeLensIsValidForFile(codeLens: TemplatedLaunchConfig["codeLens"], workspacePath: string | undefined, filePath: string) { |
| 71 | if (!codeLens?.path) |
no test coverage detected