Skip to content

Comments

feat(fuzzy-finder): add variable value completion for SET statements#510

Merged
apstndb merged 2 commits intomainfrom
feat/fuzzy-variable-value-completion
Feb 22, 2026
Merged

feat(fuzzy-finder): add variable value completion for SET statements#510
apstndb merged 2 commits intomainfrom
feat/fuzzy-variable-value-completion

Conversation

@apstndb
Copy link
Owner

@apstndb apstndb commented Feb 22, 2026

Summary

  • Add fuzzy completion for SET <name> = <Ctrl+T> showing valid values for enum-type variables (~15 enum/proto-enum vars + ~30 boolean vars)
  • Values are proper GoogleSQL literals: single-quoted strings for enums ('TABLE'), bare TRUE/FALSE for booleans
  • SET variable name completion now appends = suffix so SET <Ctrl+T> → select CLI_FORMATSET CLI_FORMAT = (ready for value input or another Ctrl+T)
  • detectFuzzyContext generalized to use last capture group as argPrefix, earlier groups as context

Test plan

  • make check passes (test + lint + fmt-check)
  • TestDetectFuzzyContext expanded with 6 value completion cases (SET FORMAT = , SET FORMAT = TA, SET FORMAT=, SET READONLY = , etc.)
  • Existing tests unchanged (name completion, statement name, table, database all still work)
  • Manual: SET CLI_FORMAT = <Ctrl+T> shows 'TABLE'/'VERTICAL'/etc.
  • Manual: SET READONLY = <Ctrl+T> shows TRUE/FALSE (unquoted)
  • Manual: SET <Ctrl+T> → select var → inserts <name> =

Fixes #509

🤖 Generated with Claude Code

Add fuzzy completion for SET <name> = <Ctrl+T> that shows valid values
for enum-type variables. Values are returned as proper GoogleSQL literals
(single-quoted strings for enums, bare TRUE/FALSE for booleans).

Also adds " = " suffix to SET variable name completion so selecting a
variable name produces "SET <name> = " ready for value input.

Key changes:
- ValidValuesEnumerator interface for variables with constrained values
- Implement on BoolVar, EnumVar[T], ProtoEnumVar[T]
- fuzzyCompleteVariableValue completion type with 2-group regex
- detectFuzzyContext uses last capture group as argPrefix
- Suffix field on fuzzyArgCompletion for post-selection text

Fixes #509

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 fuzzy finder's capabilities by introducing intelligent completion for SET statement values. It allows users to easily discover and select valid options for system variables, improving the interactive experience. The changes involve extending the completion types, refining context detection, and ensuring values are presented in a user-friendly, GoogleSQL-compliant format.

Highlights

  • Fuzzy Completion for SET Variable Values: Added fuzzy completion for SET <name> = <Ctrl+T> statements, providing valid values for enum-type and boolean variables. This includes approximately 15 enum/proto-enum variables and 30 boolean variables.
  • GoogleSQL Literal Formatting: Completion values are now presented as proper GoogleSQL literals, such as single-quoted strings for enums (e.g., 'TABLE') and bare TRUE/FALSE for booleans.
  • Enhanced SET Variable Name Completion: When completing a SET variable name, the system now automatically appends = after selection, preparing the input for immediate value entry (e.g., SET <Ctrl+T> -> select CLI_FORMAT -> inserts SET CLI_FORMAT = ).
  • Generalized Fuzzy Context Detection: The detectFuzzyContext function has been generalized to use the last regular expression capture group as the argument prefix and earlier groups as contextual information, enabling more sophisticated completion logic.
Changelog
  • internal/mycli/client_side_statement_def.go
    • Added fuzzyCompleteVariableValue to the fuzzyCompletionType enum.
    • Introduced a Suffix field to fuzzyArgCompletion to allow appending text after a selected completion candidate.
    • Updated the SET statement completion logic to include a new PrefixPattern for variable value completion and to apply the = suffix for variable name completion.
  • internal/mycli/fuzzy_finder.go
    • Modified fuzzyContextResult to include context and suffix fields for richer completion information.
    • Updated detectFuzzyContext to extract argPrefix from the last regex capture group and context from earlier groups, and to store the Suffix.
    • Adjusted Call method to use the new suffix when inserting selected candidates.
    • Modified resolveCandidates to accept completionContext for fetching context-dependent candidates.
    • Added unwrapCustomVar helper function to extract base variables from CustomVar types.
    • Implemented fetchVariableValueCandidates to retrieve valid values for system variables based on the provided context.
  • internal/mycli/fuzzy_finder_test.go
    • Expanded TestDetectFuzzyContext test cases to include wantContext and wantSuffix assertions.
    • Added new test cases specifically for SET variable value completion, covering various input formats and variable types.
  • internal/mycli/var_enum_handlers.go
    • Imported maps and slices packages.
    • Implemented the ValidValues method for EnumVar to return sorted valid enum values as GoogleSQL string literals.
    • Implemented the ValidValues method for ProtoEnumVar to return sorted, prefix-stripped valid proto enum values as GoogleSQL string literals.
  • internal/mycli/var_handler.go
    • Defined the ValidValuesEnumerator interface for variables with a constrained set of valid values.
    • Added an enumValues field to VarHandler to store optional constrained values.
    • Implemented the ValidValues method for VarHandler to fulfill the ValidValuesEnumerator interface.
    • Configured BoolVar to include TRUE and FALSE in its enumValues for completion.
  • internal/mycli/var_registry.go
    • Added GetVariable method to retrieve a Variable handler by its name from the registry.
