Refactor completion suggestions engine to use declarative rules#1761
Refactor completion suggestions engine to use declarative rules#1761rolandwalker wants to merge 4 commits intomainfrom
Conversation
132f539 to
4427504
Compare
Validation note: I couldn’t run the suite in this environment because |
4427504 to
9accb87
Compare
Codex Review:
No security issues stood out in this PR. I couldn’t run tests in this environment because |
9accb87 to
abdf19b
Compare
Codex ReviewNo blocking findings in the PR diff ( I checked the refactor in completion_engine.py against the prior branch logic and didn’t find behavior regressions in rule ordering or fallback semantics; the declarative rules preserve the old branches. Residual risk / test gap:
|
in preparation for a refactor
breaking up suggest_based_on_last_token() into many small functions. This is not perfect, as some functions such as _emit_lparen() remain large, and others such as suggest_special() are untouched. The rules are still ordered as a list, which could be finicky for future changes. An alternative is including a priority rank in the SuggestRule dataclass. A risk is that the declarative rules make ample use of lambdas, which might impose a performance penalty. Motivation: making the rules easier to understand and modify, and making rules easier to migrate to sqlglot, which may be more reliable and performant. Further work could include turning the return values from the _emit functions into a list of Suggestion instances, instead of using dicts. It could also be nice to migrate the rules in SUGGEST_BASED_ON_LAST_TOKEN_RULES into a separate file completion_rules.py, in which perhaps all rules are not based on the last token.
adding some todo comments in completion_engine.py, related to tests which are xfailed here.
so that guards such as "is inside string" can run without full parsing, for performance.
823ea55 to
bd6183c
Compare
Description
Refactor completion suggestions engine to use declarative rules, breaking up
suggest_based_on_last_token()into many small functions.This is not perfect, as some functions such as
_emit_lparen()remain large, and others such assuggest_special()are untouched. The rules are still ordered as a list, which could be finicky for future changes. An alternative is including a priority rank in theSuggestRuledataclass.A risk is that the declarative rules make ample use of lambdas, which might impose a performance penalty.
Motivation: making the rules easier to understand and modify, and making rules easier to migrate to sqlglot, which may be more reliable and performant.
Further work could include turning the return values from the
_emitfunctions into a list ofSuggestioninstances, instead of using dicts. It could also be nice to migrate the rules inSUGGEST_BASED_ON_LAST_TOKEN_RULESinto a separate filecompletion_rules.py, in which perhaps all rules are not based on the last token.The PR consists of four commits, which may make it easier to review
Checklist
changelog.mdfile.AUTHORSfile (or it's already there).