Skip to content

Commit

Permalink
Add task detection back
Browse files Browse the repository at this point in the history
  • Loading branch information
SolarLiner committed May 8, 2019
1 parent 2dd4e57 commit daac69a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@
"properties": {
"task": {
"type": "string",
"description": "The Meson task to customize"
},
"file": {
"type": "string",
"description": "The Meson file that provides the task. Can be omitted."
"description": "The Meson target to execute"
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
runMesonTest,
runMesonReconfigure
} from "./meson/runners";
import { getMesonTasks } from "./tasks";

let targetExplorer: MesonTargetsExplorer | undefined;
let testExplorer: MesonTestsExplorer | undefined;
let taskProvider;

export function activate(ctx: vscode.ExtensionContext): void {
const root = vscode.workspace.rootPath;
Expand All @@ -20,7 +22,14 @@ export function activate(ctx: vscode.ExtensionContext): void {

targetExplorer = new MesonTargetsExplorer(ctx, buildDir);
testExplorer = new MesonTestsExplorer(ctx, buildDir);

taskProvider = vscode.tasks.registerTaskProvider("meson", {
provideTasks(token) {
return getMesonTasks(buildDir);
},
resolveTask() {
return undefined;
}
});
vscode.commands.registerCommand("mesonbuild.configure", async () => {
await runMesonConfigure(root, "build");
targetExplorer.refresh();
Expand Down
53 changes: 49 additions & 4 deletions src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,60 @@

import * as path from "path";
import * as vscode from "vscode";
import { getMesonTargets } from "./meson/introspection";
import { exists, exec, getOutputChannel } from "./utils";

interface MesonTaskDefinition extends vscode.TaskDefinition {
type: "meson";
task: string;
file?: string;
}

export async function getMesonTasks(dir: string): Promise<vscode.Task[]> {
let emptyTasks: vscode.Task[] = [];
export async function getMesonTasks(buildDir: string): Promise<vscode.Task[]> {
try {
const targets = await getMesonTargets(buildDir);
const tasks = [
new vscode.Task(
{ type: "meson", task: "build all" },
"build all",
"meson",
new vscode.ShellExecution("ninja", { cwd: buildDir })
),
new vscode.Task(
{ type: "meson", task: "reconfigure" },
"reconfigure",
"meson",
new vscode.ShellExecution("ninja reconfigure", { cwd: buildDir })
),
new vscode.Task(
{ type: "meson", task: "clean" },
"clean",
"meson",
new vscode.ShellExecution("ninja clean", { cwd: buildDir })
)
];
tasks.push(
...targets.map(t => {
const def: MesonTaskDefinition = { type: "meson", task: t.name };
const task = new vscode.Task(
def,
t.name,
"meson",
new vscode.ShellExecution(`ninja ${t.name}`, { cwd: buildDir })
);
task.group = vscode.TaskGroup.Build;
return task;
})
);
return tasks;
} catch (e) {
if (e.stderr) getOutputChannel().appendLine(e.stderr);
vscode.window.showErrorMessage(
"Could not fetch targets. See Meson Build output tab for more info."
);

return [];
}
/* let emptyTasks: vscode.Task[] = [];
if (!dir) {
return emptyTasks;
}
Expand Down Expand Up @@ -54,7 +99,7 @@ export async function getMesonTasks(dir: string): Promise<vscode.Task[]> {
channel.appendLine("Auto detecting meson task failed.");
channel.show(true);
return emptyTasks;
}
} */
}

/*
Expand Down

0 comments on commit daac69a

Please sign in to comment.