Improve completion suggestions inside backticks#1581
Improve completion suggestions inside backticks#1581rolandwalker wants to merge 1 commit intomainfrom
Conversation
|
Findings
Missing tests / edge cases
Notes
Suggestions
|
ca874de to
f12b8f2
Compare
Mostly correct, addressed.
Added as an |
|
Findings (focus: correctness/regressions, security, missing tests)
Missing tests / edge cases
No security concerns found. If you want, I can propose the exact signature change and test case. |
Previously the behavior was a little janky: on the first character after a backtick, only identifiers which might _require_ a backtick were offered as suggestions (because, for instance, they matched reserved words). Sometimes, that list would be empty, and no suggestions were offered. Then, after typing a few more characters, rapidfuzz matching kicked in, and more suggestions were offered, with backticks off for the additional rapidfuzz suggestions. Now the behavior is more consistent: if a backtick is typed, _all_ suggestions which could work in that place are offered, with uniform backticks on the suggestions, even if backticks are not required for the given identifier. Of course, how early the suggestions are offered is still dependent on the min_completion_trigger option in ~/.myclirc, so the above paragraph is conditional. Changes * tuck optimization check inside _find_doubled_backticks(), and make the optimization test for double instead of single backticks * remove function unescape_name(), which is unused, and seems wrongly named since it oriented towards strings rather than identifiers * let find_matches() add backticks to all suggestions if backtick quoting is detected at the cursor * recast a variable name in _find_doubled_backticks() Per some comments in the tests, it would be nicer if column names sorted more strongly to the top in the SELECT context, but that is not new to these changes. Another idea could be sorting to the top only those suggestions which require a backtick, when in the backtick context -- something for the future. We also seem to be needlessly suggesting some generic keywords in the SELECT context, but that is also not new to these changes. And if they are going to appear, it seems to make more sense to have them in backticks like the other suggestions, for the sake of uniformity.
f12b8f2 to
048a2f8
Compare
|
Findings (Correctness)
Missing tests / edge cases
If you want, I can propose a small patch to gate the backtick wrapping to identifier‑like items only. |
|
This one is a bit complex, and my gut says to scale back the suggestions. You can't run most things surrounded by backticks, so suggesting most keywords and what not often does not make sense. I.e. From a user perspective, it seems like it would make more sense to only ever suggest object type items when suggesting inside backticks; databases, tables, columns, procedures, functions. If a user is wanting a reserved word/keyword to show up inside backticks, it means they're using it as a database/table/column name most likely anyway, and would be covered by only suggesting those objects to begin with. |
I think this is explained in the description pretty well. We are completing too many keywords, but it isn't new to this bugfix, nor particular to backticks at all. Future work could include:
but it is highly preferable to do those things in separate PRs. The cause of exuberantly offering inappropriate keywords as completions could be #1447 . We might need to do better (manual) separation of functions vs other keywords. In addition, the
|


Description
Previously the behavior was a little janky: on the first character after a backtick, only identifiers which might require a backtick were offered as suggestions (because, for instance, they matched reserved words). Sometimes, that list would be empty, and no suggestions were offered. Then, after typing a few more characters, rapidfuzz matching kicked in, and more suggestions were offered, with backticks off for the additional rapidfuzz suggestions.
Now the behavior is more consistent: if a backtick is typed, all suggestions which could work in that place are offered, with uniform backticks on the suggestions, even if backticks are not required for the given identifier.
Of course, how early the suggestions are offered is still dependent on the
min_completion_triggeroption in~/.myclirc, so precise behavior in the above paragraph is conditional on having the default settings.This PR still struggles on the case of spaces within the backtick, which I'd like to leave for future work, and an
xfailtest is included to represent the todo.Fixes #1564 .
Changes
_find_doubled_backticks(), and make the optimization test for double instead of single backticks.unescape_name(), which is unused, and seems wrongly named since it oriented towards strings rather than identifiers.find_matches() add backticks to all suggestions if backtick quoting is detected at the cursor._find_doubled_backticks().Per some comments in the tests, it would be nicer if column names sorted more strongly to the top in the
SELECTcontext, but that is not new to these changes.Another idea could be sorting to the top only those suggestions which require a backtick, when in the backtick context -- something for the future.
We also seem to be needlessly suggesting some generic keywords in the
SELECTcontext, but that is also not new to these changes. And if they are going to appear, it seems to make more sense to have them in backticks like the other suggestions, for the sake of uniformity.Example of the new behavior:

Checklist
changelog.mdfile.AUTHORSfile (or it's already there).