Skip to content

feat: Add support for nushell#485

Open
abusch wants to merge 3 commits intojdx:mainfrom
abusch:nushell_support
Open

feat: Add support for nushell#485
abusch wants to merge 3 commits intojdx:mainfrom
abusch:nushell_support

Conversation

@abusch
Copy link

@abusch abusch commented Feb 7, 2026

Gave a shot at adding support for nushell.

@gemini-code-assist
Copy link

Summary of Changes

Hello @abusch, 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 CLI tool by integrating full support for Nushell completions. It allows users of the Nushell environment to generate and leverage intelligent command-line suggestions, streamlining their workflow and improving overall usability.

Highlights

  • Nushell Support: Added "nu" (Nushell) as a supported shell for command-line completion generation within the CLI tool.
  • Core Logic Implementation: Implemented the core logic for Nushell completion generation, including handling spec caching and dynamic script creation in a new module.
  • Documentation Update: Updated the CLI documentation to include detailed instructions and examples for setting up Nushell completions.
  • Snapshot Tests: Introduced new snapshot tests to ensure the correctness and consistency of the generated Nushell completion scripts under various configurations.
Changelog
  • cli/src/cli/complete_word.rs
    • Expanded the shell argument's value_parser to include "nu".
    • Modified the match shell statement to apply fish and powershell completion logic to "nu" as well.
  • cli/src/cli/generate/completion.rs
    • Updated the shell argument's value_parser to recognize "nu" as a valid shell.
  • docs/cli/completions.md
    • Added a new section with detailed instructions and example commands for generating and sourcing Nushell completions.
  • lib/src/complete/mod.rs
    • Declared a new module mod nu;.
    • Added a nu arm to the complete function's match statement, calling nu::complete_nu(options).
  • lib/src/complete/nu.rs
    • New file containing the complete_nu function responsible for generating Nushell completion scripts.
    • Implements logic for handling usage_bin, bin, cache_key, spec, and usage_cmd to construct the Nushell completion script.
    • Includes error handling for when the usage CLI is not found.
    • Contains unit tests with insta::assert_snapshot! for various CompleteOptions configurations.
  • lib/src/complete/snapshots/usage__complete__nu__tests__complete_nu-2.snap
    • New snapshot for Nushell completion with a cache key.
  • lib/src/complete/snapshots/usage__complete__nu__tests__complete_nu-3.snap
    • New snapshot for Nushell completion with an embedded spec.
  • lib/src/complete/snapshots/usage__complete__nu__tests__complete_nu.snap
    • New snapshot for basic Nushell completion.
Activity
  • The author, abusch, initiated this pull request to add Nushell support.
  • No further review comments or activities have been recorded yet.
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

@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 adds support for nushell completions, which is a great addition. The implementation largely follows the existing patterns for other shells. I've identified a bug related to string escaping in the generated nushell script that could cause issues. I also have a couple of suggestions to improve the documentation and the formatting of the generated script. Overall, this is a solid contribution.

@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

❌ Patch coverage is 92.50000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.90%. Comparing base (ed677d0) to head (9a083b1).

Files with missing lines Patch % Lines
lib/src/complete/nu.rs 94.87% 3 Missing and 1 partial ⚠️
cli/src/cli/complete_word.rs 0.00% 0 Missing and 1 partial ⚠️
lib/src/complete/mod.rs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #485      +/-   ##
==========================================
+ Coverage   70.71%   70.90%   +0.19%     
==========================================
  Files          47       48       +1     
  Lines        6716     6796      +80     
  Branches     6716     6796      +80     
==========================================
+ Hits         4749     4819      +70     
- Misses       1277     1281       +4     
- Partials      690      696       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Remove extra new lines
- Switch code block in documentation to `nushell` syntax
- Use nushell's raw strings to hold spec, to avoid the need to escape it
@abusch
Copy link
Author

abusch commented Feb 7, 2026

/gemini review

Copy link

@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 adds support for nushell completions. The changes are comprehensive, touching the CLI argument parsing, completion logic, documentation, and adding a new module for generating nushell completion scripts.

Overall, the implementation is well done. I've left a couple of comments on the new lib/src/complete/nu.rs file with suggestions for refactoring to improve code clarity and reduce duplication. These are not critical but would improve the maintainability of the new code.

The rest of the changes, which mostly involve adding 'nu' to the list of supported shells in various files, are correct and consistent. The documentation updates are also clear and helpful.

