Skip to content

Commit

Permalink
new: Support task graph.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 27, 2024
1 parent 5d382b9 commit cc896b6
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/vscode-extension/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions packages/vscode-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
20 changes: 20 additions & 0 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"activationEvents": [
"workspaceContains:.moon",
"workspaceContains:**/moon.pkl",
"workspaceContains:**/moon.yml"
],
"extensionDependencies": [
Expand Down Expand Up @@ -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)"
},
{
Expand Down Expand Up @@ -176,6 +182,10 @@
{
"command": "moon.viewProjectGraph",
"when": "moon.hasBinary"
},
{
"command": "moon.viewTaskGraph",
"when": "moon.hasBinary"
}
],
"view/title": [
Expand Down Expand Up @@ -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": [
Expand Down
14 changes: 13 additions & 1 deletion packages/vscode-extension/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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),
),
Expand Down
14 changes: 11 additions & 3 deletions packages/vscode-extension/src/graphVisualizerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions packages/vscode-extension/src/projectsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,14 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {
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);
Expand Down Expand Up @@ -450,11 +450,16 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {
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));
Expand Down

0 comments on commit cc896b6

Please sign in to comment.