@@ -67,8 +67,9 @@ pub struct ProjectJson {
67
67
project_root : AbsPathBuf ,
68
68
manifest : Option < ManifestPath > ,
69
69
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.
72
73
runnables : Vec < Runnable > ,
73
74
}
74
75
@@ -93,31 +94,81 @@ pub struct Crate {
93
94
pub build : Option < Build > ,
94
95
}
95
96
96
- /// Additional metadata about a crate, used to configure runnables .
97
+ /// Additional, build-specific data about a crate.
97
98
#[ derive( Clone , Debug , Eq , PartialEq ) ]
98
99
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].
101
108
pub label : String ,
102
109
/// 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.
103
113
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.
106
119
pub target_kind : TargetKind ,
107
120
}
108
121
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
+ /// ```
109
146
#[ derive( Debug , Clone , PartialEq , Eq ) ]
110
147
pub struct Runnable {
148
+ /// The program invoked by the runnable.
149
+ ///
150
+ /// For example, this might be `cargo`, `buck`, or `bazel`.
111
151
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.
112
157
pub args : Vec < String > ,
158
+ /// The current working directory of the runnable.
113
159
pub cwd : Utf8PathBuf ,
114
160
pub kind : RunnableKind ,
115
161
}
116
162
163
+ /// The kind of runnable.
117
164
#[ derive( Debug , Clone , PartialEq , Eq ) ]
118
165
pub enum RunnableKind {
119
166
Check ,
167
+
168
+ /// Can run a binary.
120
169
Run ,
170
+
171
+ /// Run a single test.
121
172
TestOne ,
122
173
}
123
174
@@ -126,6 +177,7 @@ impl ProjectJson {
126
177
///
127
178
/// # Arguments
128
179
///
180
+ /// * `manifest` - The path to the `rust-project.json`.
129
181
/// * `base` - The path to the workspace root (i.e. the folder containing `rust-project.json`)
130
182
/// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via
131
183
/// configuration.
0 commit comments