Repository navigation
fix: do not offer SQL completions after the statement terminator - #1756
Open
shivampwm2020 wants to merge 1 commit into
Open
shivampwm2020 wants to merge 1 commit into
shivampwm2020 wants to merge 1 commit into
Conversation
The trailing ';' of a statement is annotated as sql_garbage and the SQL completion trigger in rl_sql_change() did not exclude that annotation. Once the schema is known, typing the same statement a second time leaves a completion popup open on the terminator, so Enter accepts the suggestion instead of executing the query. Skip completion when the attribute under the cursor is sql_garbage. Fixes tstack#1751
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Fixes #1751.
In SQL mode, running a statement and then typing the same statement again
leaves a completion popup open on the trailing
;. Pressing Enter then acceptsthe suggestion instead of executing the query, corrupting the input:
Root cause
annotate_sql_statement()tokenizes the line and has no rule for;, so itfalls through to the catch-all
(\A.)pattern and tags the terminator withSQL_GARBAGE_ATTR. The SQL completion trigger inrl_sql_change()(
src/readline_callbacks.cc) then looks up the attribute under the cursor andonly suppressed completion for
SQL_NUMBER_ATTR/SQL_HEX_LIT_ATTR:That explains the "first time works, second time breaks" behaviour:
empty and
open_popup_for_completion()returns without showing anything(it bails when
possibilities.empty()). Enter falls through toon_perform()and the query executes.similar_to(";", 10)now yields candidates. The popup opens, andNCKEY_ENTERintextinput_cursestakes the "accept completion" branchwhenever
tc_popup.is_visible(), so Enter never reacheson_perform().The terminator is a token boundary with nothing to complete, so the garbage
annotation is the right thing to skip.
Fix
Skip completion when the attribute under the cursor is
SQL_GARBAGE_ATTR:The parenthesisation matters — a bare
a && b || c || dbinds as(a && b) || c || dand leaves the bug in place. I verified that failure modeexplicitly (see Testing).
The guard applies to explicit requests too: the
;has no completions worthoffering, so no popup is shown there in any mode.
The annotator itself is left alone —
;→sql_garbageis existing, testedbehaviour (see the
sql_garbageentries intest/expected/test_sql_anno.sh_*)that
sql.formatter.ccandcmd.parser.ccalso rely on.Testing
Honest note on build/test coverage: I could not complete a full lnav build
or run the ctest suite in my environment — it lacks root access and the
required development headers (
libarchive-dev,libsqlite3-dev,libpcre2-dev,libcurl4-*-dev,notcurses, vendored submodules), socmakefails atfind_package/#include <pcre2.h>/notcurses/notcurses.h.The verification below is what I could actually run; the golden-file test case
I added has not been executed.
What I did verify:
to the original, so no structural damage was introduced.
translation unit (
g++ -std=c++20 -Wall -Wextra, no lnav deps) and assertedthe truth table. All assertions pass. Coverage:
sql_garbageat thecursor no longer completes in any mode; identifiers/keywords still
complete; the pre-existing number/hex-literal suppression is unchanged.
writing it as
a && b || c || dalso fails the harness — confirming boththe bug and the need for the explicit grouping.
masterreports
ahead_by: 1,behind_by: 0, two files changed (11 + 5 lines),and the patch content matches the intended edit.
Added to
test/test_sql_anno.sh:This pins the annotation the fix depends on (
;must staysql_garbage).Note that
run_cap_testhashes the assertion into the expected-file name, sothe corresponding
test/expected/golden files need to be generated byrunning the suite — I have not generated or committed them, since that
requires the build above. Maintainers will need to run the suite (or tell me
and I'll add the golden files) before this case can pass.
Signed-off-by: Shivam Maurya shivam@programmingwithmaurya.com