Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Add hideTasks setting for VS Code. #57

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/vscode-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## 0.7.0

- Requires VS Code ^1.75.0.
- Added action graph support (requires moon >= 1.15).
- Added support for the `automation` project type.
- Added a `moon.hideTasks` setting, to hide tasks in the projects view.

## 0.6.0

Expand Down
3 changes: 3 additions & 0 deletions packages/vscode-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ The following settings are available for this extension.
"`.`". This is useful if moon is initialized in a sub-folder.
- `moon.binPath` - Relative path from moon's workspace root to the moon binary. Defaults to
`node_modules/@moonrepo/cli/moon`. _Windows will auto-suffix with `.exe`!_
- `moon.hideTasks` - List of tasks to hide in the projects view, using target syntax. Supports
fully-qualified targets (`app:build`) and partial targets (`:build` or `*:build`). Defaults to
`[]`.

## Commands

Expand Down
30 changes: 15 additions & 15 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"tasks"
],
"engines": {
"vscode": "^1.66.0"
"vscode": "^1.75.0"
},
"categories": [
"Testing",
Expand All @@ -38,11 +38,6 @@
"directory": "packages/vscode-extension"
},
"activationEvents": [
"onCommand:moon.openSettings",
"onCommand:moon.runTargetByInput",
"onView:moonProjects",
"onView:moonProjectsExternal",
"onView:moonLastRun",
"workspaceContains:moon.yml"
],
"main": "./lib/extension.js",
Expand All @@ -57,6 +52,11 @@
"default": "node_modules/@moonrepo/cli/moon",
"markdownDescription": "Path to the moon binary, relative from the `moon.workspaceRoot` setting."
},
"moon.hideTasks": {
"type": "array",
"default": [],
"markdownDescription": "List of tasks to hide in the projects panel. Accepts fully-qualified or partial targets."
},
"moon.workspaceRoot": {
"type": "string",
"default": ".",
Expand All @@ -76,17 +76,17 @@
},
{
"command": "moon.checkProject",
"title": "moon: Run all buildable and testable targets",
"title": "moon: Run all buildable and testable tasks",
"icon": "$(run-all)"
},
{
"command": "moon.runTarget",
"title": "moon: Run the target",
"command": "moon.runTask",
"title": "moon: Run the task",
"icon": "$(run)"
},
{
"command": "moon.runTargetByInput",
"title": "moon: Run one or many targets"
"command": "moon.runTaskByInput",
"title": "moon: Run one or many tasks"
},
{
"command": "moon.viewProject",
Expand Down Expand Up @@ -115,11 +115,11 @@
"when": "false"
},
{
"command": "moon.runTarget",
"command": "moon.runTask",
"when": "false"
},
{
"command": "moon.runTargetByInput",
"command": "moon.runTaskByInput",
"when": "moon.hasBinary"
},
{
Expand Down Expand Up @@ -169,7 +169,7 @@
],
"view/item/context": [
{
"command": "moon.runTarget",
"command": "moon.runTask",
"when": "view == moonProjects && viewItem == projectTask",
"group": "inline"
},
Expand All @@ -184,7 +184,7 @@
"group": "inline@1"
},
{
"command": "moon.runTarget",
"command": "moon.runTask",
"when": "view == moonProjectsExternal && viewItem == projectTask",
"group": "inline"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/vscode-extension/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function checkProject(
await vscode.tasks.executeTask(task);
}

export async function runTarget(
export async function runTask(
target: string,
workspaceRoot: string,
modifier?: (task: Task) => void,
Expand All @@ -57,14 +57,14 @@ export async function runTarget(
await vscode.tasks.executeTask(task);
}

export async function runTargetByInput(workspaceRoot: string) {
export async function runTaskByInput(workspaceRoot: string) {
const target = await vscode.window.showInputBox({
prompt: 'In the format of "scope:task" or ":task".',
title: 'Target(s)',
});

if (target) {
await runTarget(target, workspaceRoot);
await runTask(target, workspaceRoot);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import vscode from 'vscode';
import { runTargetByInput, viewActionGraph, viewProjectGraph } from './commands';
import { runTaskByInput, viewActionGraph, viewProjectGraph } from './commands';
import { LastRunProvider } from './lastRunView';
import { findMoonBin, findWorkspaceRoot, isRealBin } from './moon';
import { ProjectsProvider } from './projectsView';
Expand Down Expand Up @@ -31,7 +31,7 @@ export async function activate(context: vscode.ExtensionContext) {

context.subscriptions.push(
// Create a "moon run <target>" task
vscode.commands.registerCommand('moon.runTargetByInput', () => runTargetByInput(workspaceRoot)),
vscode.commands.registerCommand('moon.runTaskByInput', () => runTaskByInput(workspaceRoot)),

// Create a tree view for all moon projects
vscode.window.createTreeView('moonProjects', {
Expand Down
50 changes: 43 additions & 7 deletions packages/vscode-extension/src/projectsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import vscode, {
Uri,
} from 'vscode';
import type { LanguageType, Project, ProjectType, Task as ProjectTask } from '@moonrepo/types';
import { checkProject, runTarget } from './commands';
import { checkProject, runTask } from './commands';
import { execMoon, getMoonVersion } from './moon';

const LANGUAGE_MANIFESTS: Record<LanguageType, string> = {
Expand Down Expand Up @@ -46,6 +46,33 @@ function createLangIcon(context: vscode.ExtensionContext, name: LanguageType) {
};
}

function canShowTask(target: string, hideTasks: Set<string>): boolean {
if (hideTasks.size === 0) {
return true;
}

if (hideTasks.has(':') || hideTasks.has('*:*')) {
return false;
}

for (const hideTarget of hideTasks) {
if (target === hideTarget) {
return false;
}

const [scope = '', task = ''] = hideTarget.split(':', 2);
const scopePattern = scope === '' || scope === '*' ? '^[^:]+' : `^${scope}`;
const taskPattern = task === '' || task === '*' ? '[^:]+$' : `${task}$`;
const pattern = new RegExp(`${scopePattern}:${taskPattern}`, 'i');

if (pattern.test(target)) {
return false;
}
}

return true;
}

class NoTasks extends TreeItem {
constructor() {
super('No tasks in project', TreeItemCollapsibleState.None);
Expand All @@ -60,7 +87,7 @@ class TaskItem extends TreeItem {
parent: ProjectItem;

constructor(parent: ProjectItem, task: ProjectTask) {
super(task.target.split(':')[1], TreeItemCollapsibleState.None);
super(task.target.split(':', 2)[1], TreeItemCollapsibleState.None);

this.parent = parent;
this.task = task;
Expand Down Expand Up @@ -107,10 +134,14 @@ class ProjectItem extends TreeItem {
this.tooltip = `${metadata.name} - ${metadata.description}`;
}

this.tasks = Object.values(project.tasks).map((task) => new TaskItem(this, task));
this.tasks = Object.values(project.tasks)
.filter((task) => canShowTask(task.target, this.parent.hideTasks))
.map((task) => new TaskItem(this, task));

this.resourceUri = Uri.file(
path.join(project.root, LANGUAGE_MANIFESTS[language] || 'moon.yml'),
);

this.iconPath =
language === 'unknown' ? new ThemeIcon('question') : createLangIcon(this.context, language);
}
Expand All @@ -121,12 +152,16 @@ class ProjectCategoryItem extends TreeItem {

projects: ProjectItem[] = [];

hideTasks: Set<string>;

constructor(context: vscode.ExtensionContext, type: ProjectType, projects: Project[]) {
super(type, TreeItemCollapsibleState.Expanded);

this.context = context;
this.id = type;
this.contextValue = 'projectCategory';

this.hideTasks = new Set(vscode.workspace.getConfiguration('moon').get('hideTasks', []));
this.projects = projects
.filter(
(project) => project.config.type === type || (type === 'unknown' && !project.config.type),
Expand Down Expand Up @@ -174,7 +209,7 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {

// When `.moon/*.yml` is changed, refresh projects
const watcher1 = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(wsDir, '.moon/*.yml'),
new vscode.RelativePattern(wsDir, '.moon/**/*.yml'),
);
watcher1.onDidChange(this.refresh, this);

Expand All @@ -186,7 +221,7 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {

context.subscriptions.push(
vscode.commands.registerCommand('moon.refreshProjects', this.refresh, this),
vscode.commands.registerCommand('moon.runTarget', this.runTarget, this),
vscode.commands.registerCommand('moon.runTask', this.runTask, this),
vscode.commands.registerCommand('moon.checkProject', this.checkProject, this),
vscode.commands.registerCommand('moon.viewProject', this.viewProject, this),
watcher1,
Expand Down Expand Up @@ -232,6 +267,7 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {

const categories = [
new ProjectCategoryItem(this.context, 'application', this.projects),
new ProjectCategoryItem(this.context, 'automation', this.projects),
new ProjectCategoryItem(this.context, 'library', this.projects),
new ProjectCategoryItem(this.context, 'tool', this.projects),
new ProjectCategoryItem(this.context, 'unknown', this.projects),
Expand All @@ -254,8 +290,8 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {
this.onDidChangeTreeDataEmitter.fire(null);
}

async runTarget(item: TaskItem) {
await runTarget(item.task.target, this.workspaceRoot, (task) => {
async runTask(item: TaskItem) {
await runTask(item.task.target, this.workspaceRoot, (task) => {
switch (item.task.type) {
case 'build':
task.group = TaskGroup.Build;
Expand Down