дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
HTML files in Angular projects were highlighted as plain HTML. Languages can now declare framework UI modes with root markers (angular.json, node_modules/@angular/core); files under such a root get the framework's editor mode, re-detected when a marker appears or disappears, and the root-marker lookup is shared with language server roots. The Angular Template mode (vendored @codemirror/lang-angular, MIT) adds @if/@for/@switch/@defer/@let blocks, key and animation binding names, and colours {{ }} delimiters.
Lazily loaded editor modes are now loaded before a document's first editor opens, so a file never renders as plain text first (this also left Angular templates uncoloured).
Co-authored-by: nntndfrk <[email protected]>
55 рядки
1.6 KiB
TypeScript
55 рядки
1.6 KiB
TypeScript
import { expect, it, vi } from "vitest";
|
|
import { language as languageFacet } from "@codemirror/language";
|
|
import { createMemoryBackend } from "../backend";
|
|
import { DocumentManager } from "./document";
|
|
import { EditorSlot } from "./slot";
|
|
|
|
const loading = vi.hoisted(() => {
|
|
let finish!: () => void;
|
|
const ready = new Promise<void>((resolve) => {
|
|
finish = resolve;
|
|
});
|
|
return { ready, finish, started: false };
|
|
});
|
|
|
|
vi.mock("../cm/languages", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("../cm/languages")>();
|
|
return {
|
|
...actual,
|
|
loadSupport: async (...args: Parameters<typeof actual.loadSupport>) => {
|
|
loading.started = true;
|
|
await loading.ready;
|
|
return actual.loadSupport(...args);
|
|
},
|
|
};
|
|
});
|
|
|
|
it("waits for the lazy mode before exposing an Angular document to its first slot", async () => {
|
|
const manager = new DocumentManager(
|
|
createMemoryBackend({ "/p/angular.json": "{}", "/p/src/app.html": "<p>{{ name }}</p>" }),
|
|
{ settings: () => ({}), notify: vi.fn() },
|
|
);
|
|
let acquired = false;
|
|
const pending = manager.acquire("/p/src/app.html").then((model) => {
|
|
acquired = true;
|
|
return model;
|
|
});
|
|
await vi.waitFor(() => expect(loading.started).toBe(true));
|
|
try {
|
|
expect(acquired).toBe(false);
|
|
} finally {
|
|
loading.finish();
|
|
}
|
|
const model = await pending;
|
|
const slot = new EditorSlot(model, "t1", {
|
|
onFocus() {},
|
|
onBlur() {},
|
|
onSelection() {},
|
|
onUserEdit() {},
|
|
onContextMenu() {},
|
|
});
|
|
expect(slot.currentState().facet(languageFacet)?.name).toBe("angular");
|
|
slot.dispose();
|
|
manager.stop();
|
|
});
|