Skip to content

Comments

feat(fuzzy-finder): statement name + argument completion framework#507

Merged
apstndb merged 5 commits intomainfrom
feat/fuzzy-finder
Feb 22, 2026
Merged

feat(fuzzy-finder): statement name + argument completion framework#507
apstndb merged 5 commits intomainfrom
feat/fuzzy-finder

Conversation

@apstndb
Copy link
Owner

@apstndb apstndb commented Feb 22, 2026

Summary

  • Unify fuzzy completion with clientSideStatementDef — both statement names and arguments completable from a single source of truth
  • Add Completion field to clientSideStatementDef, eliminating parallel maintenance of separate regexes in fuzzy_finder.go
  • Add statement name completion as fallback when input doesn't match any completable argument
  • Add table name completion via INFORMATION_SCHEMA.TABLES
  • Show loading indicator with 10s timeout for network-dependent completions
  • Use cursor position (not full buffer) for context detection

Two completion modes in one Ctrl+T press

  1. Argument completion (priority): if input matches a statement with a Completion entry, complete the argument
  2. Statement name completion (fallback): show all ~40 client-side statement syntaxes as fzf candidates

Behavior examples

""          + Ctrl+T → statement name list (all ~40 statements)
"SHO"       + Ctrl+T → statement names filtered by "SHO" (SHOW DATABASES, SHOW TABLES, ...)
"USE"       + Ctrl+T → statement names filtered by "USE" (shows USE <database> [ROLE <role>])
"USE "      + Ctrl+T → database names (arg completion)
"USE my"    + Ctrl+T → database names, pre-filtered "my"
"SET"       + Ctrl+T → statement names (SET <name> = <value>, SET TRANSACTION ...)
"SET "      + Ctrl+T → variable names (arg completion)
"SHOW COLUMNS FROM " + Ctrl+T → table names (arg completion)
"TRUNCATE TABLE "    + Ctrl+T → table names (arg completion)
"DROP DATABASE "     + Ctrl+T → database names (arg completion)

Completable argument contexts

Statement Completion type Source
USE <db> Database ListDatabases RPC
DROP DATABASE <db> Database ListDatabases RPC
SET <var> Variable In-memory registry
SHOW VARIABLE <var> Variable In-memory registry
SHOW COLUMNS FROM <table> Table INFORMATION_SCHEMA.TABLES
SHOW INDEX FROM <table> Table INFORMATION_SCHEMA.TABLES
TRUNCATE TABLE <table> Table INFORMATION_SCHEMA.TABLES

Test plan

  • make check passes
  • TestDetectFuzzyContext covers: all arg completion contexts, statement name fallback, edge cases (SET with =, USE without space)
  • TestExtractFixedPrefix covers: no-arg, single-arg, multi-keyword, optional, curly brace, ellipsis
  • TestBuildStatementNameCandidates and TestStatementNameDisplayTexts
  • Manual: statement name completion, argument completion, loading indicator, cursor-position-aware detection

🤖 Generated with Claude Code

…VARIABLE

Add fuzzy finder support for SET and SHOW VARIABLE statements.
Typing `SET CLI_<Ctrl+T>` or `SHOW VARIABLE <Ctrl+T>` opens the fuzzy
finder with all registered system variable names. Zero API calls needed
as variable names come from the in-memory registry.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @apstndb, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the command-line interface by introducing intelligent fuzzy completion for system variable names. Users can now leverage fuzzy search when typing SET <variable> or SHOW VARIABLE <variable>, streamlining interaction and reducing errors. The implementation ensures fast, in-memory lookups and robust handling of various input scenarios, improving the overall user experience for managing system variables.

Highlights

  • Fuzzy Finder for System Variables: Added fuzzy finder support for SET <variable> and SHOW VARIABLE <variable> commands, allowing users to quickly find and complete system variable names.
  • In-Memory Variable Lookup: Implemented variable name retrieval directly from an in-memory registry, ensuring zero API calls and instant response times for completion suggestions.
  • Context Detection and Edge Cases: Introduced new regular expressions to accurately detect SET and SHOW VARIABLE contexts and explicitly handled various edge cases, such as SET without a space, SET with an equals sign, and SHOW VARIABLES (plural), to prevent incorrect triggers.
  • Sorted Variable Candidates: Ensured that the system variable candidates presented in the fuzzy finder are sorted alphabetically for consistent and predictable ordering.
Changelog
  • internal/mycli/fuzzy_finder.go
    • Imported maps and slices packages for new functionality.
    • Defined fuzzyContextVariable constant to represent the new completion context.
    • Introduced setVarContextRe and showVarContextRe regular expressions for detecting SET and SHOW VARIABLE contexts.
    • Modified detectFuzzyContext to incorporate the new regex patterns and return fuzzyContextVariable when appropriate.
    • Updated fetchCandidates to call a new fetchVariableCandidates function for the variable context type.
    • Implemented fetchVariableCandidates to retrieve and sort system variable names from the CLI's registry.
  • internal/mycli/fuzzy_finder_test.go
    • Expanded TestDetectFuzzyContext with comprehensive test cases for SET <variable> and SHOW VARIABLE <variable> contexts.
    • Added tests for various inputs, including partial names, no names, lowercase commands, and specific edge cases like SET without a space or with an equals sign, and SHOW VARIABLES (plural).
Activity
  • No human activity has been recorded on this pull request since its creation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully adds fuzzy finder support for system variable names in SET and SHOW VARIABLE contexts. The implementation is well-integrated with the existing fuzzy finder infrastructure and includes comprehensive tests. I identified one high-severity issue where the completion feature would fail on its first use if the system variable registry hadn't been lazily initialized yet.

ListVariables() internally calls ensureRegistry(), making the explicit
Registry nil check redundant. The check also prevented the fuzzy finder
from working on first use when the registry hadn't been initialized yet.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Feb 22, 2026

Code Metrics Report

📊 View detailed coverage report (available for 7 days)

main (1292e55) #507 (1f7e7bc) +/-
Coverage 69.3% 68.8% -0.5%
Code to Test Ratio 1:1.2 1:1.2 +0.0
Test Execution Time 2m6s 1m18s -48s
Details
  |                     | main (1292e55) | #507 (1f7e7bc) |  +/-  |
  |---------------------|----------------|----------------|-------|
- | Coverage            |          69.3% |          68.8% | -0.5% |
  |   Files             |             55 |             55 |     0 |
  |   Lines             |           5762 |           5843 |   +81 |
+ |   Covered           |           3997 |           4024 |   +27 |
+ | Code to Test Ratio  |          1:1.2 |          1:1.2 |  +0.0 |
  |   Code              |          13244 |          13432 |  +188 |
+ |   Test              |          16622 |          16859 |  +237 |
+ | Test Execution Time |           2m6s |          1m18s |  -48s |

Code coverage of files in pull request scope (68.0% → 59.4%)

Files Coverage +/- Status
internal/mycli/client_side_statement_def.go 80.2% -2.1% modified
internal/mycli/fuzzy_finder.go 25.6% +15.3% modified

Reported by octocov

@apstndb
Copy link
Owner Author

apstndb commented Feb 22, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a valuable enhancement by adding fuzzy finder support for system variable completion in SET and SHOW VARIABLE contexts. The implementation is straightforward, and the added tests provide good coverage for the new functionality and its edge cases. However, I've identified a critical concurrency issue. The new code makes a call to a function that is not thread-safe, which introduces a data race risk. This violates the repository's concurrency guidelines and should be addressed to ensure application stability.

…ompletion framework

Unify fuzzy completion with clientSideStatementDef so both statement names and
arguments are completable from a single source of truth.

Two completion modes in one Ctrl+T press:
- Argument completion (priority): if input matches a statement with a Completion
  entry (e.g. "USE ", "SET ", "SHOW COLUMNS FROM "), complete the argument
- Statement name completion (fallback): show all client-side statement syntaxes
  as fuzzy candidates (e.g. typing "SHO" shows all SHOW-prefixed statements)

Key changes:
- Add fuzzyArgCompletion type and Completion field to clientSideStatementDef
- Add Completion entries for USE, SET, SHOW VARIABLE, SHOW COLUMNS FROM,
  SHOW INDEX FROM, TRUNCATE TABLE, DROP DATABASE
- Add fetchTableCandidates querying INFORMATION_SCHEMA.TABLES
- Rewrite detectFuzzyContext to iterate defs instead of hardcoded regexes
- Add extractFixedPrefix to derive insert text from syntax strings
- Use cursor position (not full buffer) for context detection
- Show loading indicator with timeout for network-dependent completions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@apstndb apstndb changed the title feat(fuzzy-finder): add system variable name completion feat(fuzzy-finder): statement name + argument completion framework Feb 22, 2026
@apstndb
Copy link
Owner Author

apstndb commented Feb 22, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a comprehensive fuzzy completion framework, unifying statement name and argument completion. It integrates completion logic directly into clientSideStatementDef and adds support for database, variable, and table name completion. The changes also include a loading indicator for network-dependent fetches and cursor-position-aware context detection. The test suite has been expanded to cover the new completion logic. The changes are well-structured and align with the project's goals of enhancing user experience through improved CLI interactivity. The code adheres to the Go best practices outlined in the repository style guide, particularly regarding clarity and maintainability in test code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@apstndb
Copy link
Owner Author

