Skip to content

feat: #184 support continuous SQL completion - #232

Merged
Cythia828 merged 1 commit into
DTStack:nextfrom
jin-sir:feat/continuous-sql-completion
Oct 30, 2026
Merged

Cythia828 merged 1 commit into
DTStack:nextfrom
jin-sir:feat/continuous-sql-completion

Conversation

@jin-sir

@jin-sir jin-sir commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

issue

#184

功能

支持 SQL 连续补全,提升 SQL 编写效率。

预览地址

暂无

变更描述

提供 continuousCompletion 配置参数,默认关闭;

将 continuousCompletion 设置为 true 可以开启连续补全:当选中一个补全项后,只要插入行为把光标带入了新的语法上下文,就会自动再次触发建议框,从而无需再次输入即可展示下一组建议。具体来说:

  • 未显式设置 insertText 的关键字补全项会带一个尾随空格插入(如 SELECT ),从而立即给出下一组建议(列名、* 等);
  • 当解析器报告当前位置处于 function 语法上下文时,关键字补全项会按原样插入(不带尾随空格),且不会再次触发建议框,方便用户自行输入函数括号;
  • insertText 以触发字符结尾的补全项会再次触发补全——例如自定义 completionService 可以让数据库项以 insertText: 'my_database.' 插入,这样选中数据库名后会立即提示该库下的表;
  • 自定义了 command 的补全项不会被修改;普通的实体项(表、列等)不会再次触发,因为接受它们并没有改变补全上下文。

@Cythia828
Cythia828 requested a review from liuxy0551 October 28, 2026 06:16
Comment thread src/languageFeatures.ts
}

const isKeyword = item.kind === languages.CompletionItemKind.Keyword;
const isParenFunction = item.insertText === undefined && isKeyword && hasFunctionContext;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里用 hasFunctionContext 判定具体补全项存在作用域混淆的问题。

hasFunctionContext 代表的是“当前光标位置语法上是否允许出现函数”。在 SQL 中,几乎所有核心表达式位置(如 SELECT | 投影列、WHERE | 条件、ON | 连接条件等)都允许函数调用,因此该标志在这些位置恒为 true。

如果直接用 item.insertText === undefined && isKeyword && hasFunctionContext 判定,会导致在上述位置,所有普通关键字(例如 DISTINCT、CASE、AND、OR 等)都被判定为 isParenFunction = true,从而全部丢失了尾随空格。

更严重的是,下方的 advancesContext 依然判定 (item.insertText === undefined && isKeyword) 为 true 并挂载了 retriggerSuggestCommand,导致用户选中 DISTINCT 后插入无空格裸词并立即在原地重新触发建议框,建议框过滤出 DISTINCT 再次弹窗,导致无法通过回车/Tab 结束补全,陷入死循环。

建议:

  1. 区分真正的函数项与普通关键字(不能仅凭光标位置语法上下文)。若为函数关键字,应转换为带参片段(如 ${name}($1))并标记为 snippet;
  2. 对于不带空格和括号的裸词,advancesContext 绝不能挂载 retriggerSuggestCommand,避免原地重复触发。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个后续配合dt-sql-parser提取Function后再做

Comment thread src/languageFeatures.ts Resolved
Comment thread src/test/completionAdapter.test.ts Resolved
Comment thread src/languageFeatures.ts Resolved
@jin-sir
jin-sir force-pushed the feat/continuous-sql-completion branch from cdce715 to 50fbb40 Compare October 29, 2026 09:30
@Cythia828
Cythia828 changed the base branch from main to next October 29, 2026 09:48
@Cythia828
Cythia828 merged commit c21657e into DTStack:next Oct 30, 2026
6 checks passed
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.

3 participants