tombi-extension-cargo
Tombi is written in Rust, and we want to make the Rust development experience even better 🦀
Experimentally, we provide additional features when editing Cargo.toml
files.
Supported Features
Code Completion
The extension provides intelligent code completion for Cargo.toml
files.
Crate Version Completion
Get version suggestions when specifying crate versions:
[dependencies]
serde = "1.0.130" # <- version suggestions appear here
tokio = { version = "1.21.0" } # <- also here
Features:
- Fetches available versions from crates.io
- Shows up to 100 versions sorted newest first
- Works in all dependency sections (
dependencies
,dev-dependencies
,build-dependencies
,workspace.dependencies
)
Crate Feature Completion
Get feature suggestions when specifying crate features:
[dependencies]
serde = { version = "1.0", features = ["derive"] } # <- feature suggestions
tokio = { version = "1.21", features = ["full", "net"] } # <- in array
Features:
- Fetches available features from:
- crates.io for registry dependencies
- Local
Cargo.toml
for path dependencies - Workspace
Cargo.toml
for workspace dependencies
- Shows feature dependencies in documentation
- Filters out already selected features
default
feature shown first, features starting with_
shown last
The extension is context-aware: when a dependency uses workspace = true
, it looks up features from the workspace definition.
Go to Definition
For example, suppose you have a Cargo.toml
like the one below:
Go to workspace/crate definition from dependencies
[dependencies]
serde = { workspace = true }
tombi-ast = { workspace = true }
In this case, when your cursor is on workspace
, executing "Go to Definition" will navigate you to the workspace definition or to the crate definition managed by the workspace.
In the example above, for serde
(an external crate), you'll be navigated to the workspace definition, while for tombi-ast
(a crate managed by the workspace), you'll be navigated to the crate definition.
If you consistently want to navigate to the workspace's Cargo.toml
, use "Go to Declaration".
Go to crate definition from workspace.dependencies
[workspace.dependencies]
tombi-ast = { path = "crates/tombi-ast" }
In this case, when your cursor is on path
, executing "Go to Definition" will navigate you to the crate definition.
Go to Declaration
[dependencies]
serde = { workspace = true }
tombi-ast = { workspace = true }
In this case, when your cursor is on workspace
, executing "Go to Declaration" will navigate you to the crate definition.
Code Actions
When working with Cargo.toml
files, additional code actions are available.
Inherit from Workspace
Convert package fields to inherit from workspace configuration:
# Before
[package]
version = "1.0.0"
authors = ["John Doe"]
# After applying "Inherit from workspace"
[package]
version.workspace = true
authors.workspace = true
Inherit Dependency from Workspace
Convert dependencies to use workspace versions:
# Before
[dependencies]
serde = "1.0"
# After applying "Inherit dependency from workspace"
[dependencies]
serde = { workspace = true }
Convert Dependency to Table Format
Transform simple string dependencies to table format for adding additional fields:
# Before
[dependencies]
serde = "1.0"
# After applying "Convert to table format"
[dependencies]
serde = { version = "1.0" }