fix: stabilize configuration editor completion

This commit is contained in:
2026-09-02 14:18:51 +09:00
parent a664e72488
commit 925100fb82
6 changed files with 83 additions and 16 deletions
@@ -1,3 +1,4 @@
import denoConfig from "../../deno.json" with { type: "json" };
import { CODEMIRROR_VITE_DEDUPE } from "../../src/lib/workspace/config-source/vite-dedupe.ts";
declare const Deno: {
@@ -24,6 +25,13 @@ Deno.test("Vite deduplicates CodeMirror stateful packages", () => {
`Vite must deduplicate ${packageName}`,
);
}
for (const packageName of CODEMIRROR_VITE_DEDUPE) {
assert(
packageName in (denoConfig.imports ?? {}),
`${packageName} must be a direct dependency so Vite can deduplicate it`,
);
}
});
Deno.test("config editor snapshots Svelte proxies before cloning baselines", async () => {
@@ -92,11 +100,15 @@ Deno.test("Decodal editor follows readonly prop changes after mount", async () =
"CodeMirror theme must use workspace tokens that actually exist",
);
assert(
source.includes("keymap.of(completionKeymap)") &&
source.includes("keymap.of(completionKeymapWithoutEnter)") &&
source.includes("binding.key !== 'Enter'") &&
source.includes("activateOnTyping: false") &&
source.includes("shouldStartCompletionAfterTyping(insertedText)") &&
source.includes("startCompletion(editor)") &&
source.includes("update.selectionSet && !update.docChanged") &&
!source.includes("EditorView.domEventHandlers") &&
!source.includes("update.selectionSet") &&
source.includes("completionStatus(editor.state) === null"),
"completion should be explicitly available and start when an editable cursor moves into an empty schema position",
"completion should start only after non-whitespace typing, without using focus, cursor movement, Space, or Enter",
);
assert(
source.includes("fixedSchemaWrapperCompartment.reconfigure") &&
@@ -3,7 +3,10 @@ declare const Deno: {
readTextFile(path: URL): Promise<string>;
};
import { toCodeMirrorCompletion } from "../../src/lib/workspace/config-source/completion.ts";
import {
shouldStartCompletionAfterTyping,
toCodeMirrorCompletion,
} from "../../src/lib/workspace/config-source/completion.ts";
import { jsonWorkerMessage } from "../../src/lib/workspace/config-source/toolchain-message.ts";
function assert(condition: unknown, message: string): asserts condition {
@@ -67,6 +70,25 @@ Deno.test("toolchain converts reactive-like proxies to plain Worker messages", a
);
});
Deno.test("completion starts only after non-whitespace typing", () => {
assert(
!shouldStartCompletionAfterTyping(" "),
"Space should not start completion",
);
assert(
!shouldStartCompletionAfterTyping("\n"),
"Enter should not start completion",
);
assert(
!shouldStartCompletionAfterTyping("\t"),
"other whitespace should not start completion",
);
assert(
shouldStartCompletionAfterTyping("p"),
"non-whitespace typing should start completion",
);
});
Deno.test("toolchain preserves WASM UTF-16 completion ranges for CodeMirror", () => {
const result = toCodeMirrorCompletion({
from: "let 名 = ".length,