apstndb commented Feb 22, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a robust fuzzy completion framework for client-side statements, unifying statement name and argument completion. It correctly leverages clientSideStatementDef for completion logic and adds support for database, variable, and table name completion. The implementation includes a loading indicator for network-dependent fetches and uses cursor position for context detection, which are good usability improvements. The test coverage for detectFuzzyContext and extractFixedPrefix is comprehensive. Overall, the changes significantly enhance the interactive experience of the CLI.

- Use FindStringSubmatchIndex for argStart calculation in
  detectFuzzyContext, replacing the implicit suffix convention
  with direct byte position from the regex engine.
- Improve fuzzyCompletionType.String() default case to include
  the numeric value for easier debugging of unhandled types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@apstndb
Copy link
Owner Author

apstndb commented Feb 22, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a comprehensive fuzzy completion framework for client-side statements, unifying statement name and argument completion. It correctly leverages the clientSideStatementDef structure to define completion types and patterns, eliminating redundant regexes. The implementation includes a loading indicator for network-dependent completions and correctly uses the cursor position for context detection. The test coverage for detectFuzzyContext has been significantly expanded to cover various argument completion contexts and statement name fallbacks, which is a great improvement. Additionally, new tests for extractFixedPrefix, buildStatementNameCandidates, and statementNameDisplayTexts ensure the robustness of the statement name completion logic. Overall, the changes are well-structured and enhance the user experience by providing intelligent and context-aware completions. One comment's severity was adjusted to reflect that the identified issue is for future robustness rather than an immediate problem, aligning with existing guidelines.

@apstndb
Copy link
Owner Author

apstndb commented Feb 22, 2026

/gemini summary

@gemini-code-assist
Copy link
Contributor

Summary of Changes

This pull request significantly enhances the interactive command-line experience by overhauling the fuzzy completion system. It unifies the logic for suggesting both statement names and their arguments, making the completion process more intelligent and extensible. Users will now benefit from context-aware suggestions for various SQL commands, including databases, variables, and table names, along with a robust fallback to general statement name completion. The changes also introduce visual feedback for network-intensive operations and improve the accuracy of completion based on the cursor's position.

Highlights

  • Unified Fuzzy Completion Framework: Integrated statement name and argument completion directly into the clientSideStatementDef structure, creating a single source of truth for fuzzy completion logic and eliminating redundant regex definitions.
  • Argument-Specific Completions: Introduced fuzzyCompletionType and fuzzyArgCompletion to define specific argument completion types (database, variable, table) with associated regex patterns, enabling context-aware suggestions for USE, DROP DATABASE, SET, SHOW VARIABLE, SHOW COLUMNS FROM, SHOW INDEX FROM, and TRUNCATE TABLE statements.
  • Statement Name Fallback: Implemented a fallback mechanism where if the input doesn't match any specific argument completion context, the fuzzy finder defaults to suggesting all client-side statement names.
  • Table Name Completion: Added functionality to fetch table names for completion from INFORMATION_SCHEMA.TABLES, providing dynamic suggestions for relevant statements.
  • Loading Indicator and Timeout for Network Fetches: Implemented a visual 'Loading...' indicator with a 10-second timeout for network-dependent completions (like fetching databases or tables), improving user experience during potential delays.
  • Cursor-Position-Aware Context Detection: Modified the fuzzy finder to use the text up to the cursor position for context detection, ensuring more accurate and relevant completion suggestions when editing in the middle of a line.
  • Improved Statement Name Candidate Generation: Developed extractFixedPrefix to intelligently determine the insert text for statement name candidates, providing a clean keyword prefix with a trailing space for statements expecting arguments, and the full statement for no-argument commands.
