diff --git a/src/debug/cppdbg.ts b/src/debug/cppdbg.ts deleted file mode 100644 index c030dfb..0000000 --- a/src/debug/cppdbg.ts +++ /dev/null @@ -1,50 +0,0 @@ -import * as vscode from "vscode"; -import { Target } from "../types"; -import { MesonDebugConfigurationProvider } from "."; - -export class DebugConfigurationProviderCppdbg extends MesonDebugConfigurationProvider { - override type: string = "cppdbg"; - - constructor(path: string) { - super(path); - } - - override async createDebugConfiguration(target: Target): Promise { - let debugConfiguration = null; - if (target.target_sources?.some((source) => source.compiler != null && ["cl"].includes(source.compiler[0]))) { - debugConfiguration = await this.createMSVCDebugConfiguration(target); - } else if ( - target.target_sources?.some((source) => source.compiler != null && ["cc", "clang"].includes(source.compiler[0])) - ) { - debugConfiguration = await this.createLLDBDebugConfiguration(target); - } else { - debugConfiguration = await this.createGDBDebugConfiguration(target); - } - return debugConfiguration; - } - - async createGDBDebugConfiguration(target: Target): Promise { - const debugConfig = await super.createDebugConfiguration(target); - debugConfig["MIMode"] = "gdb"; - debugConfig["setupCommands"] = [ - { - description: "Enable pretty-printing for gdb", - text: "-enable-pretty-printing", - ignoreFailures: true, - }, - ]; - return debugConfig; - } - - async createLLDBDebugConfiguration(target: Target): Promise { - const debugConfig = await super.createDebugConfiguration(target); - debugConfig["MIMode"] = "lldb"; - return debugConfig; - } - - async createMSVCDebugConfiguration(target: Target): Promise { - const debugConfig = await super.createDebugConfiguration(target); - debugConfig.type = "cppvsdbg"; - return debugConfig; - } -} diff --git a/src/debug/index.ts b/src/debug/index.ts index 1924421..10a16ac 100644 --- a/src/debug/index.ts +++ b/src/debug/index.ts @@ -4,27 +4,28 @@ import { getMesonTargets } from "../introspection"; import { Target } from "../types"; import { extensionConfiguration, getTargetName } from "../utils"; -export abstract class MesonDebugConfigurationProvider implements vscode.DebugConfigurationProvider { - private readonly path: string; +export enum DebuggerType { + cppvsdbg = "cppvsdbg", + cppdbg = "cppdbg", + lldb = "lldb", +} - abstract type: string; +enum MIMode { + gdb = "gdb", + lldb = "lldb", +} - constructor(path: string) { +export class MesonDebugConfigurationProvider implements vscode.DebugConfigurationProvider { + readonly type: DebuggerType; + private readonly path: string; + + constructor(type: DebuggerType, path: string) { + this.type = type; this.path = path; } async createDebugConfiguration(target: Target): Promise { - const targetName = await getTargetName(target); - const name = this.type; - return { - type: name, - name: `Debug ${target.name} (${name})`, - request: "launch", - cwd: path.dirname(this.path), - program: target.filename[0], - args: [], - preLaunchTask: `Meson: Build ${targetName}`, - }; + return await this.createDebugConfigurationForType(target, this.type); } async provideDebugConfigurations( @@ -61,4 +62,41 @@ export abstract class MesonDebugConfigurationProvider implements vscode.DebugCon ): vscode.ProviderResult { return debugConfiguration; } + + async createDebugConfigurationForType(target: Target, type: DebuggerType): Promise { + const targetName = await getTargetName(target); + const name = type.toString(); + let debugConfig: vscode.DebugConfiguration = { + type: name, + name: `Debug ${target.name} (${name})`, + request: "launch", + cwd: path.dirname(this.path), + program: target.filename[0], + args: [], + preLaunchTask: `Meson: Build ${targetName}`, + }; + + if (type === DebuggerType.cppdbg) { + let miMode; + if ( + target.target_sources?.some((source) => source.compiler != null && ["cc", "clang"].includes(source.compiler[0])) + ) { + miMode = MIMode.lldb; + } else { + miMode = MIMode.gdb; + } + debugConfig["MIMode"] = miMode.toString(); + + if (miMode === MIMode.gdb) { + debugConfig["setupCommands"] = [ + { + description: "Enable pretty-printing for gdb", + text: "-enable-pretty-printing", + ignoreFailures: true, + }, + ]; + } + } + return debugConfig; + } } diff --git a/src/debug/lldb.ts b/src/debug/lldb.ts deleted file mode 100644 index 7f85ad4..0000000 --- a/src/debug/lldb.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { MesonDebugConfigurationProvider } from "."; - -export class DebugConfigurationProviderLldb extends MesonDebugConfigurationProvider { - override type: string = "lldb"; - - constructor(path: string) { - super(path); - } -} diff --git a/src/extension.ts b/src/extension.ts index 9792d46..6cde57d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,3 +1,4 @@ +import * as os from "os"; import * as vscode from "vscode"; import { getMesonTasks, getTasks, runTask, runFirstTask } from "./tasks"; import { MesonProjectExplorer } from "./treeview"; @@ -13,8 +14,7 @@ import { mesonRootDirs, shouldModifySetting, } from "./utils"; -import { DebugConfigurationProviderCppdbg } from "./debug/cppdbg"; -import { DebugConfigurationProviderLldb } from "./debug/lldb"; +import { MesonDebugConfigurationProvider, DebuggerType } from "./debug/index"; import { CpptoolsProvider, registerCppToolsProvider } from "./cpptoolsconfigprovider"; import { testDebugHandler, testRunHandler, rebuildTests } from "./tests"; import { activateLinters } from "./linters"; @@ -77,11 +77,20 @@ export async function activate(ctx: vscode.ExtensionContext) { explorer = new MesonProjectExplorer(ctx, sourceDir, buildDir); - const providers = [DebugConfigurationProviderCppdbg, DebugConfigurationProviderLldb]; - providers.forEach((provider) => { - const p = new provider(buildDir); + let providers = []; + if (os.platform() === "win32") { + providers.push(new MesonDebugConfigurationProvider(DebuggerType.cppvsdbg, buildDir)); + } else { + providers.push(new MesonDebugConfigurationProvider(DebuggerType.cppdbg, buildDir)); + } + providers.push(new MesonDebugConfigurationProvider(DebuggerType.lldb, buildDir)); + providers.forEach((p) => { ctx.subscriptions.push( - vscode.debug.registerDebugConfigurationProvider(p.type, p, vscode.DebugConfigurationProviderTriggerKind.Dynamic), + vscode.debug.registerDebugConfigurationProvider( + p.type.toString(), + p, + vscode.DebugConfigurationProviderTriggerKind.Dynamic, + ), ); });