From 2c80b2bd561915cc79a83f3c8d034a2b3ed45282 Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Fri, 17 Mar 2023 16:42:15 -0700 Subject: [PATCH 1/5] check for pxt.json anywhere in ws folder --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b409f3..37821f5 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "activationEvents": [ "onCommand:makecode.create", - "workspaceContains:./pxt.json", + "workspaceContains:**/pxt.json", "onFileSystem:mkcdfs" ], "browser": "./dist/web/extension.js", From d8b2ab31a1313c7eef340c880d04dcaf9e27e034 Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Fri, 17 Mar 2023 19:08:48 -0700 Subject: [PATCH 2/5] git diff --- package.json | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 37821f5..b5955a0 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "url": "https://github.com/microsoft/vscode-makecode" }, "activationEvents": [ - "onCommand:makecode.create", "workspaceContains:**/pxt.json", "onFileSystem:mkcdfs" ], @@ -283,6 +282,34 @@ { "command": "makecode.createTilemap", "when": "false" + }, + { + "command": "makecode.build", + "when": "makecode.extensionActive" + }, + { + "command": "makecode.simulate", + "when": "makecode.extensionActive" + }, + { + "command": "makecode.clean", + "when": "makecode.extensionActive" + }, + { + "command": "makecode.shareProject", + "when": "makecode.extensionActive" + }, + { + "command": "makecode.addDependency", + "when": "makecode.extensionActive" + }, + { + "command": "makecode.removeDependency", + "when": "makecode.extensionActive" + }, + { + "command": "makecode.refreshAssets", + "when": "makecode.extensionActive" } ] }, From b7938077cb59feb5ead11f0fd2c528d7c128c64e Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Fri, 17 Mar 2023 19:11:46 -0700 Subject: [PATCH 3/5] hide asset types, commands until a makecode project is actually loaded --- package.json | 29 ++++++++++++++++----------- src/web/extension.ts | 47 ++++++++++++++++++++++++++++++++------------ src/web/vfs.ts | 3 ++- 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index b5955a0..2f8598d 100644 --- a/package.json +++ b/package.json @@ -173,27 +173,32 @@ { "id": "imageExplorer", "name": "%makecode.imageExplorer.title%", - "icon": "media/logo.svg" + "icon": "media/logo.svg", + "when": "makecode.hasMakeCodeProjectOpen" }, { "id": "animationExplorer", "name": "%makecode.animationExplorer.title%", - "icon": "media/logo.svg" + "icon": "media/logo.svg", + "when": "makecode.hasMakeCodeProjectOpen" }, { "id": "tileExplorer", "name": "%makecode.tileExplorer.title%", - "icon": "media/logo.svg" + "icon": "media/logo.svg", + "when": "makecode.hasMakeCodeProjectOpen" }, { "id": "tilemapExplorer", "name": "%makecode.tilemapExplorer.title%", - "icon": "media/logo.svg" + "icon": "media/logo.svg", + "when": "makecode.hasMakeCodeProjectOpen" }, { "id": "songExplorer", "name": "%makecode.songExplorer.title%", - "icon": "media/logo.svg" + "icon": "media/logo.svg", + "when": "makecode.hasMakeCodeProjectOpen" } ] }, @@ -285,31 +290,31 @@ }, { "command": "makecode.build", - "when": "makecode.extensionActive" + "when": "makecode.hasMakeCodeProjectOpen" }, { "command": "makecode.simulate", - "when": "makecode.extensionActive" + "when": "makecode.hasMakeCodeProjectOpen" }, { "command": "makecode.clean", - "when": "makecode.extensionActive" + "when": "makecode.hasMakeCodeProjectOpen" }, { "command": "makecode.shareProject", - "when": "makecode.extensionActive" + "when": "makecode.hasMakeCodeProjectOpen" }, { "command": "makecode.addDependency", - "when": "makecode.extensionActive" + "when": "makecode.hasMakeCodeProjectOpen" }, { "command": "makecode.removeDependency", - "when": "makecode.extensionActive" + "when": "makecode.hasMakeCodeProjectOpen" }, { "command": "makecode.refreshAssets", - "when": "makecode.extensionActive" + "when": "makecode.hasMakeCodeProjectOpen" } ] }, diff --git a/src/web/extension.ts b/src/web/extension.ts index 2344d15..ffdcc7c 100644 --- a/src/web/extension.ts +++ b/src/web/extension.ts @@ -108,6 +108,11 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.window.registerTreeDataProvider("songExplorer", new JResTreeProvider("song")) ); + context.subscriptions.push( + vscode.workspace.onDidChangeWorkspaceFolders(e => { + maybeSetInMakeCodeProjectAsync(); + }) + ) // This key is not sensitive, and is publicly available in client side apps logging to AI const appInsightsKey = "0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255"; @@ -124,28 +129,42 @@ export function activate(context: vscode.ExtensionContext) { // Set a context key to indicate that we have activated, so context menu commands can show vscode.commands.executeCommand('setContext', 'makecode.extensionActive', true); + maybeSetInMakeCodeProjectAsync(); } -async function chooseWorkspaceAsync(kind: "empty" | "project" | "any", silent = false): Promise { +async function maybeSetInMakeCodeProjectAsync() { + const hasProjectFolder = await findOpenFolders("project"); + if (!!hasProjectFolder.length) { + setInMakeCodeProjectAsync(); + } +} + +export function setInMakeCodeProjectAsync() { + vscode.commands.executeCommand("setContext", "makecode.hasMakeCodeProjectOpen", true); +} + +async function findOpenFolders(kind: "empty" | "project" | "any") { const folders = []; - let hasWorkspaceOpen = false; - if (vscode.workspace.workspaceFolders) { - hasWorkspaceOpen = !!vscode.workspace.workspaceFolders.length; - for (const folder of vscode.workspace.workspaceFolders) { - if (kind === "any") { - folders.push(folder); - } - else { - const pxtJSONExists = await fileExistsAsync(vscode.Uri.joinPath(folder.uri, "pxt.json")); + for (const folder of (vscode.workspace.workspaceFolders || [])) { + if (kind === "any") { + folders.push(folder); + } + else { + const pxtJSONExists = await fileExistsAsync(vscode.Uri.joinPath(folder.uri, "pxt.json")); - if ((kind === "project" && pxtJSONExists) || (kind === "empty" && !pxtJSONExists)) { - folders.push(folder); - } + if ((kind === "project" && pxtJSONExists) || (kind === "empty" && !pxtJSONExists)) { + folders.push(folder); } } } + return folders; +} + +async function chooseWorkspaceAsync(kind: "empty" | "project" | "any", silent = false): Promise { + const folders = await findOpenFolders(kind); + const hasWorkspaceOpen = !!vscode.workspace.workspaceFolders?.length; if (folders.length === 0) { if (!silent) { @@ -302,6 +321,7 @@ export async function importUrlCommand(url?: string, useWorkspace?: vscode.Works }, async progress => { try { await downloadSharedProjectAsync(workspace!, toOpen!); + setInMakeCodeProjectAsync() } catch (e) { showError(vscode.l10n.t("Unable to download project")); @@ -502,6 +522,7 @@ async function createCommand() { }); } + setInMakeCodeProjectAsync(); await renameProjectAsync(workspace, projectName); } diff --git a/src/web/vfs.ts b/src/web/vfs.ts index 4b5f1e2..484c2ea 100644 --- a/src/web/vfs.ts +++ b/src/web/vfs.ts @@ -1,6 +1,6 @@ import * as path from "path-browserify" import * as vscode from "vscode" -import { importUrlCommand } from "./extension"; +import { importUrlCommand, setInMakeCodeProjectAsync } from "./extension"; export class VFS implements vscode.FileSystemProvider { private initializedDirs: {[index: string]: boolean} = {} @@ -119,6 +119,7 @@ export class VFS implements vscode.FileSystemProvider { if (!(await this.existsAsync(pxtJSON))) { await importUrlCommand(shareId, { name: shareId, uri: projectDir, index: 0 }) } + setInMakeCodeProjectAsync(); this.initializedDirs[shareId] = true; } From 265c762e0ed5757315edddfb5d6763554c6e617d Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Tue, 21 Mar 2023 10:48:59 -0700 Subject: [PATCH 4/5] only include context menu sim when in mkcd project, move to debug group re: #154 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2f8598d..9e21c12 100644 --- a/package.json +++ b/package.json @@ -210,9 +210,9 @@ "menus": { "editor/context": [ { - "when": "resourceLangId == typescript && makecode.extensionActive", + "when": "resourceLangId == typescript && makecode.extensionActive && makecode.hasMakeCodeProjectOpen", "command": "makecode.simulate", - "group": "navigation" + "group": "debug" } ], "view/title": [ From a7da5afd8611bc22b9ac8c9ff2de6610cff7d529 Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Thu, 30 Mar 2023 08:55:36 -0700 Subject: [PATCH 5/5] add condition on makecode.testBlocks command --- package.json | 4 ++++ src/web/extension.ts | 9 +++++---- src/web/vfs.ts | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ed07c79..3f60a46 100644 --- a/package.json +++ b/package.json @@ -320,6 +320,10 @@ { "command": "makecode.refreshAssets", "when": "makecode.hasMakeCodeProjectOpen" + }, + { + "command": "makecode.testBlocks", + "when": "makecode.hasMakeCodeProjectOpen" } ] }, diff --git a/src/web/extension.ts b/src/web/extension.ts index 1bca071..d8ff12c 100644 --- a/src/web/extension.ts +++ b/src/web/extension.ts @@ -137,11 +137,11 @@ export function activate(context: vscode.ExtensionContext) { async function maybeSetInMakeCodeProjectAsync() { const hasProjectFolder = await findOpenFolders("project"); if (!!hasProjectFolder.length) { - setInMakeCodeProjectAsync(); + setInMakeCodeProject(); } } -export function setInMakeCodeProjectAsync() { +export function setInMakeCodeProject() { vscode.commands.executeCommand("setContext", "makecode.hasMakeCodeProjectOpen", true); } @@ -263,6 +263,7 @@ export async function installCommand() { await vscode.commands.executeCommand("makecode.refreshAssets"); await vscode.commands.executeCommand("workbench.files.action.refreshFilesExplorer"); + setInMakeCodeProject(); }); } @@ -323,7 +324,7 @@ export async function importUrlCommand(url?: string, useWorkspace?: vscode.Works }, async progress => { try { await downloadSharedProjectAsync(workspace!, toOpen!); - setInMakeCodeProjectAsync() + setInMakeCodeProject() } catch (e) { showError(vscode.l10n.t("Unable to download project")); @@ -524,7 +525,7 @@ async function createCommand() { }); } - setInMakeCodeProjectAsync(); + setInMakeCodeProject(); await renameProjectAsync(workspace, projectName); } diff --git a/src/web/vfs.ts b/src/web/vfs.ts index 484c2ea..dec49ca 100644 --- a/src/web/vfs.ts +++ b/src/web/vfs.ts @@ -1,6 +1,6 @@ import * as path from "path-browserify" import * as vscode from "vscode" -import { importUrlCommand, setInMakeCodeProjectAsync } from "./extension"; +import { importUrlCommand, setInMakeCodeProject } from "./extension"; export class VFS implements vscode.FileSystemProvider { private initializedDirs: {[index: string]: boolean} = {} @@ -119,7 +119,7 @@ export class VFS implements vscode.FileSystemProvider { if (!(await this.existsAsync(pxtJSON))) { await importUrlCommand(shareId, { name: shareId, uri: projectDir, index: 0 }) } - setInMakeCodeProjectAsync(); + setInMakeCodeProject(); this.initializedDirs[shareId] = true; }