Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions apps/desktop/src/components/editor/QueryEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6077,6 +6077,7 @@ onMounted(async () => {
queryEditorLineCommentToken(props.databaseType) === "//" ? shellLineCommentHighlightPlugin : [],
];
const MAX_SQL_SEMANTIC_HIGHLIGHT_WINDOWS = 32;
const MAX_FULL_DOCUMENT_SQL_SEMANTIC_HIGHLIGHT_LENGTH = 128_000;
const SQL_SEMANTIC_HIGHLIGHT_DEBOUNCE_MS = 100;
const refreshSqlSemanticHighlightEffect = StateEffect.define<null>();
buildSqlSemanticHighlightExtension = () => [
Expand All @@ -6088,6 +6089,7 @@ onMounted(async () => {
if (this.currentView.dom.isConnected) this.currentView.dispatch({ effects: refreshSqlSemanticHighlightEffect.of(null) });
}, SQL_SEMANTIC_HIGHLIGHT_DEBOUNCE_MS);
private cachedDoc: import("@codemirror/state").Text | null = null;
private prewarmedDoc: import("@codemirror/state").Text | null = null;
private cachedSql = "";
private cachedDialectId = "";
private cachedDatabaseType: DatabaseType | undefined;
Expand All @@ -6098,6 +6100,7 @@ onMounted(async () => {
}> = [];

constructor(private currentView: import("@codemirror/view").EditorView) {
this.decorations = Decoration.none;
this.decorations = this.buildDecorations(currentView);
}

Expand Down Expand Up @@ -6143,13 +6146,15 @@ onMounted(async () => {
}

const sql = this.cachedSql;
const shouldPrewarmFullDocument = this.cachedWindows.length === 0 && this.prewarmedDoc !== doc && sql.length <= MAX_FULL_DOCUMENT_SQL_SEMANTIC_HIGHLIGHT_LENGTH;
const windows: Array<{
from: number;
to: number;
spans: Array<{ start: number; end: number }>;
}> = [];
const pendingWindows: Array<{ from: number; to: number }> = [];
for (const visibleRange of currentView.visibleRanges) {
const rangesToHighlight = shouldPrewarmFullDocument ? [{ from: 0, to: sql.length }] : currentView.visibleRanges;
for (const visibleRange of rangesToHighlight) {
const cached = this.cachedWindows.find((candidate) => candidate.from <= visibleRange.from && candidate.to >= visibleRange.to);
if (cached) {
if (!windows.includes(cached)) windows.push(cached);
Expand All @@ -6169,8 +6174,10 @@ onMounted(async () => {
}

if (pendingWindows.length > 0) {
const tree = ensureSyntaxTree(currentView.state, Math.max(...pendingWindows.map((window) => window.to)), 25);
if (!tree) return Decoration.set([]);
const requestedTo = Math.max(...pendingWindows.map((window) => window.to));
const tree = ensureSyntaxTree(currentView.state, requestedTo, requestedTo === sql.length ? 250 : 25);
if (!tree) return this.decorations;
if (shouldPrewarmFullDocument) this.prewarmedDoc = doc;
for (const window of pendingWindows) {
const entry = {
...window,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ describe("QueryEditor semantic highlighting while scrolling", () => {
expect(queryEditorSource).toContain("refreshSqlSemanticHighlightEffect.of(null)");
});

it("never exposes undefined decorations and prewarms the full document only once per document", () => {
expect(queryEditorSource).toContain("this.decorations = Decoration.none;");
expect(queryEditorSource).toContain('private prewarmedDoc: import("@codemirror/state").Text | null = null;');
expect(queryEditorSource).toContain("const shouldPrewarmFullDocument =");
expect(queryEditorSource).toContain("if (shouldPrewarmFullDocument) this.prewarmedDoc = doc;");
});

it("keeps preview and diagnostics on the shared statement-range cache", () => {
expect(queryEditorSource).toContain("executableStatementRangeCache = executableStatementRangeCacheForDoc");
expect(queryEditorSource).toContain('props.databaseType === "sqlserver" ? undefined : executableStatementRangeCache?.ranges');
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src/lib/editor/editorThemes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export function createRunStatementButtonDom(ariaLabel = "Execute statement"): HT
export function sqlSemanticHighlightTheme(EditorView: typeof import("@codemirror/view").EditorView): Extension {
return EditorView.theme({
".cm-sql-table-name, .cm-sql-table-name *": {
color: `var(${SQL_TABLE_COLOR_CSS_VAR}) !important`,
// Built-in CodeMirror themes do not define the editor-specific table color
// variable. Keep semantic table names visible there as well, while custom
// and IDE themes continue to use their configured table color.
color: `var(${SQL_TABLE_COLOR_CSS_VAR}, #b4530b) !important`,
},
});
}
Expand Down