Merge pull request 'Fix EDH no-workspace command registration (#8) + selection context menus (#9)' (#10) from fix/edh-no-workspace-and-context-menus into main
This commit was merged in pull request #10.
This commit is contained in:
Vendored
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
"name": "Run Extension",
|
"name": "Run Extension",
|
||||||
"type": "extensionHost",
|
"type": "extensionHost",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
|
"args": ["${workspaceFolder}", "--extensionDevelopmentPath=${workspaceFolder}"],
|
||||||
"outFiles": ["${workspaceFolder}/out/**/*.cjs"],
|
"outFiles": ["${workspaceFolder}/out/**/*.cjs"],
|
||||||
"preLaunchTask": "npm: build"
|
"preLaunchTask": "npm: build"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,18 @@
|
|||||||
"commandPalette": [
|
"commandPalette": [
|
||||||
{ "command": "cowriting.applyAgentEdit", "when": "false" }
|
{ "command": "cowriting.applyAgentEdit", "when": "false" }
|
||||||
],
|
],
|
||||||
|
"editor/context": [
|
||||||
|
{
|
||||||
|
"command": "cowriting.editSelection",
|
||||||
|
"when": "editorHasSelection && resourceScheme == file",
|
||||||
|
"group": "1_cowriting@1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "cowriting.createThread",
|
||||||
|
"when": "editorHasSelection && resourceScheme == file",
|
||||||
|
"group": "1_cowriting@2"
|
||||||
|
}
|
||||||
|
],
|
||||||
"comments/commentThread/context": [
|
"comments/commentThread/context": [
|
||||||
{ "command": "cowriting.reply", "group": "inline", "when": "commentController == cowriting.threads" }
|
{ "command": "cowriting.reply", "group": "inline", "when": "commentController == cowriting.threads" }
|
||||||
],
|
],
|
||||||
|
|||||||
+22
-1
@@ -38,7 +38,28 @@ export function activate(context: vscode.ExtensionContext): CowritingApi | undef
|
|||||||
|
|
||||||
// --- F2: region-anchored threads (Feature #4) ---
|
// --- F2: region-anchored threads (Feature #4) ---
|
||||||
const root = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
|
const root = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
|
||||||
if (!root) return undefined; // no workspace → nothing to anchor against
|
if (!root) {
|
||||||
|
// No folder open → nothing to anchor against, but every contributed
|
||||||
|
// command must still exist: leave them unregistered and the palette
|
||||||
|
// errors with "command not found" (#8). Register warning stubs instead;
|
||||||
|
// opening a folder reloads the window, re-running activate with a root.
|
||||||
|
const stub = () =>
|
||||||
|
void vscode.window.showWarningMessage(
|
||||||
|
"Cowriting: open a folder first — coauthoring anchors threads and attribution to workspace files.",
|
||||||
|
);
|
||||||
|
for (const command of [
|
||||||
|
"cowriting.createThread",
|
||||||
|
"cowriting.reply",
|
||||||
|
"cowriting.resolveThread",
|
||||||
|
"cowriting.reopenThread",
|
||||||
|
"cowriting.editSelection",
|
||||||
|
"cowriting.toggleAttribution",
|
||||||
|
"cowriting.applyAgentEdit",
|
||||||
|
]) {
|
||||||
|
context.subscriptions.push(vscode.commands.registerCommand(command, stub));
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
const store = new CoauthorStore(root);
|
const store = new CoauthorStore(root);
|
||||||
const threadController = new ThreadController(store, root);
|
const threadController = new ThreadController(store, root);
|
||||||
context.subscriptions.push(threadController);
|
context.subscriptions.push(threadController);
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ async function main(): Promise<void> {
|
|||||||
launchArgs: [workspace, "--disable-extensions"],
|
launchArgs: [workspace, "--disable-extensions"],
|
||||||
extensionTestsEnv: { E2E_WORKSPACE: workspace },
|
extensionTestsEnv: { E2E_WORKSPACE: workspace },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Second pass — NO workspace folder (regression for #8): commands must
|
||||||
|
// exist as warning stubs instead of erroring "command not found".
|
||||||
|
await runTests({
|
||||||
|
extensionDevelopmentPath,
|
||||||
|
extensionTestsPath: path.resolve(__dirname, "./suite-no-workspace/index"),
|
||||||
|
launchArgs: ["--disable-extensions"],
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
fs.rmSync(workspace, { recursive: true, force: true });
|
fs.rmSync(workspace, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import * as path from "path";
|
||||||
|
import Mocha from "mocha";
|
||||||
|
import { glob } from "glob";
|
||||||
|
|
||||||
|
export async function run(): Promise<void> {
|
||||||
|
const mocha = new Mocha({ ui: "tdd", color: true, timeout: 60000 });
|
||||||
|
const testsRoot = path.resolve(__dirname);
|
||||||
|
const files = await glob("**/*.test.js", { cwd: testsRoot });
|
||||||
|
for (const f of files) mocha.addFile(path.resolve(testsRoot, f));
|
||||||
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
mocha.run((failures) => (failures > 0 ? reject(new Error(`${failures} E2E test(s) failed`)) : resolve()));
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import * as assert from "assert";
|
||||||
|
import * as vscode from "vscode";
|
||||||
|
|
||||||
|
// Regression for #8: with NO workspace folder open, activate() used to return
|
||||||
|
// before registering the F2/F3 commands, so the palette errored with
|
||||||
|
// "command 'cowriting.editSelection' not found". The fix registers warning
|
||||||
|
// stubs instead. This suite runs in a second EDH pass launched WITHOUT a
|
||||||
|
// folder (see runTest.ts).
|
||||||
|
|
||||||
|
suite("no-workspace activation (#8)", () => {
|
||||||
|
test("EDH really has no workspace folder", () => {
|
||||||
|
assert.strictEqual(vscode.workspace.workspaceFolders, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("all contributed coauthoring commands are registered as warning stubs", async () => {
|
||||||
|
const ext = vscode.extensions.getExtension("benstull.vscode-cowriting-plugin")!;
|
||||||
|
const api = await ext.activate();
|
||||||
|
assert.strictEqual(api, undefined, "no-root activation returns no API");
|
||||||
|
const all = await vscode.commands.getCommands(true);
|
||||||
|
for (const command of [
|
||||||
|
"cowriting.createThread",
|
||||||
|
"cowriting.reply",
|
||||||
|
"cowriting.resolveThread",
|
||||||
|
"cowriting.reopenThread",
|
||||||
|
"cowriting.editSelection",
|
||||||
|
"cowriting.toggleAttribution",
|
||||||
|
"cowriting.applyAgentEdit",
|
||||||
|
]) {
|
||||||
|
assert.ok(all.includes(command), `${command} is registered`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("invoking a stub does not throw (shows a warning instead)", async () => {
|
||||||
|
await vscode.commands.executeCommand("cowriting.editSelection");
|
||||||
|
await vscode.commands.executeCommand("cowriting.createThread");
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user