fix: #478 column completion and incomplete SELECT validate#479
Open
Cythia828 wants to merge 1 commit into
Open
fix: #478 column completion and incomplete SELECT validate#479Cythia828 wants to merge 1 commit into
Cythia828 wants to merge 1 commit into
Conversation
Collaborator
Author
|
@liuxy0551 @mumiao 客户需求中涉及到这块内容,有空可尽快review |
liuxy0551
reviewed
Jun 12, 2026
| candidateRule.ruleList.includes(MySqlParser.RULE_fromClause) || | ||
| candidateRule.ruleList.includes(MySqlParser.RULE_orderByExpression) || | ||
| candidateRule.ruleList.includes(MySqlParser.RULE_groupByItem) || | ||
| candidateRule.ruleList.includes(MySqlParser.RULE_havingClause) |
Collaborator
There was a problem hiding this comment.
这个 if 的判断条件写法可以优化下,将使用到的规则统一管理
const ALLOW_EMPTY_COLUMN_PARENT_RULES = new Set([
MySqlParser.RULE_joinSpec,
MySqlParser.RULE_fromClause,
MySqlParser.RULE_orderByExpression,
MySqlParser.RULE_groupByItem,
MySqlParser.RULE_havingClause,
]);
if (candidateRule.ruleList.some((rule) => ALLOW_EMPTY_COLUMN_PARENT_RULES.has(rule))) {
syntaxContextType = EntityContextType.COLUMN;
}
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.
相关issue
解决问题
解决了上面两个issue中描述的问题:
1、
mysql、pgsql、trinoJOIN...ON...关联语法后面无法提示字段列表2、
mysqlSELECT age from orders WHERE age GROUP BY ORDER BY语句中ORDER BY和GROUP BY后面无法提示字段3、
pgsql在SELECT FROM a这种情况下无法正常抛错以上为客户需求中明确描述需要的功能
变更描述
Mysql变更1 —
JOIN ON空列路径columnNamePath新增 # columnNamePath_dot_empty:uid DOT emptyColumn,配合 shouldMatchEmpty() 仅在补全/实体收集模式匹配columnNamePathAllowEmpty重构:先走 columnNamePath,再走裸 emptyColumnjoinSpec已有columnNamePathAllowEmpty,配合上述规则支持ON o.变更 2 — ORDER BY / GROUP BY / HAVING 补全
orderByExpression、groupByItem、havingClause均增加 |columnNamePathAllowEmpty分支(与fromClause中 WHERE 的处理对称)变更 3 — 补全候选映射(mysql/index.ts)
preferredRules加入RULE_columnNamePathAllowEmptyprocessCandidates白名单:仅在 joinSpec / fromClause / orderByExpression / groupByItem / havingClause 上下文将候选识别为 COLUMN变更 4 — 实体收集(mysqlEntityCollector.ts)
新增 exitColumnNamePath_dot_empty,在 o. 空列位置 push COLUMN 实体
PGSQL变更 1 — JOIN ON 空列路径
columnNamePath新增 #columnNamePath_dot_empty(同 MySQL 思路)postgreEntityCollector增加exitColumnNamePath_dot_emptypostgresql/index.ts在columnNamePath的ruleList白名单中加入RULE_joinQual变更 2 — 不完整 SELECT 飘红(核心 validate 修复)
sqlExpression:targetList?→targetList必填targetList 允许空清单的条件(语义谓词):
isFollowedByInto():下一 token 为 INTO → 支持 SELECT DISTINCT ON (...) INTO ... FROM ...isFollowedByEnd():下一 token 为 ; 或 EOF → 支持合法 SELECT;、SELECT INTO new_table;下一 token 为 FROM 时两个谓词均为 false → 必须有 targetEl → SELECT FROM ... 仍报错
使用 PostgreSqlParser.KW_INTO / SEMI 静态常量(非 this.KW_INTO,避免 antlr4ng 实例上为 undefined)
Trino变更 1 —
JOIN ON专用解析路径新增
joinColumnEquality / joinColumnReference规则,支持 ON o. = u.joinColumnReference:identifier DOT emptyColumn(仅 entityCollecting 时)或 columnName变更 2 — 实体收集 vs validate 分流
joinCriteria:KW_ON (joinColumnEquality | {notEntityCollecting()}? booleanExpression)joinColumnEquality,解析不完整 ONbooleanExpression,不完整 ON 仍报错变更 3 — 补全与 bugfix(trino/index.ts)
RULE_columnName白名单增加RULE_joinCriteria补上缺失的 break,避免 case fall-through
预览地址
https://cythia828.github.io/monaco-sql-languages/
测试SQL
create table orders ( id BIGINT, age int, name VARCHAR ); create table t1 ( id1 BIGINT, age1 int, name1 VARCHAR ); SELECT o.age, u.age1 FROM orders o JOIN t1 u ON o. = u.;create table orders ( id BIGINT, age int, name VARCHAR ); create table t1 ( id1 BIGINT, age1 int, name1 VARCHAR ); SELECT age FROM orders o where order by group by