fix(editor): complete MySQL table names after DESC

Closes #6668
This commit is contained in:
t8y2 committed 2026-08-19 12:41:29 +00:00
1 parent 7a707e77d8
commit 4e74f77cc8
2 files changed
+47 -2

No files matched your search

@@ -1,5 +1,14 @@
import { describe, expect, it } from "vitest";
import { buildPostgresSequenceLiteralCompletionItems, buildSelectStarExpansion, buildSqlCompletionItems, getPostgresSequenceLiteralCompletionContext, getSqlCompletionContext, selectStarResultColumnsMatch, shouldAutoOpenSqlCompletion } from "@/lib/sql/sqlCompletion";
import {
buildPostgresSequenceLiteralCompletionItems,
buildSelectStarExpansion,
buildSqlCompletionItems,
buildSqlCompletionItemsFromContext,
getPostgresSequenceLiteralCompletionContext,
getSqlCompletionContext,
selectStarResultColumnsMatch,
shouldAutoOpenSqlCompletion,
} from "@/lib/sql/sqlCompletion";
import { sqlCompletionContextFromSemantic } from "@/lib/sql/semantic/completion";
import { buildSqlSemanticModel } from "@/lib/sql/semantic/model";
import { originForSqlCompletionProvider, originForTypedSqlCompletionStart, shouldAllowSqlCompletionTrigger, type SqlCompletionTriggerFacts } from "@/lib/sql/sqlCompletionTriggerPolicy";
@@ -17,6 +26,38 @@ describe("sqlCompletion keyword snippets", () => {
});
});
describe("MySQL DESCRIBE table completion", () => {
it.each(["DESC", "DESCRIBE"])("treats %s as a table-name context", (keyword) => {
const sql = `${keyword} ord`;
const options = { databaseType: "mysql", dialect: "mysql" } as const;
const context = sqlCompletionContextFromSemantic(buildSqlSemanticModel(sql, sql.length, options), getSqlCompletionContext(sql, sql.length, options));
expect(context.suggestTables).toBe(true);
expect(shouldAutoOpenSqlCompletion(sql, sql.length, options)).toBe(true);
expect(
buildSqlCompletionItemsFromContext(context, {
tables: [{ name: "orders" }],
columnsByTable: new Map(),
...options,
}),
).toEqual(expect.arrayContaining([expect.objectContaining({ label: "orders", type: "table" })]));
});
it("does not treat PostgreSQL ORDER BY DESC as a table-name context", () => {
const sql = "SELECT * FROM users ORDER BY name DESC ord";
const options = { databaseType: "postgres", dialect: "postgres" } as const;
const context = sqlCompletionContextFromSemantic(buildSqlSemanticModel(sql, sql.length, options), getSqlCompletionContext(sql, sql.length, options));
expect(context.suggestTables).toBe(false);
expect(
buildSqlCompletionItemsFromContext(context, {
tables: [{ name: "orders" }],
columnsByTable: new Map(),
...options,
}).some((item) => item.type === "table"),
).toBe(false);
});
});
describe("PostgreSQL sequence literal completion", () => {
it.each(["nextval", "currval", "setval"])("recognizes the first %s regclass literal", (functionName) => {
const sql = `SELECT ${functionName}('public.order_`;