Activity
  • The author confirmed that make check (test + lint + fmt-check) passes.
  • The TestDetectFuzzyContext was expanded with 6 new value completion cases.
  • Existing tests for name completion, statement name, table, and database completion remain unchanged and functional.
  • Manual testing was performed to verify SET CLI_FORMAT = <Ctrl+T> shows 'TABLE'/'VERTICAL'/etc.
  • Manual testing was performed to verify SET READONLY = <Ctrl+T> shows TRUE/FALSE (unquoted).
  • Manual testing was performed to verify SET <Ctrl+T> followed by selecting a variable inserts <name> = .
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.

@github-actions
Copy link

github-actions bot commented Feb 22, 2026

Code Metrics Report

📊 View detailed coverage report (available for 7 days)

main (08d52cc) #510 (3d5cd7d) +/-
Coverage 68.8% 68.5% -0.4%
Code to Test Ratio 1:1.2 1:1.2 -0.1
Test Execution Time 1m6s 1m7s +1s
Details
  |                     | main (08d52cc) | #510 (3d5cd7d) |  +/-  |
  |---------------------|----------------|----------------|-------|
- | Coverage            |          68.8% |          68.5% | -0.4% |
  |   Files             |             55 |             55 |     0 |
  |   Lines             |           5843 |           5879 |   +36 |
+ |   Covered           |           4024 |           4031 |    +7 |
- | Code to Test Ratio  |          1:1.2 |          1:1.2 |  -0.1 |
  |   Code              |          13432 |          13514 |   +82 |
+ |   Test              |          16859 |          16900 |   +41 |
- | Test Execution Time |           1m6s |           1m7s |   +1s |

Code coverage of files in pull request scope (75.5% → 73.0%)

Files Coverage +/- Status
internal/mycli/client_side_statement_def.go 79.9% -0.4% modified
internal/mycli/fuzzy_finder.go 25.6% +0.0% modified
internal/mycli/var_custom_handlers.go 76.2% -0.7% modified
internal/mycli/var_enum_handlers.go 75.0% -12.7% modified
internal/mycli/var_handler.go 91.6% -1.3% modified
internal/mycli/var_registry.go 90.3% -0.4% modified

Reported by octocov

- CLI_QUERY_MODE: change CustomVar base from dummy StringVar to
  QueryModeVar so unwrapCustomVar exposes ValidValuesEnumerator
- LogLevelVar: implement ValidValues() returning standard log levels

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 fuzzy completion for variable values in SET statements, significantly improving the user experience for configuring system variables. While the implementation is well-integrated, follows Go idioms, and includes comprehensive test coverage, a high-severity Local File Inclusion (LFI) vulnerability was identified. This vulnerability, located in a modified file but not directly on the changed lines, allows an attacker to read arbitrary files from the local filesystem by maliciously setting a specific system variable. Addressing this security concern is critical.

@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 significant enhancement to the fuzzy finder by adding variable value completion for SET statements. The implementation is clean, idiomatic, and leverages Go 1.25 features as specified in the repository style guide. Key improvements include the generalization of detectFuzzyContext to handle context (like variable names), the addition of the ValidValuesEnumerator interface to provide constrained candidates for enums and booleans, and a UX improvement where selecting a variable name automatically appends the = suffix. The use of GoogleSQL literals (quoted strings for enums, bare TRUE/FALSE for booleans) ensures consistency with the tool's parser. The test coverage has been appropriately expanded to verify the new completion logic.

