Skip to content

Commit

Permalink
More work.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 31, 2023
1 parent 79a83cc commit d4cb037
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
9 changes: 2 additions & 7 deletions packages/vscode-extension/src/lastRunView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ export class LastRunProvider implements vscode.WebviewViewProvider {
this.context = context;
this.workspace = workspace;

// When `.moon/cache/runReport.json` is changed, refresh view
const watcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(
vscode.workspace.workspaceFolders?.[0] ?? workspace.root,
REPORT_PATH,
),
);
// When the report is changed, refresh view
const watcher = vscode.workspace.createFileSystemWatcher(REPORT_PATH);
watcher.onDidChange(this.renderView, this);
watcher.onDidCreate(this.renderView, this);
watcher.onDidDelete(this.renderView, this);
Expand Down
22 changes: 7 additions & 15 deletions packages/vscode-extension/src/projectsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import vscode, {
} from 'vscode';
import type { LanguageType, Project, ProjectType, Task as ProjectTask } from '@moonrepo/types';
import { checkProject, runTask } from './commands';
import { execMoon, getMoonVersion } from './moon';
import type { Workspace } from './workspace';

const LANGUAGE_MANIFESTS: Record<LanguageType, string> = {
Expand All @@ -39,7 +38,7 @@ function createLangIcon(context: vscode.ExtensionContext, name: LanguageType) {
};
}

const unknown = context.asAbsolutePath(path.join(`assets/langs/unknown.svg`));
const unknown = context.asAbsolutePath(path.join('assets/langs/unknown.svg'));

return {
dark: unknown,
Expand Down Expand Up @@ -206,18 +205,12 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {
this.onDidChangeTreeDataEmitter = new EventEmitter<TreeItem | null>();
this.onDidChangeTreeData = this.onDidChangeTreeDataEmitter.event;

const wsDir = vscode.workspace.workspaceFolders?.[0] ?? workspaceRoot;

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

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

context.subscriptions.push(
Expand Down Expand Up @@ -252,12 +245,11 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {
}

if (!this.projects) {
const version = await getMoonVersion(this.workspaceRoot);
const version = await this.workspace.getMoonVersion();

const { projects } = JSON.parse(
await execMoon(
await this.workspace.execMoon(
satisfies(version, '>=0.24.0') ? ['query', 'projects', '--json'] : ['query', 'projects'],
this.workspaceRoot,
),
) as {
projects: Project[];
Expand Down Expand Up @@ -292,7 +284,7 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {
}

async runTask(item: TaskItem) {
await runTask(item.task.target, this.workspaceRoot, (task) => {
await runTask(item.task.target, this.workspace, (task) => {
switch (item.task.type) {
case 'build':
task.group = TaskGroup.Build;
Expand All @@ -305,7 +297,7 @@ export class ProjectsProvider implements vscode.TreeDataProvider<TreeItem> {
}

async checkProject(item: ProjectItem) {
await checkProject(item.project.id, this.workspaceRoot);
await checkProject(item.project.id, this.workspace);
}

async viewProject(item: ProjectItem) {
Expand Down
12 changes: 10 additions & 2 deletions packages/vscode-extension/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import vscode from 'vscode';
import { findMoonBin, isRealBin } from './moon';

export class Workspace {
// Current moon binary path
binPath: string | null = null;

// Current vscode workspace folder
Expand All @@ -14,11 +15,18 @@ export class Workspace {
constructor() {
// When a file is opened, attempt to find the moon workspace
vscode.workspace.onDidOpenTextDocument((text) => {
void this.findWorkspaceRoot(text.uri);
void this.findRoot(text.uri);
});
vscode.workspace.onDidCloseTextDocument((text) => {
void this.findRoot(text.uri);
});
}

async findWorkspaceRoot(openUri: vscode.Uri) {
async findRoot(openUri: vscode.Uri) {
if (this.root && openUri.fsPath.startsWith(this.root)) {
return;
}

const workspaceFolder = vscode.workspace.getWorkspaceFolder(openUri);

if (workspaceFolder) {
Expand Down

0 comments on commit d4cb037

Please sign in to comment.