Skip to content

Commit 2b47745

Browse files
committed
docs
1 parent 0dc68a9 commit 2b47745

File tree

1 file changed

+61
-8
lines changed

1 file changed

+61
-8
lines changed

crates/project-model/src/project_json.rs

+61-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//!
3434
//! * file on disk
3535
//! * a field in the config (ie, you can send a JSON request with the contents
36-
//! of rust-project.json to rust-analyzer, no need to write anything to disk)
36+
//! of `rust-project.json` to rust-analyzer, no need to write anything to disk)
3737
//!
3838
//! Another possible thing we don't do today, but which would be totally valid,
3939
//! is to add an extension point to VS Code extension to register custom
@@ -67,8 +67,9 @@ pub struct ProjectJson {
6767
project_root: AbsPathBuf,
6868
manifest: Option<ManifestPath>,
6969
crates: Vec<Crate>,
70-
/// Configuration for commands, such as CLI invocations for
71-
/// a check build or a test run.
70+
/// Configuration for CLI commands.
71+
///
72+
/// Examples include a check build or a test run.
7273
runnables: Vec<Runnable>,
7374
}
7475

@@ -93,31 +94,82 @@ pub struct Crate {
9394
pub build: Option<Build>,
9495
}
9596

96-
/// Additional metadata about a crate, used to configure runnables.
97+
/// Additional, build-specific data about a crate.
9798
#[derive(Clone, Debug, Eq, PartialEq)]
9899
pub struct Build {
99-
/// The name associated with this crate, according to the custom
100-
/// build system being used.
100+
/// The name associated with this crate.
101+
///
102+
/// This is determined by the build system that produced
103+
/// the `rust-project.json` in question. For instance, if buck were used,
104+
/// the label might be something like `//ide/rust/rust-analyzer:rust-analyzer`.
105+
///
106+
/// Do not attempt to parse the contents of this string; it is a build system-specific
107+
/// identifier similar to [`Crate::display_name`].
101108
pub label: String,
102109
/// Path corresponding to the build system-specific file defining the crate.
110+
///
111+
/// It is roughly analogous to [`ManifestPath`], but it should *not* be used with
112+
/// [`crate::ProjectManifest::from_manifest_file`], as the build file may not be
113+
/// be in the `rust-project.json`.
103114
pub build_file: Utf8PathBuf,
104-
/// What kind of target is this crate? For example, we don't want
105-
/// to offer a 'run' button for library crates.
115+
/// The kind of target.
116+
///
117+
/// Examples (non-exhaustively) include [`TargetKind::Bin`], [`TargetKind::Lib`],
118+
/// and [`TargetKind::Test`]. This information is used to determine what sort
119+
/// of runnable codelens to provide, if any.
106120
pub target_kind: TargetKind,
107121
}
108122

123+
/// A template-like structure for describing runnables.
124+
///
125+
/// These are used for running and debugging binaries and tests without encoding
126+
/// build system-specific knowledge into rust-analyzer.
127+
///
128+
/// # Example
129+
///
130+
/// Below is an example of a test runnable. `{label}` and `{test_id}`
131+
/// are explained in [`Runnable::args`]'s documentation.
132+
///
133+
/// ```json
134+
/// {
135+
/// "program": "buck",
136+
/// "args": [
137+
/// "test",
138+
/// "{label}",
139+
/// "--",
140+
/// "{test_id}",
141+
/// "--print-passing-details"
142+
/// ],
143+
/// "cwd": "/home/user/repo-root/",
144+
/// "kind": "testOne"
145+
/// }
146+
/// ```
109147
#[derive(Debug, Clone, PartialEq, Eq)]
110148
pub struct Runnable {
149+
/// The program invoked by the runnable.
150+
///
151+
/// For example, this might be `cargo`, `buck`, or `bazel`.
111152
pub program: String,
153+
/// The arguments passed to [`Runnable::program`].
154+
///
155+
/// The args can contain two template strings: `{label}` and `{test_id}`.
156+
/// rust-analyzer will find and replace `{label}` with [`Build::label`] and
157+
/// `{test_id}` with the test name.
112158
pub args: Vec<String>,
159+
/// The current working directory of the runnable.
113160
pub cwd: Utf8PathBuf,
114161
pub kind: RunnableKind,
115162
}
116163

164+
/// The kind of runnable.
117165
#[derive(Debug, Clone, PartialEq, Eq)]
118166
pub enum RunnableKind {
119167
Check,
168+
169+
/// Can run a binary.
120170
Run,
171+
172+
/// Run a single test.
121173
TestOne,
122174
}
123175

@@ -126,6 +178,7 @@ impl ProjectJson {
126178
///
127179
/// # Arguments
128180
///
181+
/// * `manifest` - The path to the `rust-project.json`.
129182
/// * `base` - The path to the workspace root (i.e. the folder containing `rust-project.json`)
130183
/// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via
131184
/// configuration.

0 commit comments

Comments
 (0)