Changelog
  • internal/mycli/client_side_statement_def.go
    • Defined fuzzyCompletionType enum and fuzzyArgCompletion struct to standardize argument completion types and patterns.
    • Added a Completion field to clientSideStatementDef to associate argument completion rules directly with client-side statements.
    • Populated the Completion field for several statements (USE, DROP DATABASE, SHOW COLUMNS FROM, SHOW INDEX FROM, TRUNCATE TABLE, SET, SHOW VARIABLE) with appropriate regex patterns and completion types.
    • Implemented a String() method for fuzzyCompletionType to provide human-readable names for logging and debugging.
  • internal/mycli/fuzzy_finder.go
    • Imported necessary packages for string manipulation, time, unicode, and Spanner client operations.
    • Introduced fuzzyFetchTimeout constant for network-dependent completion operations.
    • Modified Call method to use the input up to the cursor position for context detection, improving accuracy.
    • Updated Call to handle insertion of both argument completions and statement name fixed prefixes.
    • Refactored detectFuzzyContext to prioritize argument completion based on clientSideStatementDef.Completion entries, falling back to statement name completion if no argument context is found.
    • Removed deprecated fuzzyContextType and useContextRe.
    • Added statementNameCandidate struct and related functions (statementNameDisplayTexts, buildStatementNameCandidates, extractFixedPrefix) to manage and generate candidates for statement name completion.
    • Introduced requiresNetwork and resolveCandidates functions to manage loading indicators and apply timeouts for network-fetching completion types.
    • Implemented fetchVariableCandidates to retrieve system variable names from an in-memory registry.
    • Implemented fetchTableCandidates to query INFORMATION_SCHEMA.TABLES for table names.
  • internal/mycli/fuzzy_finder_test.go
    • Expanded TestDetectFuzzyContext with numerous new test cases covering various argument completion contexts (database, variable, table) and statement name fallback scenarios, including edge cases.
    • Added TestExtractFixedPrefix to verify the correct extraction of fixed keyword prefixes from statement syntax strings.
    • Added TestBuildStatementNameCandidates and TestStatementNameDisplayTexts to ensure proper generation and display of statement name completion candidates.
Activity
  • A summary of changes was provided by gemini-code-assist[bot] upon PR creation.
  • A Code Metrics Report was posted by github-actions[bot], indicating a slight decrease in overall coverage but an increase in coverage for fuzzy_finder.go.
  • The author, apstndb, requested multiple /gemini review and /gemini summary commands.
  • gemini-code-assist[bot] suggested fixing an unnecessary sv.Registry == nil check, which was addressed by apstndb in commit 9193766.
  • gemini-code-assist[bot] raised a critical concern about the concurrency safety of sv.ListVariables() due to a check-then-act pattern; apstndb responded that it's a pre-existing pattern not introduced by this PR and would be better addressed separately.
  • gemini-code-assist[bot] recommended logging completionType.String() for better debug readability; apstndb added a String() method to fuzzyCompletionType (commit 50208d2), noting slog automatically uses it.
  • gemini-code-assist[bot] questioned the argStart calculation; apstndb clarified its correctness for rune-based indexing and the pattern's intent.
  • gemini-code-assist[bot] suggested adding a String() method to fuzzyCompletionType, which apstndb implemented (commit 50208d2).
  • gemini-code-assist[bot] acknowledged the iota + 1 pattern for fuzzyCompletionType as a clean way to handle default states.
  • gemini-code-assist[bot] suggested a more descriptive default case for fuzzyCompletionType.String(); apstndb updated it to include the unhandled numeric value for better debugging (commit 3c81624).
  • gemini-code-assist[bot] repeatedly suggested more robust regex patterns for PrefixPattern in client_side_statement_def.go to handle quoted identifiers; apstndb consistently responded that the current \S* is sufficient as these are fuzzy completion triggers, not full parsers, and users select from candidates.
  • gemini-code-assist[bot] acknowledged the improvement of using B.SubString(0, B.Cursor) for input, which apstndb also acknowledged.
  • gemini-code-assist[bot] suggested explicitly calling err.Error() in slog.Debug calls; apstndb clarified that slog handles error values natively and explicit calls are unnecessary.
  • gemini-code-assist[bot] suggested optimizing the detectFuzzyContext lookup; apstndb stated that for the current small, fixed number of statements, the linear scan is performant enough.
  • gemini-code-assist[bot] noted the hardcoded TABLE_CATALOG = '' in fetchTableCandidates; apstndb agreed it's acceptable for current Spanner behavior.
  • gemini-code-assist[bot] provided positive feedback on the comprehensive test cases for TestDetectFuzzyContext, SET with =, and general statement name completion, which apstndb acknowledged.

@apstndb apstndb merged commit 08d52cc into main Feb 22, 2026
2 checks passed
@apstndb apstndb deleted the feat/fuzzy-finder branch February 22, 2026 17:56
apstndb added a commit that referenced this pull request Feb 22, 2026
Improve review workflow skills and Gemini style guide based on learnings
from PR #507 review cycles.

Key changes:
- review-cycle.md: Expand from simple delegation to fully autonomous
  workflow with thread-type detection, fix/explain/acknowledge strategies,
  and explicit reply-then-re-review loop (fixes logical gap in step 6)
- review-respond.md: Add reply content guidelines (no bare commit hashes),
  improve examples with explanation-first format, fix arguments field typo
- .gemini/styleguide.md: Add "Avoid Praise-Only Comments" section to
  reduce noise (~30% of #507 threads were praise-only)
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.

1 participant