A language server for Cargo.toml
's dependencies.
-
Diagnostic Hints - show hints for latest version for every dependency version (that is not the latest).
-
Info on Hover - show info about a create on hover in this format:
<NAME>: <LATEST_VERSION> <AVAILABLE_FEATURES> <DESCRIPTION>
-
Code Actions - a code action for updating a dependency version to latest.
-
Version Completion - open a version's quotation mark (
"
), and you'll be presented with a list of different granularities for the latest version, e.g., for a crate with the latest version0.1.3
, you'll be offered with the completions: [0.1.3
,0.1
,0
]. -
Features Completion - open a features' quotation mark inside the features array, and you'll be presented with a list of a crate's available features.
-
Goto definition opens docs.rs - invoke a
goto definition
event on a dependency name, and the crate's docs.rs page will be opened in your browser.
The bellow requirements are only when building from source or using cargo install
(i.e., you don't need these if you use the provided Nix flake).
This program uses nightly features, thus requiring using Nightly Rust to compile.
- Nightly rust
Also, this program vendors OpenSSL, which requires the following to build:
Note, the above are quite common, so you might want to check if you have them before installing.
Clone this repository:
git clone https://github.com/rotmh/crates-language-server.git
Then build the project:
cd crates-language-server
cargo build --release
Finally, make sure to put it somewhere in your $PATH
.
Add this repository as an input:
inputs = {
# ...
crates-ls.url = "github:rotmh/crates-language-server";
};
Then in the system packages (NixOS
) or the home packages (home-manager
):
[
# ...
(inputs.crates-ls.packages.${pkgs.system}.default)
]
Finally, rebuild your system.
NOTE: I will soon add this to crates.io and nixpkgs.
Define a new language server:
[language-server.crates-ls]
command = "crates-language-server"
Note: to use the above snippet, you must have the binary in your $PATH
, if you don't, you can also specify the full path to the binary.
Then define a language for Cargo.toml
, that uses this language server:
[[language]]
name = "crates"
scope = "source.toml"
file-types = [{ glob = "Cargo.toml" }]
injection-regex = "toml"
grammar = "toml"
language-servers = [ "crates-ls" ] # you can also add taplo here
Finally, we want to have definitions for highlights and such, thus we need to have an entry for the crates
language in the Helix runtime directory.
In your config directory (where you have your config.toml
for helix; $HOME/.config/helix
in Linux), add a runtime/queries/crates/
directory, and copy these files there. Essentially what we do is copy the toml
queries to a queries definition for our language (crates
).
Know how to integrate this LSP with neovim? Please issue a PR :)
Know how to integrate this LSP with VS Code? Please issue a PR :)
Know how to integrate this LSP with another editor? Your PR will be appreciated!
This project uses both crates.io's API, and the sparse index.
The API comes with limitations, notably a rate limit (1 request per second). This project respects this rate limit, and does not perform more than 1 request per second.
This limitation does not impacts the performance of the tool, because the API is only used for the crates' descriptions (and the sparse index, which is used for the rest of the crates data, does not enforce a rate limit).
PRs, issues, suggestions, and ideas are all appreciated and very welcome :)
This project is licensed under MIT.