Skip to content

Add upstream Cargo completion spec for terminal suggestions - #305309

Merged
Megan Rogge (meganrogge) merged 11 commits into
microsoft:mainfrom
Muszic:feature/terminal-suggest-cargo-clean
Sep 15, 2026
Merged

Megan Rogge (meganrogge) merged 11 commits into
microsoft:mainfrom
Muszic:feature/terminal-suggest-cargo-clean

Conversation

@Muszic

@Muszic Sangeet (Muszic) commented Mar 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Cargo terminal completions using the complete upstream withfig/autocomplete Cargo spec instead of a hand-written subset.

Details

  • Imports cargo through the existing upstream-spec generation pipeline.
  • Covers Cargo's full upstream command and option surface, including dynamic package, target, feature, crate, toolchain, and plugin suggestions.
  • Extends the local filepaths adapter to preserve upstream exact-name filters for Cargo.toml and deny.toml.
  • Removes an upstream debug console.log during generation.
  • Adds regression coverage for the command/build-option surface and exact file-name filters.

Validation

  • Terminal Suggest extension-host suite: 384 passing.
  • Terminal Suggest TypeScript no-emit check passed.
  • Upstream Cargo generation is byte-stable across repeated runs.

Fixes #336216.

@Muszic

Copy link
Copy Markdown
Contributor Author

Alex Ross (@alexr00) Bryan Chen (@bryanchen-d) review and merge the PR please

@meganrogge Megan Rogge (meganrogge) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

@meganrogge Megan Rogge (meganrogge) added this to the 1.116.0 milestone Apr 8, 2026
@meganrogge Megan Rogge (meganrogge) added the feature-request Request for new features or functionality label Apr 8, 2026
@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) April 8, 2026 18:04
@alexr00 Alex Ross (alexr00) removed this from the 1.116.0 milestone Apr 13, 2026
Copilot AI review requested due to automatic review settings May 9, 2026 09:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new cargo completion spec to the terminal-suggest extension, including dynamic feature-name suggestions sourced from the local project, and wires it into the spec registry and test runner.

Changes:

  • Added a new cargo completion spec with common subcommands/options and a cargo read-manifest-based feature generator for --features.
  • Registered the new spec in the extension’s availableSpecs.
  • Added a dedicated test suite and included it in the main terminal-suggest test runner.
Show a summary per file
File Description
extensions/terminal-suggest/src/terminalSuggestMain.ts Registers the new cargo completion spec in availableSpecs.
extensions/terminal-suggest/src/completions/cargo.ts Implements cargo subcommands/options and a dynamic generator for --features.
extensions/terminal-suggest/src/test/completions/cargo.test.ts Adds basic completion coverage for the cargo spec.
extensions/terminal-suggest/src/test/terminalSuggestMain.test.ts Wires the new cargo test suite into the aggregated runner.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 2

Comment thread extensions/terminal-suggest/src/completions/cargo.ts Outdated
Comment thread extensions/terminal-suggest/src/completions/cargo.ts Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sangeet (@Muszic) Could you please address Copilot's comments and look at the failing CI?

auto-merge was automatically disabled June 1, 2026 16:07

Head branch was pushed to by a user without write access

@Muszic
Sangeet (Muszic) force-pushed the feature/terminal-suggest-cargo-clean branch from cfb675a to 963ab34 Compare June 1, 2026 16:07
@Muszic

Copy link
Copy Markdown
Contributor Author

Dmitriy Vasyura (@dmitrivMS) Could you please review the PR , I have addressed all the comments

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Sangeet (@Muszic) Thanks for working on this! Would you be so kind as to review the AI feedback below? My understanding is if not all, but most points make sense:


1. --features is on the wrong level

const cargoSpec: Fig.Spec = {
    name: 'cargo',
    subcommands: [ /* build, run, test, ... */ ],
    options: [
        { name: ['-F', '--features'], args: { generators: cargoFeaturesGenerator } },
        ...
    ]
};

These options apply to top-level cargo only, not to subcommands. Nobody types cargo --features foo — it's cargo build --features foo, cargo test --features foo, cargo run --features foo, etc. As written, the dynamic feature generator never actually fires in real usage. Could persistentOptions work instead, or pushing --features onto each of build / run / test / check / bench / clippy / install / doc?

2. Coverage is thin for a daily Rust user

The spec lists ~14 subcommands and 5 options. Cargo has ~30 subcommands and most of the value of completions is the per-subcommand option set. Missing in particular:

  • Subcommands: bench, install, uninstall, search, tree, metadata, package, yank, owner, fix, rustc, rustdoc, generate-lockfile, vendor, login, logout, locate-project, pkgid.
  • Options users hit constantly: --release, --profile, --target, --target-dir, --manifest-path, --workspace, -p/--package, --bin, --lib, --example, --test, --bench, -j/--jobs, --offline, --locked, --frozen, -v/-vv/-q.

Have you looked at whether we can adopt the upstream withfig/autocomplete cargo spec into src/completions/upstream/ instead? That's the pattern we use for other large specs (see src/completions/upstream/git.ts / docker.ts / dotnet.ts) — it's much more complete and we get upstream fixes for free. Hand-rolling cargo here means we own the maintenance forever and we're already shipping with most of the surface missing.

3. Cache TTL of 5s is too aggressive

cache: {
    strategy: 'stale-while-revalidate',
    ttl: 5_000,
    cacheByDirectory: true
},

cargo read-manifest is not cheap on cold cache (hundreds of ms in larger workspaces), and Cargo.toml doesn't change every 5s. Could we bump this to a minute or two? Even better: invalidate on Cargo.toml file change rather than time-based.

4. console.error in the generator

} catch (e) {
    console.error('Failed to parse cargo manifest:', e);
    return [];
}

This shouldn't go through console.error — it'll just be noise. Either drop it or route it through the extension's logger if there is one. The test suite will run this code path repeatedly.


@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) June 5, 2026 16:13
Replace the hand-written Cargo completion with the complete upstream Fig spec and support exact file-name resource filters used by Cargo manifest options.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dmitrivMS Dmitriy Vasyura (dmitrivMS) changed the title Added new terminal-suggest completion spec for cargo (Rust's package manager), providing intelligent autocompletion for Cargo's subcommands and options. feat(terminal-suggest): Add upstream Cargo completion spec Sep 6, 2026
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Megan Rogge (@meganrogge) This is what a full spec looks like. Do we like?

@boedysutris-ctrl

boedysutris-ctrl commented Sep 6, 2026 via email

Copy link
Copy Markdown

@dmitrivMS Dmitriy Vasyura (dmitrivMS) added terminal General terminal issues that don't fall under another label terminal-suggest and removed feature-request Request for new features or functionality labels Sep 12, 2026
@dmitrivMS Dmitriy Vasyura (dmitrivMS) changed the title feat(terminal-suggest): Add upstream Cargo completion spec Add upstream Cargo completion spec for terminal suggestions Sep 13, 2026
@meganrogge
Megan Rogge (meganrogge) merged commit 71e0a3d into microsoft:main Sep 15, 2026
33 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.139.0 milestone Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

terminal General terminal issues that don't fall under another label terminal-suggest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal suggest: Add Cargo completions

9 participants