Language Server implementation targeted specifically towards the Cargo.toml
file of Rust projects, providing auto-completion for crate versions and
in-editor hints when the selected crate versions are out of date.
Project is heavily inspired by the crates plugin for VSCode.
In order to use crates-lsp
, you must:
- Install the
crates-lsp
binary somewhere on your machine. - Configure your editor to use the
crates-lsp
binary as a Language Server.
You can either download the pre-built crates-lsp
binary from a release,
or if you have Cargo (the Rust build tool) installed, you can build and install it yourself directly from crates.io:
cargo install --locked crates-lsp
This step is highly dependent on which editor you are using, see the guides below for known example configurations.
In most cases, these require crates-lsp
to be available in your $PATH
, or for you to specify the full path to it.
vim.lsp.config['crates'] = {
cmd = { 'crates-lsp' },
filetypes = { 'toml' },
root_markers = { 'Cargo.toml', '.git' },
init_options = {
-- Configuration options go here
}
}
[language-servers.crates-lsp]
except-features = ["format"]
# config = {} # Configuration options go here
[[language]]
name = "toml"
language-servers = [ "crates-lsp", "taplo" ]
formatter = { command = "taplo", args = ["fmt", "-"] }
See the Languages section of the Helix wiki, if you're unsure of where to put this.
See Lsp section of the Neovim wiki, if you're unsure of where to put this.
crates-lsp
has the following configuration options, which can be passed in from your editor (See Usage section above):
Option | Type | Default | Description |
---|---|---|---|
cache_directory |
string/path |
OS-specific crates-lsp cache directory |
Directory in which to cache information about available crate versions, to avoid constantly querying crates.io. Uses the OS-specific cache directory. See directories-rs |
files |
[string] |
["Cargo.toml"] |
List of exact filenames for which crates-lsp should provide feedback. Avoids crates-lsp throwing errors if you happen to open a toml file with a [dependencies] section, which does not contain Rust package names. |
use_api |
bool |
false |
If true, uses the Crates API instead of the Crate Index. There are almost no reasons to ever enable this, and doing so puts a lot more strain on the services provided by crates.io. Please don't! |
inlay_hints |
bool |
true |
If false, disables inlay hints. |
up_to_date_hint |
string |
✓ |
Text of inlay hint to show, when package is up to date. |
needs_update_hint |
string |
{} |
Text of inlay hint to show next to packages which should be updated. Any appearance of {} within the string, will be replaced by the newer version, which the package should be updated to. |
diagnostics |
bool |
true |
If false, disables diagnostics. |
unknown_dep_severity |
int |
2 (WARNING) |
Sets severity of diagnostics indicating that a package could not be looked up. See Diagnostic Severity |
needs_update_severity |
int |
3 (INFO) |
Sets severity of diagnostics indicating that a package needs to be updated. See Diagnostic Severity |
up_to_date_severity |
int |
4 (HINT) |
Sets severity of diagnostics indicating that a package is up to date. See Diagnostic Severity |
Integer indicating the severity to use when crates-lsp
conveys a diagnostic about packages, such as: Needs Update, Unknown Package, or Up To Date. The following severities are available:
1
ERROR2
WARNING3
INFORMATION4
HINT
These examples only showcase configuration options, and are not complete examples!
The init_options
field contains the crates-lsp
configuration options.
vim.lsp.config['crates'] = {
init_options = {
inlay_hints = false, -- Disable inlay hints entirely
needs_update_severity = 1 -- Report necessary updates as ERRORs
}
}
[language-server.crates-lsp]
# Disable inlay hints, Report necessary updates as ERRORs
config = { inlay_hints = false, needs_update_severity = 1 }