Skip to content

feat(cli): one-command shell completion install (completions --install)#20

Merged
sunerpy merged 2 commits into
mainfrom
feat/completions-install
Jun 22, 2026
Merged

feat(cli): one-command shell completion install (completions --install)#20
sunerpy merged 2 commits into
mainfrom
feat/completions-install

Conversation

@sunerpy

@sunerpy sunerpy commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Summary

Make shell completions actually usable in one command. codegraph completions <shell> previously only printed the script to stdout, leaving users to hand-wire their rc/profile — which on PowerShell is actively broken (clap_complete emits using namespace ... at the top, so appending it into a non-empty $PROFILE fails with UsingMustBeAtStartOfScript, and re-appending duplicates it).

  • feat(cli): completions <shell> --install — writes the completion script to the shell's standard location and reports the path. Idempotent (safe to re-run). Without --install, behavior is unchanged (stdout).
    • bash → ${XDG_DATA_HOME:-~/.local/share}/bash-completion/completions/codegraph (auto-loaded, no .bashrc edit)
    • zsh → ~/.zfunc/_codegraph (+ advises fpath+=~/.zfunc)
    • fish → ~/.config/fish/completions/codegraph.fish
    • powershell → %LOCALAPPDATA%\codegraph\completion.ps1 (a separate file so using namespace is legal at file start) + a single idempotent dot-source line in $PROFILE
    • elvish → ~/.config/codegraph/completion.elv (+ advises eval)
    • Design: generate a completion file + add one source/dot-source reference to the rc — never paste the full script inline; re-running deduplicates.
  • docs: docs/cli.md expanded with per-shell enablement (--install + manual fallback), the PowerShell using/UsingMustBeAtStartOfScript rationale, and the Ctrl+Space / Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete tip; concise zh-CN mirror; one-line README pointer.

Verification

  • cargo test -p codegraph-rs green incl. new completions_powershell_install_is_idempotent + completions_bash_install_writes_file.
  • Hands-on: PowerShell --install ×3 → exactly one dot-source line in $PROFILE; bash --install ×2 → one completion file, .bashrc untouched.
  • cargo clippy --workspace --all-targets -- -D warnings clean; cargo fmt --all --check + make fmt clean; bash scripts/guardrail.sh exit 0.
  • Windows x86_64 cross-compile (cargo-xwin) green.
  • release-please will compute v0.5.0 (feat present).

Note

CI may flake on two pre-existing parallel tests (codegraph-watch::sync::tests::unchanged_file_hash_is_not_reindexed, codegraph-mcp::golden_mcp::tools_list_matches_upstream_names_and_schemas) — re-run if so; not introduced here.

sunerpy added 2 commits June 22, 2026 17:06
`codegraph completions <shell> --install` writes the generated script to
the shell's standard completion location instead of only printing it, and
prints a restart hint. Without --install the behavior is unchanged (stdout).

PowerShell emits `using namespace System.Management.Automation` on its first
lines, and PowerShell only accepts `using` at the start of a script. Appending
the output to a non-empty $PROFILE therefore fails with
UsingMustBeAtStartOfScript and, on repeat, leaves a duplicate block. The fix
writes the PowerShell script to its own completion.ps1 (where `using` is legal
at file start) under %LOCALAPPDATA%\codegraph and adds a single idempotent
dot-source line to $PROFILE (check-before-append, never duplicated).

bash/zsh/fish/elvish are written into their standard completion dirs
(${XDG_DATA_HOME:-~/.local/share}/bash-completion/completions/codegraph,
~/.zfunc/_codegraph, ~/.config/fish/completions/codegraph.fish,
~/.config/codegraph/completion.elv); zsh/elvish print a one-time manual
loading hint, no rc files are edited automatically.
@sunerpy sunerpy merged commit c7961b7 into main Jun 22, 2026
4 checks passed
@sunerpy sunerpy deleted the feat/completions-install branch June 22, 2026 09:31
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