@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 fuzzy finder's capabilities by introducing intelligent completion for SET statement values. It allows users to easily discover and select valid options for system variables, improving the interactive experience. The changes involve extending the completion types, refining context detection, and ensuring values are presented in a user-friendly, GoogleSQL-compliant format.

Highlights

  • Fuzzy Completion for SET Variable Values: Added fuzzy completion for SET <name> = <Ctrl+T> statements, providing valid values for enum-type and boolean variables (approximately 15 enum/proto-enum variables and 30 boolean variables).
  • GoogleSQL Literal Formatting: Completion values are now presented as proper GoogleSQL literals, such as single-quoted strings for enums (e.g., 'TABLE') and bare TRUE/FALSE for booleans.
  • Enhanced SET Variable Name Completion: When completing a SET variable name, the system now automatically appends = after selection, preparing the input for immediate value entry (e.g., SET <Ctrl+T> -> select CLI_FORMAT -> inserts SET CLI_FORMAT = ).
  • Generalized Fuzzy Context Detection: The detectFuzzyContext function has been generalized to use the last regular expression capture group as the argument prefix and earlier groups as contextual information, enabling more sophisticated completion logic.
Changelog
  • internal/mycli/client_side_statement_def.go
    • Added fuzzyCompleteVariableValue to the fuzzyCompletionType enum and its string representation.
    • Introduced a Suffix field to the fuzzyArgCompletion struct to allow appending text after a selected completion candidate.
    • Updated the SET statement completion logic to include a new PrefixPattern for variable value completion and to apply the = suffix for variable name completion.
  • internal/mycli/fuzzy_finder.go
    • Modified fuzzyContextResult to include context and suffix fields for richer completion information.
    • Updated detectFuzzyContext to extract argPrefix from the last regex capture group and context from earlier groups, and to store the Suffix.
    • Adjusted the Call method to use the new suffix when inserting selected candidates.
    • Modified resolveCandidates to accept completionContext for fetching context-dependent candidates.
    • Added unwrapCustomVar helper function to extract base variables from CustomVar types.
    • Implemented fetchVariableValueCandidates to retrieve valid values for system variables based on the provided context.
  • internal/mycli/fuzzy_finder_test.go
    • Expanded TestDetectFuzzyContext test cases to include wantContext and wantSuffix assertions.
    • Added new test cases specifically for SET variable value completion, covering various input formats and variable types.
  • internal/mycli/var_custom_handlers.go
    • Implemented the ValidValues method for LogLevelVar to return standard log level names as GoogleSQL string literals.
  • internal/mycli/var_enum_handlers.go
    • Imported maps and slices packages for collection manipulation.
    • Implemented the ValidValues method for EnumVar to return sorted valid enum values as GoogleSQL string literals.
    • Implemented the ValidValues method for ProtoEnumVar to return sorted, prefix-stripped valid proto enum values as GoogleSQL string literals.
  • internal/mycli/var_handler.go
    • Defined the ValidValuesEnumerator interface for variables with a constrained set of valid values.
    • Added an enumValues field to VarHandler to store optional constrained values.
    • Implemented the ValidValues method for VarHandler to fulfill the ValidValuesEnumerator interface.
    • Configured BoolVar to include TRUE and FALSE in its enumValues for completion.
  • internal/mycli/var_registry.go
    • Added GetVariable method to retrieve a Variable handler by its name from the registry.
    • Updated the registration of CLI_QUERY_MODE to use QueryModeVar for its base, enabling proper ValidValues enumeration.
Activity
  • The author confirmed that make check (test + lint + fmt-check) passes.
  • The TestDetectFuzzyContext was expanded with 6 new value completion cases to cover the new functionality.
  • Existing tests for name completion, statement name, table, and database completion remain unchanged and functional.
  • Manual testing was performed to verify SET CLI_FORMAT = <Ctrl+T> shows 'TABLE'/'VERTICAL'/etc.
  • Manual testing was performed to verify SET READONLY = <Ctrl+T> shows TRUE/FALSE (unquoted).
  • Manual testing was performed to verify SET <Ctrl+T> followed by selecting a variable inserts <name> = .
  • A bot identified a potential Local File Inclusion (LFI) vulnerability related to CLI_OUTPUT_TEMPLATE_FILE in var_registry.go.
  • The author responded, clarifying that the reported LFI is a false positive for an interactive CLI tool where users already have filesystem access, and the GetVariable method added in this PR is unrelated to the template file setter.

@apstndb apstndb merged commit 1744964 into main Feb 22, 2026
2 checks passed
@apstndb apstndb deleted the feat/fuzzy-variable-value-completion branch February 22, 2026 20:33
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.

Fuzzy completion: remaining tasks

1 participant