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.
主要变更
commentOtherLine
方法,(只包括在单行中补全的单测)关于优化自动补全
为什么要寻找最小的合适范围?
在sql文本量很大的时候,antlr4-c3 会表现出严重的性能问题,此前的测试中发现sql 内容 5000 行时,antlr4-c3 需要大概30秒才能收集完成,这太慢了。所以需要找到一个最小的合适的范围,在这个范围内做自动补全以保证性能稳定。
如何寻找最小的合适范围?
对于左边界,为什么需要它的上一句也是一个不包含解析异常的语句(右边界同理)
因为可能会出现一条独立语句可以由多条独立语句组成的情况,比如
在寻找这个最小范围时,相当重要的一个基本准则是:需要保证按这个范围切割后的文本片段交给c3 去收集的结果,与完整文本交给c3去收集的结果相同。
基于这个基本准则,在寻找这个范围时需要特别小心,左边界向前看一句和右边界向后看一句,都能尽量减少误差。
值得强调的是,即使这样做了也不能完全保证遵守了上述基本准则,因为不同的sql的语法存在差异,另外在某些情况下,如果文本中包含了语法错误,Antlr4 在错误位置将会以一种怪异的方式生成语法树。
在理论上也无法绝对保证遵守上述基本准则,是因为这实际上是在用普通的js逻辑去试图理解哪些解析树节点属于同一个语句。在自动补全方法内部的对应策略只能尽量取得平衡(性能和准确性之前的平衡), 好消息是目前看起来一切运行良好。
关于多行sql自动补全的单元测试
多行情况下,自动补全的情况分为三种: