summaryrefslogtreecommitdiff
path: root/editors/vscode/src/debug.ts
blob: 3b9a5fbcfb839775d8be2b93fc51e7d92b6c4d50 (plain)
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
import * as vscode from 'vscode';

import * as os from "os";
import { Config } from './config';

type DebugConfigProvider = (executable: string) => vscode.DebugConfiguration;

export function getDebugConfiguration(config: Config, program: string): any {

	const knownEngines: Record<string, DebugConfigProvider> = {
        "vadimcn.vscode-lldb": getLldbDebugConfig,
        "ms-vscode.cpptools": getCppvsDebugConfig
    };

	var debugEngine = null;

    if(config.debugEngine !== "") {
        debugEngine = vscode.extensions.getExtension(config.debugEngine);
    } 

    if(debugEngine === null || debugEngine === undefined) {
        for (var engineId in knownEngines) {
            debugEngine = vscode.extensions.getExtension(engineId);
            if (debugEngine) {
                break;
            } 
        }
    }

	if (!debugEngine) {
        vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)`
		+ ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`);
        return;
    }

	return knownEngines[debugEngine.id](program);
}

function getLldbDebugConfig(executable: string): vscode.DebugConfiguration {
    return {
        type: "lldb",
        request: "launch",
        name: "test debug",
        program: executable,
        cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath
    };
}

function getCppvsDebugConfig(executable: string): vscode.DebugConfiguration {
    return {
        type: (os.platform() === "win32") ? "cppvsdbg" : "cppdbg",
        request: "launch",
        name: "test debug",
        program: executable,
        cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath
    };
}