feat(cargo): add auto-completion for dependency feature names in Cargo.toml#83
Merged
feat(cargo): add auto-completion for dependency feature names in Cargo.toml#83
Conversation
…o.toml Implement LSP completion for feature names inside `features = [...]` arrays in Cargo.toml dependency entries. When the cursor is positioned inside a features array, the server now detects this context and returns feature names fetched from the crates.io sparse index. Changes: - Add `features_range() -> Option<Range>` to the `Dependency` trait in deps-core with a default `None` implementation so other ecosystems are unaffected - Implement `features_range()` in `ParsedDependency` (deps-cargo) using the range already tracked by the TOML parser - Replace the TODO in `detect_completion_context` (deps-core) with feature detection: if cursor is within `features_range`, return `CompletionContext::Feature` with the partial prefix extracted via the new `extract_feature_prefix` helper - Add `extract_feature_prefix` that scans backwards from the cursor to the last unmatched `"` on the current line, handling both inline and multi-line feature arrays - Add unit tests for `detect_completion_context`, `extract_feature_prefix`, and the `features_range` trait integration Closes #82
1 task
There was a problem hiding this comment.
Pull request overview
Adds Cargo-specific LSP completion for dependency feature names by exposing the features = [...] value range through the generic Dependency trait and using it during completion-context detection.
Changes:
- Extend
deps-core’sDependencytrait withfeatures_range()(defaulting toNonefor non-supporting ecosystems). - Implement feature-context detection in
detect_completion_context, including a newextract_feature_prefixhelper and unit tests. - Wire Cargo’s parsed dependency type to expose
features_range, and document the feature in the changelog.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| crates/deps-core/src/ecosystem.rs | Adds features_range() to the Dependency trait with a default None implementation. |
| crates/deps-core/src/completion.rs | Detects feature completion context, adds extract_feature_prefix, and adds tests covering feature-context detection/prefix extraction. |
| crates/deps-cargo/src/types.rs | Implements features_range() for Cargo parsed dependencies. |
| CHANGELOG.md | Documents the new Cargo feature-name completion under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…traction - extract_feature_prefix: count quotes after the last '[' to detect whether cursor is inside a string; return empty when it is not (prevents returning garbage from version quotes like '"1"' when cursor is between items, e.g. `["full", |]`) - Mark doctest as no_run to avoid brittle hard-coded character offsets - Fix comment: remove incorrect "unescaped" qualifier - features_range(): use imported Range alias instead of qualified path - Add tests: cursor between items, cursor after opening bracket
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.
Summary
features = [...]arrays in Cargo.toml (closes Add auto-completion for dependency features in Cargo.toml #82)features_range()to theDependencytrait so feature position is accessible generically; other ecosystems default toNoneand are unaffectedextract_feature_prefixhelper that extracts the partial feature string typed at cursor position, handling both inline and multi-line arrayscomplete_featuresandbuild_feature_completioninfrastructure indeps-cargo/deps-corewas already in place — this PR wires up the missing context detection stepTest plan
extract_feature_prefix(basic, empty, multi-line, no-quote cases)detect_completion_contextwithFeaturecontext (inline, empty prefix, second item, outside range)cargo nextest run --workspace --all-features --lib --bins)cargo clippy --all-targets --all-features --workspace -- -D warningscleancargo +nightly fmt --checkcleanCargo.toml, addserde = { version = "1", features = ["and trigger completion — should showderive,std, etc.