Skip to content

Commit

Permalink
Added configure/build/clean context menus where appropriate to meson …
Browse files Browse the repository at this point in the history
…project view.

Moved reconfigure button to project node from sidebar header
(when multiple roots / build dirs are supported, header position wouldn't make sense).

Build icons from vscode-cmake-tools.
  • Loading branch information
lukester1975 committed Nov 16, 2023
1 parent 459c3e0 commit d9c81f3
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 14 deletions.
80 changes: 72 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@
},
{
"command": "mesonbuild.build",
"title": "Meson: Build"
"title": "Meson: Build",
"icon": {
"dark": "res/build-icon-dark.svg",
"light": "res/build-icon-light.svg"
}
},
{
"command": "mesonbuild.test",
Expand All @@ -88,6 +92,26 @@
"command": "mesonbuild.restartLanguageServer",
"title": "Meson: Restart Language Server"
},
{
"command": "mesonbuild.node.reconfigure",
"title": "Reconfigure",
"icon": {
"dark": "res/meson_32.svg",
"light": "res/meson_32.svg"
}
},
{
"command": "mesonbuild.node.build",
"title": "Build",
"icon": {
"dark": "res/build-icon-dark.svg",
"light": "res/build-icon-light.svg"
}
},
{
"command": "mesonbuild.node.clean",
"title": "Clean"
},
{
"command": "mesonbuild.node.runAll",
"title": "Run all",
Expand Down Expand Up @@ -398,11 +422,46 @@
},
"menus": {
"view/item/context": [
{
"command": "mesonbuild.node.reconfigure",
"when": "view == meson-project && viewItem == meson-projectroot",
"group": "inline"
},
{
"command": "mesonbuild.node.reconfigure",
"when": "view == meson-project && viewItem == meson-projectroot",
"group": "build@0"
},
{
"command": "mesonbuild.node.build",
"when": "view == meson-project && viewItem == meson-projectroot",
"group": "inline"
},
{
"command": "mesonbuild.node.build",
"when": "view == meson-project && viewItem == meson-projectroot",
"group": "build@1"
},
{
"command": "mesonbuild.node.clean",
"when": "view == meson-project && viewItem == meson-projectroot",
"group": "build@2"
},
{
"command": "mesonbuild.openBuildFile",
"when": "view == meson-project && viewItem == meson-target",
"group": "inline"
},
{
"command": "mesonbuild.openBuildFile",
"when": "view == meson-project && viewItem == meson-target",
"group": "build"
},
{
"command": "mesonbuild.node.build",
"when": "view == meson-project && viewItem == meson-target",
"group": "build"
},
{
"command": "mesonbuild.node.runAll",
"when": "view == meson-project && viewItem == meson-test-root",
Expand All @@ -424,18 +483,23 @@
"group": "run"
}
],
"view/title": [
{
"command": "mesonbuild.reconfigure",
"when": "view == meson-project",
"group": "navigation"
}
],
"commandPalette": [
{
"command": "mesonbuild.openBuildFile",
"when": "false"
},
{
"command": "mesonbuild.node.reconfigure",
"when": "false"
},
{
"command": "mesonbuild.node.build",
"when": "false"
},
{
"command": "mesonbuild.node.clean",
"when": "false"
},
{
"command": "mesonbuild.node.run",
"when": "false"
Expand Down
8 changes: 8 additions & 0 deletions res/build-icon-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions res/build-icon-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { activateFormatters } from "./formatters";
import { SettingsKey, TaskQuickPickItem } from "./types";
import { createLanguageServerClient } from "./lsp/common";
import { dirname, relative } from "path";
import { IRunnableNode } from "./treeview/nodes/base";
import { IBuildableNode, IRunnableNode } from "./treeview/nodes/base";

export let extensionPath: string;
export let workspaceState: vscode.Memento;
Expand Down Expand Up @@ -202,6 +202,22 @@ export async function activate(ctx: vscode.ExtensionContext) {
}),
);

ctx.subscriptions.push(
vscode.commands.registerCommand("mesonbuild.node.reconfigure", async () => {
runFirstTask("reconfigure");
}),
);

ctx.subscriptions.push(
vscode.commands.registerCommand("mesonbuild.node.build", async (node: IBuildableNode) => node.build()),
);

ctx.subscriptions.push(
vscode.commands.registerCommand("mesonbuild.node.clean", async () => {
runFirstTask("clean");
}),
);

// Two commands just to have different icons.
ctx.subscriptions.push(
vscode.commands.registerCommand("mesonbuild.node.runAll", async (node: IRunnableNode) => node.run()),
Expand Down
2 changes: 1 addition & 1 deletion src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function createReconfigureTask(buildDir: string, sourceDir: string) {
export async function getMesonTasks(buildDir: string, sourceDir: string) {
try {
const defaultBuildTask = new vscode.Task(
{ type: "meson", mode: "build" },
{ type: "meson", mode: "build", target: pseudoAllTarget },
"Build all targets",
"Meson",
new vscode.ShellExecution(extensionConfiguration("mesonPath"), ["compile", "-C", buildDir]),
Expand Down
5 changes: 5 additions & 0 deletions src/treeview/nodes/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export abstract class BaseDirectoryNode<T> extends BaseNode {
abstract buildFileTree(fpaths: T[]): FolderMap<T> | Thenable<FolderMap<T>>;
}

// A node in the meson tree view that can be built.
export interface IBuildableNode {
build(): Thenable<any>;
}

// A node in the meson tree view that can be run.
export interface IRunnableNode {
run(): Thenable<any>;
Expand Down
8 changes: 6 additions & 2 deletions src/treeview/nodes/targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BaseNode } from "../basenode";
import { Target, Targets } from "../../types";
import { TargetSourcesRootNode, TargetGeneratedSourcesRootNode } from "./sources";
import { extensionRelative, getTargetName } from "../../utils";
import { BaseDirectoryNode } from "./base";
import { BaseDirectoryNode, IBuildableNode } from "./base";

export class TargetDirectoryNode extends BaseDirectoryNode<Target> {
constructor(parentId: string, folder: string, targets: Targets) {
Expand Down Expand Up @@ -72,7 +72,7 @@ export class TargetDirectoryNode extends BaseDirectoryNode<Target> {
}
}

export class TargetNode extends BaseNode {
export class TargetNode extends BaseNode implements IBuildableNode {
constructor(
parentId: string,
private readonly target: Target,
Expand Down Expand Up @@ -123,6 +123,10 @@ export class TargetNode extends BaseNode {
return item;
}

async build() {
return vscode.commands.executeCommand("mesonbuild.build", await getTargetName(this.target));
}

private getIconPath() {
switch (this.target.type) {
case "executable":
Expand Down
12 changes: 10 additions & 2 deletions src/treeview/nodes/toplevel.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as vscode from "vscode";

import { BaseNode } from "../basenode";
import { ProjectInfo, Subproject, Targets, Tests } from "../../types";
import { ProjectInfo, Subproject, Targets, Tests, pseudoAllTarget } from "../../types";
import { extensionRelative } from "../../utils";
import { TargetDirectoryNode } from "./targets";
import { getMesonBenchmarks, getMesonTargets, getMesonTests } from "../../introspection";
import { TestRootNode } from "./tests";
import { IBuildableNode } from "./base";

export class ProjectNode extends BaseNode {
export class ProjectNode extends BaseNode implements IBuildableNode {
constructor(
private readonly project: ProjectInfo,
projectDir: string,
Expand All @@ -26,6 +27,9 @@ export class ProjectNode extends BaseNode {
item.iconPath = extensionRelative("res/meson_32.svg");
item.collapsibleState = vscode.TreeItemCollapsibleState.Expanded;

// To key in to "when": "view == meson-project && viewItem == test" in package.json.
item.contextValue = "meson-projectroot";

return item;
}

Expand Down Expand Up @@ -60,6 +64,10 @@ export class ProjectNode extends BaseNode {

return children;
}

async build() {
return vscode.commands.executeCommand("mesonbuild.build", pseudoAllTarget);
}
}

class SubprojectsRootNode extends BaseNode {
Expand Down

0 comments on commit d9c81f3

Please sign in to comment.