fix(editor): skip statement frame for oversized oracle package bodies
This commit is contained in:
1 parent
0f9d32e1f5
commit
1e9babca45
2 files changed
+37
-1
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { Text } from "@codemirror/state";
|
||||
import { currentStatementFrameLayer, currentStatementFrameRect, FRAME_INSET_PX } from "@/lib/editor/codemirrorCurrentStatementFrameLayer";
|
||||
import { currentStatementFrameLayer, currentStatementFrameRect, FRAME_INSET_PX, MAX_FRAME_STATEMENT_LINES } from "@/lib/editor/codemirrorCurrentStatementFrameLayer";
|
||||
|
||||
interface CoordRect {
|
||||
left: number;
|
||||
@@ -252,6 +252,30 @@ describe("currentStatementFrameRect", () => {
|
||||
const expectedHeight = (73 - 47) * LINE_HEIGHT + FRAME_INSET_PX * 2;
|
||||
expect(rect!.height).toBe(expectedHeight);
|
||||
});
|
||||
|
||||
it("skips huge multi-thousand-line statements instead of probing every line (dbx#7226)", () => {
|
||||
// A large Oracle package body is parsed as one statement spanning the
|
||||
// whole file. Without a cap, this loop would issue two coordsAtPos
|
||||
// calls per logical line, freezing the UI on every scroll frame.
|
||||
const lineCount = MAX_FRAME_STATEMENT_LINES + 2000;
|
||||
const lines = Array.from({ length: lineCount }, (_, i) => ` proc_body_line_${i};`);
|
||||
const view = buildView(lines);
|
||||
const coords = vi.spyOn(view, "coordsAtPos");
|
||||
|
||||
const rect = currentStatementFrameRect(view, 0, view.state.doc.length);
|
||||
|
||||
expect(rect).toBeNull();
|
||||
expect(coords).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("still frames a statement right at the line-count cap", () => {
|
||||
const lines = Array.from({ length: MAX_FRAME_STATEMENT_LINES + 1 }, (_, i) => `-- line ${i}`);
|
||||
const view = buildView(lines);
|
||||
|
||||
const rect = currentStatementFrameRect(view, 0, view.state.doc.length);
|
||||
|
||||
expect(rect).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("currentStatementFrameLayer", () => {
|
||||
|
||||
@@ -36,6 +36,17 @@ function spansVisualRows(start: PositionRect, end: PositionRect): boolean {
|
||||
return Math.abs(startMid - endMid) > Math.max(2, Math.min(startHeight, endHeight) / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Statements spanning more logical lines than this render no frame. The
|
||||
* horizontal-bounds loop below does a constant number of geometry probes
|
||||
* per logical line, so its cost is O(logical lines) — fine for ordinary
|
||||
* statements, but a multi-thousand-line PL/SQL package body (Oracle, and
|
||||
* other dialects with BEGIN/END routine bodies) is parsed as a single
|
||||
* statement spanning the whole file, turning routine scrolling into
|
||||
* thousands of `coordsAtPos` calls per frame. See dbx#7226.
|
||||
*/
|
||||
export const MAX_FRAME_STATEMENT_LINES = 500;
|
||||
|
||||
/**
|
||||
* Measure the pixel rectangle of one statement rendered in `view`.
|
||||
*
|
||||
@@ -62,6 +73,7 @@ export function currentStatementFrameRect(view: Viewish, from: number, to: numbe
|
||||
|
||||
const startLine = doc.lineAt(from);
|
||||
const endLine = doc.lineAt(to);
|
||||
if (endLine.number - startLine.number > MAX_FRAME_STATEMENT_LINES) return null;
|
||||
const base = view.scrollDOM.getBoundingClientRect();
|
||||
|
||||
// Vertical bounds: convert screen coords to content-layer coords.
|
||||
|
||||
Reference in new issue
Block a user