Skip to content

Commit 877c39d

Browse files
committed
docs
1 parent 0dc68a9 commit 877c39d

File tree

1 file changed

+59
-7
lines changed

1 file changed

+59
-7
lines changed

crates/project-model/src/project_json.rs

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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,81 @@ 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 analagous to [ManifestPath], but none of the indexing/loading
112+
/// operations can be directly applied/used with this file.
103113
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.
114+
/// The kind of target.
115+
///
116+
/// Examples (non-exhaustively) include [TargetKind::Bin], [TargetKind::Lib],
117+
/// and [TargetKind::Test]. This information is used to determine what sort
118+
/// runnable codelens to provide, if any.
106119
pub target_kind: TargetKind,
107120
}
108121

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

163+
/// The kind of runnable.
117164
#[derive(Debug, Clone, PartialEq, Eq)]
118165
pub enum RunnableKind {
119166
Check,
167+
168+
/// Can run a binary.
120169
Run,
170+
171+
/// Run a single test.
121172
TestOne,
122173
}
123174

@@ -126,6 +177,7 @@ impl ProjectJson {
126177
///
127178
/// # Arguments
128179
///
180+
/// * `manifest` - The path to the `rust-project.json`.
129181
/// * `base` - The path to the workspace root (i.e. the folder containing `rust-project.json`)
130182
/// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via
131183
/// configuration.

0 commit comments

Comments
 (0)