manual: Document all rust-project.json fields

Ensure that all the fields that rust-analyzer understands are in the
manual, they all have doc comments, and they use consistent
punctuation (`;` rather than mixing `,` and `;`).

Whilst we're here, fix the `sysroot_src` example and add 2024 as a
legal value for Rust edition.
This commit is contained in:
Wilfred Hughes 2025-01-07 16:37:49 -08:00
parent 0b68402d78
commit 86a4b2fdd7
2 changed files with 84 additions and 8 deletions

View file

@ -63,7 +63,7 @@ use crate::{ManifestPath, TargetKind};
pub struct ProjectJson { pub struct ProjectJson {
/// e.g. `path/to/sysroot` /// e.g. `path/to/sysroot`
pub(crate) sysroot: Option<AbsPathBuf>, pub(crate) sysroot: Option<AbsPathBuf>,
/// e.g. `path/to/sysroot/lib/rustlib/src/rust` /// e.g. `path/to/sysroot/lib/rustlib/src/rust/library`
pub(crate) sysroot_src: Option<AbsPathBuf>, pub(crate) sysroot_src: Option<AbsPathBuf>,
project_root: AbsPathBuf, project_root: AbsPathBuf,
/// The path to the rust-project.json file. May be None if this /// The path to the rust-project.json file. May be None if this

View file

@ -716,6 +716,32 @@ interface JsonProject {
/// dependencies as well as sysroot crate (libstd, /// dependencies as well as sysroot crate (libstd,
/// libcore and such). /// libcore and such).
crates: Crate[]; crates: Crate[];
/// Configuration for CLI commands.
///
/// These are used for running and debugging binaries
/// and tests without encoding build system-specific
/// knowledge into rust-analyzer.
///
/// # Example
///
/// Below is an example of a test runnable. `{label}` and `{test_id}`
/// are explained in `Runnable::args`'s documentation below.
///
/// ```json
/// {
/// "program": "buck",
/// "args": [
/// "test",
/// "{label}",
/// "--",
/// "{test_id}",
/// "--print-passing-details"
/// ],
/// "cwd": "/home/user/repo-root/",
/// "kind": "testOne"
/// }
/// ```
runnables?: Runnable[];
} }
interface Crate { interface Crate {
@ -726,7 +752,10 @@ interface Crate {
/// Path to the root module of the crate. /// Path to the root module of the crate.
root_module: string; root_module: string;
/// Edition of the crate. /// Edition of the crate.
edition: "2015" | "2018" | "2021"; edition: '2015' | '2018' | '2021' | '2024';
/// The version of the crate. Used for calculating
/// the correct docs.rs URL.
version?: string;
/// Dependencies /// Dependencies
deps: Dep[]; deps: Dep[];
/// Should this crate be treated as a member of /// Should this crate be treated as a member of
@ -757,9 +786,9 @@ interface Crate {
/// rust-analyzer assumes that files from one /// rust-analyzer assumes that files from one
/// source can't refer to files in another source. /// source can't refer to files in another source.
source?: { source?: {
include_dirs: string[], include_dirs: string[];
exclude_dirs: string[], exclude_dirs: string[];
}, };
/// List of cfg groups this crate inherits. /// List of cfg groups this crate inherits.
/// ///
/// All cfg in these groups will be concatenated to /// All cfg in these groups will be concatenated to
@ -776,21 +805,68 @@ interface Crate {
target?: string; target?: string;
/// Environment variables, used for /// Environment variables, used for
/// the `env!` macro /// the `env!` macro
env: { [key: string]: string; }, env: { [key: string]: string; };
/// Whether the crate is a proc-macro crate. /// Whether the crate is a proc-macro crate.
is_proc_macro: boolean; is_proc_macro: boolean;
/// For proc-macro crates, path to compiled /// For proc-macro crates, path to compiled
/// proc-macro (.so file). /// proc-macro (.so file).
proc_macro_dylib_path?: string; proc_macro_dylib_path?: string;
/// Repository, matching the URL that would be used
/// in Cargo.toml.
repository?: string;
/// Build-specific data about this crate.
build?: BuildInfo;
} }
interface Dep { interface Dep {
/// Index of a crate in the `crates` array. /// Index of a crate in the `crates` array.
crate: number, crate: number;
/// Name as should appear in the (implicit) /// Name as should appear in the (implicit)
/// `extern crate name` declaration. /// `extern crate name` declaration.
name: string, name: string;
}
interface BuildInfo {
/// The name associated with this crate.
///
/// This is determined by the build system that produced
/// the `rust-project.json` in question. For instance, if buck were used,
/// the label might be something like `//ide/rust/rust-analyzer:rust-analyzer`.
///
/// Do not attempt to parse the contents of this string; it is a build system-specific
/// identifier similar to `Crate::display_name`.
label: string;
/// Path corresponding to the build system-specific file defining the crate.
build_file: string;
/// The kind of target.
///
/// This information is used to determine what sort
/// of runnable codelens to provide, if any.
target_kind: 'bin' | 'lib' | 'test';
}
interface Runnable {
/// The program invoked by the runnable.
///
/// For example, this might be `cargo`, `buck`, or `bazel`.
program: string;
/// The arguments passed to `program`.
args: string[];
/// The current working directory of the runnable.
cwd: string;
/// Used to decide what code lens to offer.
///
/// `testOne`: This runnable will be used when the user clicks the 'Run Test'
/// CodeLens above a test.
///
/// The args for testOne can contain two template strings:
/// `{label}` and `{test_id}`. `{label}` will be replaced
/// with the `Build::label` and `{test_id}` will be replaced
/// with the test name.
kind: 'testOne' | string;
} }
---- ----