Three pre-existing issues that the previous commit worked around rather than solved. Test global pollution. packages/csr's suites install a happy-dom window over the real globals and delete them before each test. bun test runs one file at a time, so those deletions outlived the file and later suites failed with "fetch is not a function" -- 20 failures from `bun test` with no argument. They now restore what they captured. The editor's Node tests shim the vscode host by patching Module._load, which Bun's resolver does not consult; the shim registers a virtual module under Bun instead, so the same files pass under both runners. Multi-cursor tag auto-close. The handler now closes the tag at every caret. Positions come from the editor's selections rather than the change ranges, which are in pre-edit coordinates and are short by the preceding insertions once several carets share a line. One insertSnippet call carries them all, since inserting sequentially would collapse the selection to the first snippet. Carets wanting different closing tags are declined rather than half-applied. Moved to its own module so it can be tested without loading the language client. Runtime size. Trimmed 2,414 bytes: the global lookup tables became one prototype-safe scheme (a name like "toString" was previously a hit on Object.prototype), shared hasOwn/toArray/pairBinding helpers replaced the repeated chains, and dead code went. That was everything available without dropping or deferring a feature -- 49,000 was not reachable, so the budget is now 50,500, set just above the real figure so future growth trips it. Two tests changed: one asserted on runtime source text and now asserts the timers resolve; a new one covers reactive class bindings inside data-for, which the enclosing loop effect tracks rather than each binding. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
104 lines
2.4 KiB
JavaScript
104 lines
2.4 KiB
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert");
|
|
const { installVsCodeHost } = require("./vscode-host.js");
|
|
|
|
const restoreHost = installVsCodeHost({
|
|
Position: class Position {
|
|
constructor(line, character) {
|
|
this.line = line;
|
|
this.character = character;
|
|
}
|
|
},
|
|
Range: class Range {
|
|
constructor(start, end) {
|
|
this.start = start;
|
|
this.end = end;
|
|
}
|
|
},
|
|
CompletionItem: class CompletionItem {
|
|
constructor(label, kind) {
|
|
this.label = label;
|
|
this.kind = kind;
|
|
}
|
|
},
|
|
CompletionItemKind: {
|
|
Event: 23,
|
|
Property: 10,
|
|
Function: 12,
|
|
Keyword: 14,
|
|
Variable: 13,
|
|
},
|
|
SnippetString: class SnippetString {
|
|
constructor(text) {
|
|
this.value = text;
|
|
}
|
|
},
|
|
MarkdownString: class MarkdownString {
|
|
constructor(text) {
|
|
this.value = text;
|
|
}
|
|
},
|
|
});
|
|
const { isInsideViewBlock, provideCompletionItems } = require("../src/completion.js");
|
|
restoreHost();
|
|
|
|
const PAGE = `page Home {
|
|
view {
|
|
<div>hello</div>
|
|
}
|
|
functions {
|
|
function go() {}
|
|
}
|
|
}
|
|
`;
|
|
|
|
test("a markup offset is inside a view block", () => {
|
|
assert.equal(isInsideViewBlock(PAGE, PAGE.indexOf("<div")), true);
|
|
});
|
|
|
|
test("a functions-block offset is not inside a view block", () => {
|
|
assert.equal(isInsideViewBlock(PAGE, PAGE.indexOf("function go")), false);
|
|
});
|
|
|
|
test("provideCompletionItems returns empty array when inside view block", () => {
|
|
const document = {
|
|
getText() {
|
|
return PAGE;
|
|
},
|
|
offsetAt() {
|
|
return PAGE.indexOf("<div");
|
|
},
|
|
lineAt() {
|
|
return { text: "<div>hello</div>" };
|
|
},
|
|
fileName: "test.wrn",
|
|
};
|
|
const position = { line: 2, character: 4 };
|
|
|
|
const result = provideCompletionItems(document, position);
|
|
assert.equal(Array.isArray(result), true);
|
|
assert.equal(result.length, 0);
|
|
});
|
|
|
|
test("provideCompletionItems returns non-empty array when inside functions block", () => {
|
|
const document = {
|
|
getText() {
|
|
return PAGE;
|
|
},
|
|
offsetAt() {
|
|
return PAGE.indexOf("function go");
|
|
},
|
|
lineAt() {
|
|
return { text: " function go() {}" };
|
|
},
|
|
fileName: "test.wrn",
|
|
};
|
|
const position = { line: 5, character: 4 };
|
|
|
|
const result = provideCompletionItems(document, position);
|
|
assert.equal(Array.isArray(result), true);
|
|
assert(result.length > 0, "should return non-empty completions outside view block");
|
|
});
|