feat(editor): 支持 SELECT * 展开为字段列表

* ✨ feat(editor): 支持将 SELECT * 展开为字段列表

- 新增右键菜单及 `Mod+Shift+X` 快捷键,可展开 `*` 和 `别名.*`
- 基于语义分析识别单表来源、别名及原始引用符,并按数据库方言处理字段名转义
- 优先读取本地或远程表字段元数据,单表纯星号查询可回退使用执行结果字段
- 增加字段加载失败提示及多语言文案
- 补充星号展开、结果匹配和快捷键注册测试

* fix(editor): selectStar 回退加词边界检查并记录加载失败

---------

Co-authored-by: t8y2 <t8y2@users.noreply.github.com>
Co-authored-by: skyler <1156263951@qq.com>
This commit is contained in:
authored and GitHub committed 2026-08-06 00:55:36 +08:00
1 parent fa6540b739
commit 5c281b1653
18 files changed
+473 -17

No files matched your search

+41 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { sqlSemanticCompletionScope, sqlSemanticLocalColumnsByTable, sqlSemanticProjectionAliasColumns } from "@/lib/sql/semantic/completion";
import { sqlSemanticCompletionScope, sqlSemanticLocalColumnsByTable, sqlSemanticProjectionAliasColumns, sqlSemanticSelectStarIsOnlyProjection, sqlSemanticSelectStarQualifierSql, sqlSemanticSelectStarTableSource } from "@/lib/sql/semantic/completion";
import { SQL_SEMANTIC_BASELINE_FIXTURES, sqlFixtureCursor } from "@/lib/sql/semantic/fixtures";
import { buildSqlSemanticModel, sqlSemanticTableNameSpans } from "@/lib/sql/semantic/model";
@@ -29,6 +29,46 @@ describe("sqlSemanticModel baseline fixtures", () => {
});
}
it("does not treat SELECT as the qualifier of an unqualified star", () => {
const { sql, cursor } = sqlFixtureCursor("select *| from apis as ap");
const model = buildSqlSemanticModel(sql, cursor);
expect(model.cursorIntent).toEqual(expect.objectContaining({ kind: "star", qualifierParts: [] }));
});
it("retains the qualifier of a qualified star", () => {
const { sql, cursor } = sqlFixtureCursor("select ap.*| from apis as ap");
const model = buildSqlSemanticModel(sql, cursor);
expect(model.cursorIntent).toEqual(expect.objectContaining({ kind: "star", qualifierParts: ["ap"], targetSourceId: model.rowSources[0]?.id }));
});
it("does not resolve an unqualified star to the only physical table among multiple row sources", () => {
const { sql, cursor } = sqlFixtureCursor("select *| from users u join (select 1 as x) s on 1 = 1");
const model = buildSqlSemanticModel(sql, cursor);
expect(model.rowSources.map((source) => source.kind)).toEqual(["table", "subquery"]);
expect(sqlSemanticSelectStarTableSource(model)).toBeUndefined();
});
it.each([
["select *| from apis", true],
["select distinct *| from apis", true],
["select ap.*| from apis ap", true],
["select *, 1 as extra| from apis", false],
["select ap.*, 1 as extra| from apis ap", false],
] as const)("detects whether the star is the only projection in %s", (markedSql, expected) => {
const { sql, cursor } = sqlFixtureCursor(markedSql);
expect(sqlSemanticSelectStarIsOnlyProjection(buildSqlSemanticModel(sql, cursor))).toBe(expected);
});
it("retains the original quoting of a star qualifier", () => {
const { sql, cursor } = sqlFixtureCursor('select "Order Alias".*| from orders as "Order Alias"');
expect(sqlSemanticSelectStarQualifierSql(buildSqlSemanticModel(sql, cursor, { databaseType: "postgres", dialect: "postgres" }))).toBe('"Order Alias"');
});
it("does not mix row sources from inactive statements", () => {
const { sql, cursor } = sqlFixtureCursor("select * from users u; select * from orders o where o.|");
const model = buildSqlSemanticModel(sql, cursor);