Skip to content

nix profile upgrade/remove: Implement tab completion#382

Open
edolstra wants to merge 1 commit intomainfrom
profile-element-completion
Open

nix profile upgrade/remove: Implement tab completion#382
edolstra wants to merge 1 commit intomainfrom
profile-element-completion

Conversation

@edolstra
Copy link
Collaborator

@edolstra edolstra commented Mar 11, 2026

Motivation

Context

Summary by CodeRabbit

New Features

  • Implemented tab completion for profile elements in nix profile commands, allowing users to efficiently discover and select available profile items through intelligent prefix-based filtering

Tests

  • Added tests validating profile element tab completion functionality, including empty input handling, prefix-based filtering accuracy, and completion behavior across multiple command scenarios

@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

📝 Walkthrough

Walkthrough

The changes refactor class inheritance in profile commands to consolidate MixDefaultProfile into MixProfileElementMatchers, introduce dynamic completion logic for profile elements via prefix matching, and add test coverage for the new completion functionality.

Changes

Cohort / File(s) Summary
Profile Element Completion
src/nix/profile.cc
Restructured inheritance to move MixDefaultProfile into MixProfileElementMatchers (now public virtual base), added completeProfileElements function for prefix-based profile element completion with error suppression, and wired auto-completion for the elements argument.
Completion Tests
tests/functional/nix-profile.sh
Added test cases verifying tab completion behavior for profile elements, including empty input completions and prefix-filtered results (e.g., 'fl' matching 'flake1' but not 'foo'), tested across profile and upgrade commands.

Sequence Diagram

sequenceDiagram
    participant User
    participant Command as Nix Profile Command
    participant Completer as completeProfileElements
    participant Manifest as Profile Manifest
    participant Results as Completion Results

    User->>Command: Provide partial input (e.g., "fl")
    Command->>Completer: Invoke with prefix
    Completer->>Manifest: Inspect profile manifest
    Manifest-->>Completer: Return all profile elements
    Completer->>Completer: Filter by prefix match
    Completer-->>Results: Return filtered completions
    Results-->>User: Display matching elements
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops of joy through profile lines,
Completion magic intertwines,
Inheritance streams now unified and bright,
Prefix matching dances left and right!
Tests confirm the path is true,
Profile elements wait for you! 🌱

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: implementing tab completion for nix profile upgrade and remove commands, which aligns with the code changes refactoring inheritance and adding completion logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch profile-element-completion

Comment @coderabbitai help to get the list of available commands and usage tips.

@edolstra edolstra enabled auto-merge March 11, 2026 02:23
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/nix/profile.cc (1)

568-583: Consider logging errors instead of silently swallowing them.

The empty catch block at lines 581-582 prevents completion failures from breaking the shell experience, which is appropriate. However, completely silencing errors makes debugging difficult when completions don't work as expected.

🔧 Optional: Log completion errors at debug level
         for (auto & [name, element] : manifest.elements)
             if (name.starts_with(prefix))
                 completions.add(name, element.identifier());
-    } catch (...) {
+    } catch (std::exception & e) {
+        debug("profile element completion failed: %s", e.what());
+    } catch (...) {
+        debug("profile element completion failed with unknown exception");
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/nix/profile.cc` around lines 568 - 583, The empty catch in
completeProfileElements should be replaced with debug-level logging so failures
aren't silently swallowed; change the catch(...) to first catch const
std::exception& and call your project's debug logger with a message like
"completeProfileElements failed" including e.what() (and a second catch(...)
that logs an "unknown exception" message) so errors arising while using
EvalCommand, ProfileManifest, or completions.add are recorded for debugging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/nix/profile.cc`:
- Around line 568-583: The empty catch in completeProfileElements should be
replaced with debug-level logging so failures aren't silently swallowed; change
the catch(...) to first catch const std::exception& and call your project's
debug logger with a message like "completeProfileElements failed" including
e.what() (and a second catch(...) that logs an "unknown exception" message) so
errors arising while using EvalCommand, ProfileManifest, or completions.add are
recorded for debugging.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3219e1a8-860d-4ff9-becc-f7fbad7a988f

📥 Commits

Reviewing files that changed from the base of the PR and between 6362dda and 6191c88.

📒 Files selected for processing (2)
  • src/nix/profile.cc
  • tests/functional/nix-profile.sh

@github-actions
Copy link

@github-actions github-actions bot temporarily deployed to pull request March 11, 2026 02:26 Inactive
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