Comment on lines +9 to +13
let spec_variable = if let Some(cache_key) = &opts.cache_key {
format!("_usage_spec_{bin_snake}_{}", cache_key.to_snake_case())
} else {
format!("_usage_spec_{bin_snake}")
};

Choose a reason for hiding this comment

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

medium

The way spec_variable is constructed and then used to create spec_file on line 57 leads to a filename with a double underscore (e.g., usage__usage_spec_...). This is a bit awkward and could be improved for clarity.

Consider separating the unique identifier part of the name. This would make the generated filenames cleaner and the code easier to follow.

Example refactoring:

let spec_identifier = if let Some(cache_key) = &opts.cache_key {
    format!("{}_{}", bin_snake, cache_key.to_snake_case())
} else {
    bin_snake.to_string()
};
let spec_variable = format!("_usage_spec_{}", spec_identifier);

// ... and later in the file:
// let spec_file = $"($nu.temp-dir)/usage_{spec_identifier}.spec"

This would produce a filename like usage_mycli_1_2_3.spec instead of usage__usage_spec_mycli_1_2_3.spec.

Comment on lines +30 to +52
let file_write_logic = if let Some(usage_cmd) = &opts.usage_cmd {
if opts.cache_key.is_some() {
format!(
r#"if not ($spec_file | path exists) {{
{usage_cmd} | collect | save $spec_file
}}"#
)
} else {
format!(r#"{usage_cmd} | collect | save -f $spec_file"#)
}
} else if let Some(_spec) = &opts.spec {
if opts.cache_key.is_some() {
format!(
r#"if not ($spec_file | path exists) {{
${spec_variable} | save $spec_file
}}"#
)
} else {
format!(r#"${spec_variable} | save -f $spec_file"#)
}
} else {
String::new()
};

Choose a reason for hiding this comment

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

medium

There's duplicated logic for building file_write_logic. The conditional logic for opts.cache_key.is_some() is repeated for both usage_cmd and spec cases. This can be refactored to be more DRY and improve maintainability.

    let file_write_logic = {
        let spec_source = if let Some(usage_cmd) = &opts.usage_cmd {
            Some(format!("{} | collect", usage_cmd))
        } else if opts.spec.is_some() {
            Some(format!("${}", spec_variable))
        } else {
            None
        };

        if let Some(spec_source) = spec_source {
            if opts.cache_key.is_some() {
                format!(
                    r#"if not ($spec_file | path exists) {{
            {} | save $spec_file
        }}"#,
                    spec_source
                )
            } else {
                format!(r#"{} | save -f $spec_file"#, spec_source)
            }
        } else {
            String::new()
        }
    };

Copy link
Owner

@jdx jdx 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 (AI-generated)

Overall this is a solid PR that adds nushell completion support following the established patterns of the existing shell implementations. The changes are well-structured across all the right files. A few issues to flag:


Issues

1. Indentation bug in generated nushell code (medium)

The .trim() call on the format string in nu.rs:52-68 strips the leading 4-space indent from def, causing it to sit at column 0 while everything else inside the module block is properly indented. You can see this in the snapshots:

module _mycli_completions {
def mycli_completer [spans: list<string>] {    # <-- should be indented
        let spec_file = ...
    }

    @complete mycli_completer
    export extern mycli []
}

The const line (when present) is correctly indented at 4 spaces, but def loses its indent. Either remove .trim() and adjust the format string, or restructure to maintain consistent indentation.

2. Doc comment not updated

cli/src/cli/generate/completion.rs:7 still says:

/// Generate shell completion scripts for bash, fish, powershell, or zsh

Should include nu/nushell.

3. Trailing whitespace in generated code

There's a trailing space after the help string in the error message (nu.rs:82):

        help: "See https://usage.jdx.dev for more information." 
                                                               ^ trailing space

4. Raw string r#'...'# could break on certain specs (low risk)

If a spec ever contains the literal character sequence '#, the nushell raw string r#'...'# would terminate early and produce a syntax error. This is unlikely in practice but worth noting — fish handles a similar concern by escaping single quotes. Could either document this limitation or add validation/escaping.


Looks good

  • Grouping "nu" with "fish" | "powershell" in complete_word.rs for tab-separated output is correct and matches the parsing logic in the generated nushell script.
  • The @complete attribute + export extern pattern is the correct modern nushell completion registration approach.
  • Module wrapping + use import is idiomatic nushell.
  • Test coverage with 3 snapshot variants matches other shells.
  • All plumbing files (fig.ts, KDL spec, docs, commands.json) properly updated.

🤖 This review was AI-generated.

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.

2 participants