Skip to content
Merged
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
21 changes: 21 additions & 0 deletions frontend/src/core/codemirror/language/languages/sql/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ export class SQLLanguageAdapter
theme: defaultSqlHoverTheme(theme),
},
}),
EditorView.updateListener.of((update) => {
if (update.focusChanged) {
parser.setFocusState(update.view.hasFocus);
}
}),
);
}

Expand All @@ -293,6 +298,11 @@ export class SQLLanguageAdapter
class CustomSqlParser extends NodeSqlParser {
private validationTimeout: number | null = null;
private readonly VALIDATION_DELAY_MS = 300; // Wait 300ms after user stops typing
private isFocused = false; // Only validate if the editor is focused

setFocusState(focused: boolean) {
this.isFocused = focused;
}

private async validateWithDelay(
sql: string,
Expand All @@ -307,6 +317,12 @@ class CustomSqlParser extends NodeSqlParser {
// Set up a new request to be called after the delay
return new Promise((resolve) => {
this.validationTimeout = window.setTimeout(async () => {
// Only validate if the editor is still focused
if (!this.isFocused) {
resolve([]);
return;
}

try {
const sqlMode = getSQLMode();
const result = await validateSQL(sql, engine, dialect, sqlMode);
Expand All @@ -330,6 +346,11 @@ class CustomSqlParser extends NodeSqlParser {
): Promise<SqlParseError[]> {
const metadata = getSQLMetadata(opts.state);

// Only validate if the editor is focused
if (!this.isFocused) {
return [];
}

// Only perform custom validation for DuckDB
if (!INTERNAL_SQL_ENGINES.has(metadata.engine)) {
return super.validateSql(sql, opts);
Expand Down
Loading