33
33
//!
34
34
//! * file on disk
35
35
//! * 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)
37
37
//!
38
38
//! Another possible thing we don't do today, but which would be totally valid,
39
39
//! is to add an extension point to VS Code extension to register custom
@@ -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,82 @@ 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 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`.
103
114
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.
106
120
pub target_kind : TargetKind ,
107
121
}
108
122
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
+ /// ```
109
147
#[ derive( Debug , Clone , PartialEq , Eq ) ]
110
148
pub struct Runnable {
149
+ /// The program invoked by the runnable.
150
+ ///
151
+ /// For example, this might be `cargo`, `buck`, or `bazel`.
111
152
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.
112
158
pub args : Vec < String > ,
159
+ /// The current working directory of the runnable.
113
160
pub cwd : Utf8PathBuf ,
114
161
pub kind : RunnableKind ,
115
162
}
116
163
164
+ /// The kind of runnable.
117
165
#[ derive( Debug , Clone , PartialEq , Eq ) ]
118
166
pub enum RunnableKind {
119
167
Check ,
168
+
169
+ /// Can run a binary.
120
170
Run ,
171
+
172
+ /// Run a single test.
121
173
TestOne ,
122
174
}
123
175
@@ -126,6 +178,7 @@ impl ProjectJson {
126
178
///
127
179
/// # Arguments
128
180
///
181
+ /// * `manifest` - The path to the `rust-project.json`.
129
182
/// * `base` - The path to the workspace root (i.e. the folder containing `rust-project.json`)
130
183
/// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via
131
184
/// configuration.
0 commit comments