From cc896b6e65a727e7f06159f40ec4c9f550e52f6b Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 26 Nov 2024 19:21:08 -0800 Subject: [PATCH] new: Support task graph. --- packages/vscode-extension/.eslintrc.js | 1 + packages/vscode-extension/CHANGELOG.md | 5 +++++ packages/vscode-extension/package.json | 20 +++++++++++++++++++ packages/vscode-extension/src/commands.ts | 14 ++++++++++++- packages/vscode-extension/src/extension.ts | 9 ++++++++- .../src/graphVisualizerView.ts | 14 ++++++++++--- packages/vscode-extension/src/projectsView.ts | 17 ++++++++++------ 7 files changed, 69 insertions(+), 11 deletions(-) diff --git a/packages/vscode-extension/.eslintrc.js b/packages/vscode-extension/.eslintrc.js index 6ddce1f..061fdb9 100644 --- a/packages/vscode-extension/.eslintrc.js +++ b/packages/vscode-extension/.eslintrc.js @@ -4,6 +4,7 @@ module.exports = { rules: { 'max-classes-per-file': 'off', 'no-console': 'off', + 'no-nested-ternary': 'off', 'no-param-reassign': 'off', // We want to use exhaustive checks 'default-case': 'off', diff --git a/packages/vscode-extension/CHANGELOG.md b/packages/vscode-extension/CHANGELOG.md index 0ab7bdc..8194677 100644 --- a/packages/vscode-extension/CHANGELOG.md +++ b/packages/vscode-extension/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.14.0 + +- Added support for the task graph. Requires moon v1.30. +- Added support for `.pkl` config files. + ## 0.13.0 - Added a new command that will generate local `yaml.schemas` settings. diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index 5947477..fea2add 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -39,6 +39,7 @@ }, "activationEvents": [ "workspaceContains:.moon", + "workspaceContains:**/moon.pkl", "workspaceContains:**/moon.yml" ], "extensionDependencies": [ @@ -120,6 +121,11 @@ { "command": "moon.viewProjectGraph", "title": "moon: View project graph", + "icon": "$(group-by-ref-type)" + }, + { + "command": "moon.viewTaskGraph", + "title": "moon: View task graph", "icon": "$(type-hierarchy-sub)" }, { @@ -176,6 +182,10 @@ { "command": "moon.viewProjectGraph", "when": "moon.hasBinary" + }, + { + "command": "moon.viewTaskGraph", + "when": "moon.hasBinary" } ], "view/title": [ @@ -213,6 +223,16 @@ "command": "moon.viewProjectGraph", "when": "view == moonProjectsExternal && moon.hasBinary", "group": "navigation" + }, + { + "command": "moon.viewTaskGraph", + "when": "view == moonProjects && moon.hasBinary", + "group": "navigation" + }, + { + "command": "moon.viewTaskGraph", + "when": "view == moonProjectsExternal && moon.hasBinary", + "group": "navigation" } ], "view/item/context": [ diff --git a/packages/vscode-extension/src/commands.ts b/packages/vscode-extension/src/commands.ts index 820f35d..bdfc972 100644 --- a/packages/vscode-extension/src/commands.ts +++ b/packages/vscode-extension/src/commands.ts @@ -94,11 +94,23 @@ export async function viewProjectGraph(context: vscode.ExtensionContext, workspa await new GraphVisualizerView(context, workspace, 'project-graph').renderPanel(); } +export async function viewTaskGraph(context: vscode.ExtensionContext, workspace: Workspace) { + const version = await workspace.getMoonVersion(); + + if (satisfies(version, '<1.30.0')) { + await vscode.window.showErrorMessage(`Task graph requires moon >= 1.30.0, found ${version}`); + + return; + } + + await new GraphVisualizerView(context, workspace, 'task-graph').renderPanel(); +} + export async function appendSchemasConfig(context: vscode.ExtensionContext, workspace: Workspace) { const version = await workspace.getMoonVersion(); if (satisfies(version, '<1.27.0')) { - await vscode.window.showErrorMessage('YAML schemas require moon >= 1.27.0'); + await vscode.window.showErrorMessage(`YAML schemas require moon >= 1.27.0, found ${version}`); return; } diff --git a/packages/vscode-extension/src/extension.ts b/packages/vscode-extension/src/extension.ts index 02d6ce6..67a7c6e 100644 --- a/packages/vscode-extension/src/extension.ts +++ b/packages/vscode-extension/src/extension.ts @@ -1,5 +1,11 @@ import vscode from 'vscode'; -import { appendSchemasConfig, runTaskByInput, viewActionGraph, viewProjectGraph } from './commands'; +import { + appendSchemasConfig, + runTaskByInput, + viewActionGraph, + viewProjectGraph, + viewTaskGraph, +} from './commands'; import { LastRunProvider } from './lastRunView'; import { ProjectsProvider } from './projectsView'; import { Workspace } from './workspace'; @@ -22,6 +28,7 @@ export function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand('moon.viewProjectGraph', () => viewProjectGraph(context, workspace), ), + vscode.commands.registerCommand('moon.viewTaskGraph', () => viewTaskGraph(context, workspace)), vscode.commands.registerCommand('moon.appendSchemasConfig', () => appendSchemasConfig(context, workspace), ), diff --git a/packages/vscode-extension/src/graphVisualizerView.ts b/packages/vscode-extension/src/graphVisualizerView.ts index 1c1935b..0d5e618 100644 --- a/packages/vscode-extension/src/graphVisualizerView.ts +++ b/packages/vscode-extension/src/graphVisualizerView.ts @@ -2,7 +2,7 @@ import { satisfies } from 'semver'; import vscode, { ViewColumn } from 'vscode'; import type { Workspace } from './workspace'; -export type GraphType = 'action-graph' | 'project-graph'; +export type GraphType = 'action-graph' | 'project-graph' | 'task-graph'; export class GraphVisualizerView { context: vscode.ExtensionContext; @@ -18,8 +18,16 @@ export class GraphVisualizerView { this.workspace = workspace; this.type = type; this.panel = vscode.window.createWebviewPanel( - type === 'action-graph' ? 'moonActionGraph' : 'moonProjectGraph', - type === 'action-graph' ? 'Action graph' : 'Project graph', + type === 'action-graph' + ? 'moonActionGraph' + : type === 'project-graph' + ? 'moonProjectGraph' + : 'moonTaskGraph', + type === 'action-graph' + ? 'Action graph' + : type === 'project-graph' + ? 'Project graph' + : 'Task graph', ViewColumn.Active, { enableScripts: true, diff --git a/packages/vscode-extension/src/projectsView.ts b/packages/vscode-extension/src/projectsView.ts index d6271de..c52b6db 100644 --- a/packages/vscode-extension/src/projectsView.ts +++ b/packages/vscode-extension/src/projectsView.ts @@ -310,14 +310,14 @@ export class ProjectsProvider implements vscode.TreeDataProvider { return undefined; } - // When `.moon/**/*.yml` is changed, refresh projects + // When `.moon/**/*.*` is changed, refresh projects const watcher1 = vscode.workspace.createFileSystemWatcher( - new vscode.RelativePattern(folder.uri, workspace.getMoonDirPath('**/*.yml')), + new vscode.RelativePattern(folder.uri, workspace.getMoonDirPath('**/*.{pkl,yml}')), ); - // When `moon.yml` is changed, refresh projects + // When `moon.*` is changed, refresh projects const watcher2 = vscode.workspace.createFileSystemWatcher( - new vscode.RelativePattern(folder.uri, '**/moon.yml'), + new vscode.RelativePattern(folder.uri, '**/moon.{pkl,yml}'), ); watcher1.onDidChange(this.refresh, this); @@ -450,11 +450,16 @@ export class ProjectsProvider implements vscode.TreeDataProvider { async viewProject(item: ProjectItem) { await vscode.commands.executeCommand('workbench.view.explorer'); - const configUri = Uri.file(path.join(item.project.root, 'moon.yml')); + const yamlUri = Uri.file(path.join(item.project.root, 'moon.yml')); + const pklUri = Uri.file(path.join(item.project.root, 'moon.pkl')); await vscode.commands.executeCommand( 'vscode.open', - fs.existsSync(configUri.fsPath) ? configUri : item.resourceUri, + fs.existsSync(yamlUri.fsPath) + ? yamlUri + : fs.existsSync(pklUri.fsPath) + ? pklUri + : item.resourceUri, ); // await vscode.commands.executeCommand('vscode.openFolder', Uri.file(item.project.root));