Skip to content

Commit 45dc225

Browse files
authored
Merge pull request #61 from Ongy/add-debug-configuration-provider
Add debug configuration provider
2 parents b0ec447 + 27d35fc commit 45dc225

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"homepage": "https://github.com/mesonbuild/vscode-meson/blob/master/README.md",
3535
"engines": {
36-
"vscode": "^1.26.0"
36+
"vscode": "^1.59.0"
3737
},
3838
"categories": [
3939
"Programming Languages"
@@ -44,7 +44,9 @@
4444
"onCommand:mesonbuild.build",
4545
"onCommand:mesonbuild.test",
4646
"onCommand:mesonbuild.benchmark",
47-
"workspaceContains:meson.build"
47+
"workspaceContains:meson.build",
48+
"onDebugDynamicConfigurations",
49+
"onDebugDynamicConfigurations:cppdbg"
4850
],
4951
"main": "./out/src/extension",
5052
"contributes": {
@@ -209,7 +211,7 @@
209211
"devDependencies": {
210212
"@types/node": "^16.11.7",
211213
"typescript": "^4.4.4",
212-
"vscode": "^1.1.37"
214+
"@types/vscode": "^1.1.59"
213215
},
214216
"dependencies": {
215217
"array-flat-polyfill": "^1.0.1"

src/configprovider.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as vscode from "vscode";
2+
3+
import {
4+
getMesonTargets
5+
} from "./meson/introspection"
6+
import {
7+
getTargetName
8+
} from "./utils"
9+
10+
export class DebugConfigurationProvider implements vscode.DebugConfigurationProvider {
11+
private path: string;
12+
13+
constructor(path: string) {
14+
this.path = path
15+
}
16+
17+
async provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> {
18+
let targets = await getMesonTargets(this.path);
19+
20+
const executables = targets.filter(target => target.type == "executable");
21+
let ret: vscode.DebugConfiguration[] = [];
22+
23+
for (const target of executables) {
24+
if (!target.target_sources.some(source => ['cpp', 'c'].includes(source.language))) {
25+
continue;
26+
}
27+
28+
const targetName = await getTargetName(target)
29+
ret.push({
30+
type: 'cppdbg',
31+
name: target.name,
32+
request: "launch",
33+
cwd: this.path,
34+
program: target.filename[0],
35+
preLaunchTask: `Meson: Build ${targetName}`
36+
})
37+
}
38+
39+
return ret;
40+
}
41+
42+
resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, debugConfiguration: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
43+
return debugConfiguration
44+
}
45+
46+
resolveDebugConfigurationWithSubstitutedVariables(folder: vscode.WorkspaceFolder, debugConfiguration: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
47+
return debugConfiguration
48+
}
49+
50+
}

src/extension.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
getMesonTests,
2121
getMesonBenchmarks
2222
} from "./meson/introspection";
23+
import {DebugConfigurationProvider} from "./configprovider";
24+
2325

2426
export let extensionPath: string;
2527
let explorer: MesonProjectExplorer;
@@ -37,6 +39,12 @@ export async function activate(ctx: vscode.ExtensionContext) {
3739
explorer = new MesonProjectExplorer(ctx, root, buildDir);
3840
watcher = vscode.workspace.createFileSystemWatcher(`${workspaceRelative(extensionConfiguration("buildFolder"))}/build.ninja`, false, false, true);
3941

42+
ctx.subscriptions.push(
43+
vscode.debug.registerDebugConfigurationProvider('cppdbg',
44+
new DebugConfigurationProvider(workspaceRelative(extensionConfiguration("buildFolder"))),
45+
vscode.DebugConfigurationProviderTriggerKind.Dynamic)
46+
);
47+
4048
ctx.subscriptions.push(watcher);
4149

4250
ctx.subscriptions.push(

src/treeview/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MesonProjectDataProvider implements vscode.TreeDataProvider<BaseNode> {
1818
}
1919

2020
refresh() {
21-
this._onDataChangeEmitter.fire();
21+
this._onDataChangeEmitter.fire(null);
2222
}
2323

2424
getTreeItem(element: BaseNode) {

0 commit comments

Comments
 (0)