feat(editor): support executing all SQL from blank lines
This commit is contained in:
18 files changed
+82
-11
No files matched your search
@@ -21,20 +21,21 @@ describe("QueryEditor execution routing", () => {
|
||||
|
||||
it("keeps selection priority and the configured current/all target choice", () => {
|
||||
const selectionBranch = queryEditorSource.indexOf("if (!options.ignoreSelection && !selection.empty)");
|
||||
const executeModeBranch = queryEditorSource.indexOf("executionCandidateForMode(candidates, settingsStore.editorSettings.executeMode)");
|
||||
const executeModeBranch = queryEditorSource.indexOf("executionCandidateForMode(candidates, executeMode");
|
||||
|
||||
expect(selectionBranch).toBeGreaterThan(-1);
|
||||
expect(executeModeBranch).toBeGreaterThan(selectionBranch);
|
||||
});
|
||||
|
||||
it("does not fall back to all SQL when current mode has no statement at the cursor", () => {
|
||||
expect(queryEditorSource).toContain("const candidate = executionCandidateForMode(candidates, settingsStore.editorSettings.executeMode)");
|
||||
expect(queryEditorSource).toContain("if (!candidate) return true");
|
||||
it("uses the opt-in blank-line fallback and otherwise reports the missing cursor statement", () => {
|
||||
expect(queryEditorSource).toContain("executeAllOnBlankLine: settingsStore.editorSettings.executeAllOnBlankLine");
|
||||
expect(queryEditorSource).toContain('toast(t("editor.noExecutableStatementAtCursor"), 3000)');
|
||||
expect(queryEditorSource).not.toContain("?? candidates[0]");
|
||||
});
|
||||
|
||||
it("consumes the execution shortcut when the editor has no executable target", () => {
|
||||
expect(queryEditorSource).toContain("if (candidates.length === 0) return true");
|
||||
it("consumes the execution shortcut and reports an empty current target", () => {
|
||||
expect(queryEditorSource).toContain("if (candidates.length === 0)");
|
||||
expect(queryEditorSource).toContain('if (executeMode === "current") toast(t("editor.noExecutableStatementAtCursor"), 3000)');
|
||||
});
|
||||
|
||||
it("preserves the source range when executing a current/all candidate without a manual selection", () => {
|
||||
|
||||
@@ -23,6 +23,13 @@ describe("executionCandidateForMode", () => {
|
||||
expect(executionCandidateForMode([all], "all")).toBe(all);
|
||||
});
|
||||
|
||||
it("falls back to all SQL only when blank-line execution is enabled", () => {
|
||||
const all = candidate("all", ["all"]);
|
||||
|
||||
expect(executionCandidateForMode([all], "current", { executeAllOnBlankLine: false })).toBeNull();
|
||||
expect(executionCandidateForMode([all], "current", { executeAllOnBlankLine: true })).toBe(all);
|
||||
});
|
||||
|
||||
it("uses the deduplicated candidate when one statement is both current and all", () => {
|
||||
const currentAndAll = candidate("all", ["cursor", "all"]);
|
||||
|
||||
|
||||
@@ -1321,6 +1321,7 @@ WHERE t2.product_name = '12345'
|
||||
expect(candidateKinds(candidates)).toEqual(["all"]);
|
||||
expect(candidates[0].supportedKinds).toEqual(["all"]);
|
||||
expect(executionCandidateForMode(candidates, "current")).toBeNull();
|
||||
expect(executionCandidateForMode(candidates, "current", { executeAllOnBlankLine: true })).toBe(candidates[0]);
|
||||
expect(executionCandidateForMode(candidates, "all")).toBe(candidates[0]);
|
||||
});
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ export const EDITOR_SETTINGS_DRAFT_KEYS = [
|
||||
"customThemes",
|
||||
"activeCustomThemeId",
|
||||
"executeMode",
|
||||
"executeAllOnBlankLine",
|
||||
"globalConnectTimeoutSecs",
|
||||
"globalQueryTimeoutSecs",
|
||||
"showExecutionTargetPicker",
|
||||
|
||||
@@ -106,6 +106,7 @@ export const SETTINGS_SEARCH_DEFINITIONS: readonly SettingsSearchDefinition[] =
|
||||
{ id: "editor-theme", category: "editor", titleKey: "settings.theme", targetId: "editor" },
|
||||
{ id: "editor-font-size", category: "editor", titleKey: "settings.fontSize", targetId: "editor" },
|
||||
{ id: "editor-execute-mode", category: "editor", titleKey: "settings.executeMode", targetId: "editor" },
|
||||
{ id: "editor-execute-all-on-blank-line", category: "editor", titleKey: "settings.executeAllOnBlankLine", descriptionKey: "settings.executeAllOnBlankLineDescription", targetId: "editor" },
|
||||
{ id: "editor-global-connect-timeout", category: "editor", titleKey: "settings.globalConnectTimeout", descriptionKey: "settings.globalConnectTimeoutDescription", targetId: "editor" },
|
||||
{ id: "editor-global-query-timeout", category: "editor", titleKey: "settings.globalQueryTimeout", descriptionKey: "settings.globalQueryTimeoutDescription", targetId: "editor" },
|
||||
{ id: "editor-execution-target", category: "editor", titleKey: "settings.showExecutionTargetPicker", descriptionKey: "settings.showExecutionTargetPickerDescription", targetId: "editor" },
|
||||
|
||||
@@ -41,9 +41,11 @@ export function isSqlExecutionSnapshot(value: SqlExecutionOverride | undefined):
|
||||
return typeof value === "object" && value !== null && typeof value.fullSql === "string" && typeof value.selectedSql === "string" && typeof value.cursorPos === "number" && typeof value.selectionFrom === "number" && typeof value.selectionTo === "number";
|
||||
}
|
||||
|
||||
export function executionCandidateForMode(candidates: SqlExecutionCandidate[], mode: ExecuteMode): SqlExecutionCandidate | null {
|
||||
export function executionCandidateForMode(candidates: SqlExecutionCandidate[], mode: ExecuteMode, options: { executeAllOnBlankLine?: boolean } = {}): SqlExecutionCandidate | null {
|
||||
const targetKind: SqlExecutionTargetKind = mode === "current" ? "cursor" : "all";
|
||||
return candidates.find((candidate) => candidate.supportedKinds.includes(targetKind)) ?? null;
|
||||
const candidate = candidates.find((item) => item.supportedKinds.includes(targetKind));
|
||||
if (candidate || mode !== "current" || !options.executeAllOnBlankLine) return candidate ?? null;
|
||||
return candidates.find((item) => item.supportedKinds.includes("all")) ?? null;
|
||||
}
|
||||
|
||||
export function resolveExecutableSql(fullSql: string, selectedSql: string, options?: { mode?: ExecuteMode; cursorPos?: number }): string {
|
||||
|
||||
Reference in new issue
Block a user