Skip to content

fix: #436 improve SQL keyword suggestions - #485

Open
liuxy0551 wants to merge 1 commit into
DTStack:nextfrom
liuxy0551:fix_436
Open

fix: #436 improve SQL keyword suggestions#485
liuxy0551 wants to merge 1 commit into
DTStack:nextfrom
liuxy0551:fix_436

Conversation

@liuxy0551

@liuxy0551 liuxy0551 commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

本次改动

Fixes #436 优化光标位置的 SQL 关键字补全:

  • 默认只保留当前 SQL 语句的关键字候选
  • 避免未结束语句后出现 SELECT 等下一语句起始关键字
  • 保留当前语句合法的续写关键字和组合关键字
  • 新增可选的 keywordFilter 回调,支持调用方自定义过滤
  • 关键字过滤不影响语法补全结果

API 使用方式

const excludedKeywords = new Set(['WHERE', 'ORDER BY']);

const suggestions = parser.getSuggestionAtCaretPosition(sql, position, {
    keywordFilter: (keyword) => !excludedKeywords.has(keyword),
});

keywordFilter 针对最终生成的关键字执行:

  • 返回 true:保留关键字
  • 返回 false:移除关键字

效果展示

https://liuxy0551.github.io/monaco-sql-languages/

当前语句关键字补全

image

补全列表只包含当前查询合法的续写关键字,不再出现 SELECT 等下一语句起始关键字。

输入部分关键字后的补全

image

输入 s 后,只展示 SORTSORT BY 等符合当前位置的候选项。

测试

  • 覆盖 MySQL、FlinkSQL、SparkSQL、HiveSQL、PostgreSQL、TrinoSQL、ImpalaSQL、GenericSQL
  • 覆盖无分号、分号后、多语句和未完成单词等场景
  • 覆盖黑名单、白名单和组合关键字过滤
  • 验证过滤逻辑不影响语法补全
  • 全量测试及 TypeScript 类型检查通过

@liuxy0551
liuxy0551 requested a review from Cythia828 July 28, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant