дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
Before the SQL console runs a statement that changes or clears a whole table (a DELETE or UPDATE without WHERE, and similar cases), it shows a warning banner with Execute, Execute and Suppress (no more warnings in this console) and close; nothing runs until the user chooses. The statement also gets a squiggle, a gutter icon and a hover. The check runs on the text after parameter substitution, and works with the console's streaming execution. Co-authored-by: kidp2h <[email protected]>
38 рядки
1.5 KiB
TypeScript
38 рядки
1.5 KiB
TypeScript
/** Problems a feature marks on its own text (database console) show in the editor hover like diagnostics. */
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { EditorState } from "@codemirror/state";
|
|
import { EditorView } from "@codemirror/view";
|
|
import { problemProviders } from "@/editor/api";
|
|
import { hoverSource } from "./hover";
|
|
|
|
let view: EditorView | null = null;
|
|
afterEach(() => {
|
|
view?.destroy();
|
|
view = null;
|
|
document.body.replaceChildren();
|
|
});
|
|
|
|
function editor() {
|
|
const state = EditorState.create({
|
|
doc: "DELETE FROM t WHERE 1=1",
|
|
extensions: [problemProviders.of(() => [{ from: 20, to: 23, severity: "warning", message: "Unsafe query" }])],
|
|
});
|
|
return (view = new EditorView({ state, parent: document.body.appendChild(document.createElement("div")) }));
|
|
}
|
|
|
|
describe("contributed problems in the hover", () => {
|
|
it("shows the problem under the pointer with its severity icon and no quick-fix links", async () => {
|
|
const tip = await hoverSource(editor(), 21);
|
|
expect(tip).toMatchObject({ pos: 20, end: 23 });
|
|
const { dom } = tip!.create();
|
|
const row = dom.querySelector(".cm-lsp-diag-warning")!;
|
|
expect(row.querySelector(".cm-lsp-diag-message")?.textContent).toBe("Unsafe query");
|
|
expect(row.querySelector(".cm-lsp-diag-icon")).not.toBeNull();
|
|
expect(dom.querySelector(".cm-lsp-link-button")).toBeNull();
|
|
});
|
|
|
|
it("stays out away from the problem", async () => {
|
|
expect(await hoverSource(editor(), 3)).toBeNull();
|
|
});
|
|
});
|