Skip to content

feat: add dependency feature lookup by used version#12

Open
Jinghao-Tu wants to merge 2 commits intoBarbossHack:masterfrom
Jinghao-Tu:feature/feature-completion-impl
Open

feat: add dependency feature lookup by used version#12
Jinghao-Tu wants to merge 2 commits intoBarbossHack:masterfrom
Jinghao-Tu:feature/feature-completion-impl

Conversation

@Jinghao-Tu
Copy link

I've added a new feature that queries dependencies' features by used version, along with suggestions and auto-completion.

Entering a comma or double quote in the features array triggers suggestions; selecting the desired feature and pressing Enter completes the auto-completion.

screen_shot_2026-02-28-17-12-45

Ignore the two lines of double quotes. They were created by "even better toml" extension. :)

I referenced the specification of the tombi cargo extension.

  1. Fetches available features from:crates.io for registry dependencies;Local Cargo.toml for path dependencies;Workspace Cargo.toml for workspace dependencies
  2. Filters out already selected features
  3. default feature shown first, features starting with _ shown last
  4. context-aware: when a dependency uses workspace = true, it looks up features from the workspace definition.

To be honest, the code was generated by GPT-5.3, and I only did some simple checks and tests.

Copilot AI review requested due to automatic review settings February 28, 2026 09:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Cargo feature-aware UX (completion + diagnostics) by resolving available features for a dependency based on the used version requirement, with additional support for workspace/path dependencies.

Changes:

  • Resolve and expose dependency features (registry via sparse index + local/workspace via manifest parsing) and use them for feature completion/diagnostics.
  • Update sparse index fetching to pick features from the max-satisfying version (plus improved caching dimensions).
  • Extend TOML parsing and dependency indexing to better represent workspace/path dependencies and disambiguate duplicates.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/ui/featureDiagnostics.ts New diagnostics pass to warn about unknown selected features.
src/toml/parser.ts Extends dependency parsing to carry path / workspace and include non-version deps.
src/providers/autoCompletion.ts Reworks feature completion to be context-aware, filtered, and sorted; uses resolved dep.features.
src/extension.ts Registers feature completion provider triggers.
src/core/listener.ts Passes Cargo.toml path to fetcher and runs feature diagnostics after decoration.
src/core/fetcher.ts Builds fetchedDepsMap by key; resolves local/workspace features; passes version requirement into sparse fetch.
src/core/featureSources.ts New helpers to read features from local/workspace manifests.
src/core/Item.ts Adds path and workspace fields to parsed items.
src/core/Dependency.ts Replaces version-keyed feature completion items with a plain features list.
src/api/sparse-index-server.ts Resolves features for the max-satisfying version and expands cache key dimensions.
src/api/crateMetadatas.ts Makes features optional in the metadata type.
Comments suppressed due to low confidence (1)

src/toml/parser.ts:75

  • Removing the skip for keys ending in ".workspace" / ".path" means dotted keys like foo.path = "../foo" (and similar .registry, .package, etc.) will be treated as standalone dependencies and fetched from crates.io under the wrong crate name (e.g. "foo.path"), which can lead to request failures and incorrect diagnostics/completions. Reintroduce filtering for non-version dotted dependency fields (or only accept plain keys / .version here and ignore other dotted keys).
function findVersion(item: Item): Item[] {
  let dependencies: Item[] = [];
  for (const field of item.values) {
    if (field.values.length > 0) {
      const dependency = findVersionTable(field);
      if (dependency) dependencies.push(dependency);
    } else if (field.value != null) {
      if (field.key.endsWith(".version")) field.key = field.key.replace(".version", "");
      dependencies.push(field)
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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