mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-30 00:19:35 +00:00
fix(editor): suppress completion after punctuation
This commit is contained in:
@@ -6,7 +6,11 @@ import { resolveExecutableSql } from "@/lib/sqlExecutionTarget";
|
||||
import { formatSqlText, type SqlFormatDialect } from "@/lib/sqlFormatter";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { buildSqlCompletionItemsFromContext, getSqlCompletionContext } from "@/lib/sqlCompletion";
|
||||
import {
|
||||
buildSqlCompletionItemsFromContext,
|
||||
getSqlCompletionContext,
|
||||
shouldAutoOpenSqlCompletion,
|
||||
} from "@/lib/sqlCompletion";
|
||||
import { extractIdentifierAt, isSqlKeyword, matchTable } from "@/lib/sqlNavigation";
|
||||
import { loadEditorTheme, editorFontTheme } from "@/lib/editorThemes";
|
||||
import type { SqlCompletionColumn } from "@/lib/sqlCompletion";
|
||||
@@ -122,11 +126,17 @@ async function formatCurrentSql() {
|
||||
}
|
||||
}
|
||||
|
||||
async function provideSqlCompletions(currentState: import("@codemirror/state").EditorState, position: number) {
|
||||
async function provideSqlCompletions(
|
||||
currentState: import("@codemirror/state").EditorState,
|
||||
position: number,
|
||||
explicit: boolean,
|
||||
) {
|
||||
if (!props.connectionId || !props.database) return null;
|
||||
|
||||
try {
|
||||
const fullDoc = currentState.doc.toString();
|
||||
if (!explicit && !shouldAutoOpenSqlCompletion(fullDoc, position)) return null;
|
||||
|
||||
const completionContext = getSqlCompletionContext(fullDoc, position);
|
||||
const shouldLoadTables = completionContext.suggestTables || !!completionContext.qualifier;
|
||||
let tables = shouldLoadTables
|
||||
@@ -338,7 +348,9 @@ onMounted(async () => {
|
||||
sql({ dialect }),
|
||||
autocompletion({
|
||||
activateOnTyping: true,
|
||||
override: [async (context: CompletionContext) => provideSqlCompletions(context.state, context.pos)],
|
||||
override: [
|
||||
async (context: CompletionContext) => provideSqlCompletions(context.state, context.pos, context.explicit),
|
||||
],
|
||||
}),
|
||||
codeMirrorTheme.of(theme),
|
||||
closeBrackets(),
|
||||
|
||||
@@ -333,6 +333,12 @@ export function buildSqlCompletionItemsFromContext(
|
||||
return dedupeAndSort(items);
|
||||
}
|
||||
|
||||
export function shouldAutoOpenSqlCompletion(sql: string, cursor: number): boolean {
|
||||
const previousChar = sql[cursor - 1];
|
||||
if (!previousChar) return false;
|
||||
return /[\w$.]/.test(previousChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the start position of the SQL statement containing the cursor.
|
||||
* Respects semicolons and string literals.
|
||||
|
||||
Reference in New Issue
Block a user