feat: add dependency feature lookup by used version#12
Open
Jinghao-Tu wants to merge 2 commits intoBarbossHack:masterfrom
Open
feat: add dependency feature lookup by used version#12Jinghao-Tu wants to merge 2 commits intoBarbossHack:masterfrom
Jinghao-Tu wants to merge 2 commits intoBarbossHack:masterfrom
Conversation
There was a problem hiding this comment.
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 /.versionhere 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
featuresarray triggers suggestions; selecting the desired feature and pressing Enter completes the auto-completion.Ignore the two lines of double quotes. They were created by "even better toml" extension. :)
I referenced the specification of the tombi cargo extension.
To be honest, the code was generated by GPT-5.3, and I only did some simple checks and tests.