fix(completion): show derived table columns
This commit is contained in:
3 files changed
+35
No files matched your search
@@ -4940,6 +4940,13 @@ function buildLocalSqlCompletionResult(completionContext: ReturnType<typeof getS
|
||||
|
||||
const cteDefs = extractCteDefinitions(fullDoc);
|
||||
for (const refTable of completionContext.referencedTables) {
|
||||
if (refTable.columns?.length) {
|
||||
columnsByTable.set(
|
||||
refTable.name,
|
||||
refTable.columns.map((name) => ({ name, table: refTable.name, schema: refTable.schema })),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (isVirtualCompletionTableReference(refTable)) continue;
|
||||
const cteDef = cteDefs.find((c) => c.name.toLowerCase() === refTable.name.toLowerCase());
|
||||
if (cteDef) {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
const queryEditorSource = readFileSync(new URL("../../../components/editor/QueryEditor.vue", import.meta.url), "utf8");
|
||||
|
||||
it("maps inline projected columns into local completion results", () => {
|
||||
expect(queryEditorSource).toMatch(/if \(refTable\.columns\?\.length\) \{[\s\S]*?columnsByTable\.set\([\s\S]*?refTable\.columns\.map/);
|
||||
});
|
||||
@@ -441,6 +441,26 @@ WHERE a.id = b.fk_kpi_set_score_id`,
|
||||
expect(items.filter((item) => item.type === "column").map((item) => item.label)).toEqual(["id", "user_name"]);
|
||||
});
|
||||
|
||||
it("keeps projected aliases from a multiline derived table", () => {
|
||||
const { items } = semanticCompletion(
|
||||
`SELECT
|
||||
t.DEPTNO,
|
||||
t.|
|
||||
FROM (
|
||||
SELECT
|
||||
DEPTNO,
|
||||
AVG(SAL) avg_sal,
|
||||
RANK() OVER (ORDER BY AVG(SAL) DESC) AS rnk
|
||||
FROM emp
|
||||
GROUP BY DEPTNO
|
||||
) AS t`,
|
||||
{},
|
||||
{ databaseType: "mysql", dialect: "mysql" },
|
||||
);
|
||||
|
||||
expect(items.filter((item) => item.type === "column").map((item) => item.label)).toEqual(["DEPTNO", "avg_sal", "rnk"]);
|
||||
});
|
||||
|
||||
it("expands alias star from only the qualified row source", () => {
|
||||
const columnsByTable = new Map<string, SqlCompletionColumn[]>([
|
||||
["users", ["id", "name"].map((name) => ({ name, table: "users" }))],
|
||||
|
||||
Reference in new issue
Block a user