Repository navigation
Conversation
Cythia828
force-pushed
the
feat/support_CTE_entity
branch
from
October 8, 2026 02:45
8f72ba4 to
3e367c3
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
功能
playground 补全新增 CTE 名称(
WITH ... AS)与脚本内CREATE TABLE建表名的建议,并修复语法错误场景下把整段子句当成补全项、以及同名表/列重复出现的问题。同时带上 1.2.1 发布元信息、dt-sql-parser升级与仓库指引AGENTS.md。分支:
feat/support_CTE_entity→next(3 个提交,基线4b9461f)预览地址
https://cythia828.github.io/monaco-sql-languages/
变更描述
一、playground 补全支持 CTE 实体与脚本建表
主要改动集中在
website/src/languages/helpers/completionService.ts。解决的问题
WITH定义的 CTE 在实体模型中表现为TABLE+declareType = EXPRESSION,而原有逻辑只收集TABLE_CREATE(脚本建表)实体,因此WITH t AS (...) SELECT * FROM |的补全列表里看不到t。getSpecificDerivedTableColumns仅在传入displayAlias时才匹配实体(displayAlias ? ... : false),FROM myCte这类无别名引用直接返回空,派生表列补全缺失。FROM后接JOIN myOwn会得到表实体文本JOIN myOwn\nORDER BY 1,并被直接当作补全 label 展示。FROM orders JOIN t1 ON中orders、t1各出现两次);CTE 的定义实体与引用实体共享同一份对外列,逐条map会产出重复列项。实现方案
(1)新增
isEntityName名称合法性校验要求实体文本"长得像标识符"才允许成为补全项:
`my table`)整体视为不透明,直接通过——parseEntityText对内容不是裸标识符的反引号标识符会保留反引号,因此必须保持有效;.切分,每段均需匹配/^[A-Za-z0-9_$]+$/。在
getSpecificTableColumns、getSpecificDerivedTableColumns、getSpecificCTASTableColumns、sourceTables表项与CREATE TABLE表项处统一接入,从源头过滤脏实体。(2)新增
getCteTableCompletions遍历
isAccessible且declareType === EXPRESSION的TABLE实体收集可见 CTE 名称,按小写去重(定义与引用共享text,只保留一个),输出detail: 'derived table'的补全项。(3)
getSpecificDerivedTableColumns支持无别名引用新增第三个参数
tableText:有displayAlias时按别名匹配;否则按tb.text === tableText或getPureEntityText相等匹配。命中后只取matched[0]——CTE 定义实体与引用实体共享同一份对外列,取首条即可避免列项重复。表名解析顺序为displayAlias || getPureEntityText(tableText) || alias || getPureEntityText(tb.text),同样经过isEntityName。(4)触发时机与去重
syntaxContextType为TABLE或COLUMN、words.length <= 1时注入,覆盖未完成的FROM/JOIN/ON位置;TABLE放宽为TABLE || COLUMN,使JOIN t ON |这类连接条件也能看到表名;sourceTableLabels(可访问源表标签,小写)集合,脚本建表项与之同名时跳过;sourceTables侧改用flatMap+seenTableLabels去重,并跳过无别名的EXPRESSION实体(其名称已由 CTE 建议统一提供,避免重复)。(5)列名刻意不做
isEntityName校验无别名的列通常是表达式(
UPPER(name)、amount * 2),作为 label 仍然可用,因此三处列处理分支保留原逻辑并补充注释说明。二、
chore(release): 1.2.1CHANGELOG.md补充 1.2.1 条目:formatSQL API(格式化功能标准化 #206)、SQL run([Feat]: built-in support for running SQL in segments #222)、dt-sql-parser升级、优化建议 #165 注释相关修复;package.json版本1.2.1-beta.2→1.2.1;deploy脚本远端由git@github.com:...改为https://github.com/...,避免无 SSH key 的环境部署失败。三、
feat: add agent guidelines新增
AGENTS.md(206 行),面向在本仓库工作的 agent 的指引:目录布局、常用命令与"完成标准"(改动类型 → 需要跑的校验)、双 worker 流水线架构、各方言接线方式与新增方言步骤、playground 的三个集成点、format 入口的注册机制、约定与测试框架限制(test/all.js不支持子集运行)等。四、依赖与版本
dt-sql-parser4.5.1→4.5.2-beta.0(CTE 实体信息由解析器侧提供),pnpm-lock.yaml同步更新;package.json版本1.2.1→1.2.2-beta.0。变更文件
website/src/languages/helpers/completionService.tsisEntityName校验、去重(+185 / -67)AGENTS.mdCHANGELOG.mdpackage.jsondt-sql-parser依赖、deploy远端pnpm-lock.yaml验证方式
website/目录下没有测试用例,该改动只能手工验证:pnpm build(或保持pnpm watch-esm运行);cd website && pnpm install && pnpm dev;WITH t AS (SELECT ...) SELECT * FROM |能看到 CTE 名称t;FROM myCte(无别名)能补全出该 CTE 的列;CREATE TABLE后,后续语句能补全出该表名;FROM orders JOIN t1 ON |中表名不重复出现;FROM后直接接JOIN)时,补全列表不出现JOIN ... ORDER BY ...这类整段子句文本。已执行
prettier --check(覆盖 CI 的check任务),结果:All matched files use Prettier code style!。website/不在根pnpm build/pnpm test覆盖范围内,未跑其他校验。