@@ -74,106 +74,6 @@ pub struct ProjectJson {
7474 runnables : Vec < Runnable > ,
7575}
7676
77- /// A crate points to the root module of a crate and lists the dependencies of the crate. This is
78- /// useful in creating the crate graph.
79- #[ derive( Clone , Debug , Eq , PartialEq ) ]
80- pub struct Crate {
81- pub ( crate ) display_name : Option < CrateDisplayName > ,
82- pub root_module : AbsPathBuf ,
83- pub ( crate ) edition : Edition ,
84- pub ( crate ) version : Option < String > ,
85- pub ( crate ) deps : Vec < Dep > ,
86- pub ( crate ) cfg : Vec < CfgAtom > ,
87- pub ( crate ) target : Option < String > ,
88- pub ( crate ) env : FxHashMap < String , String > ,
89- pub ( crate ) proc_macro_dylib_path : Option < AbsPathBuf > ,
90- pub ( crate ) is_workspace_member : bool ,
91- pub ( crate ) include : Vec < AbsPathBuf > ,
92- pub ( crate ) exclude : Vec < AbsPathBuf > ,
93- pub ( crate ) is_proc_macro : bool ,
94- pub ( crate ) repository : Option < String > ,
95- pub build : Option < Build > ,
96- }
97-
98- /// Additional, build-specific data about a crate.
99- #[ derive( Clone , Debug , Eq , PartialEq ) ]
100- pub struct Build {
101- /// The name associated with this crate.
102- ///
103- /// This is determined by the build system that produced
104- /// the `rust-project.json` in question. For instance, if buck were used,
105- /// the label might be something like `//ide/rust/rust-analyzer:rust-analyzer`.
106- ///
107- /// Do not attempt to parse the contents of this string; it is a build system-specific
108- /// identifier similar to [`Crate::display_name`].
109- pub label : String ,
110- /// Path corresponding to the build system-specific file defining the crate.
111- ///
112- /// It is roughly analogous to [`ManifestPath`], but it should *not* be used with
113- /// [`crate::ProjectManifest::from_manifest_file`], as the build file may not be
114- /// be in the `rust-project.json`.
115- pub build_file : Utf8PathBuf ,
116- /// The kind of target.
117- ///
118- /// Examples (non-exhaustively) include [`TargetKind::Bin`], [`TargetKind::Lib`],
119- /// and [`TargetKind::Test`]. This information is used to determine what sort
120- /// of runnable codelens to provide, if any.
121- pub target_kind : TargetKind ,
122- }
123-
124- /// A template-like structure for describing runnables.
125- ///
126- /// These are used for running and debugging binaries and tests without encoding
127- /// build system-specific knowledge into rust-analyzer.
128- ///
129- /// # Example
130- ///
131- /// Below is an example of a test runnable. `{label}` and `{test_id}`
132- /// are explained in [`Runnable::args`]'s documentation.
133- ///
134- /// ```json
135- /// {
136- /// "program": "buck",
137- /// "args": [
138- /// "test",
139- /// "{label}",
140- /// "--",
141- /// "{test_id}",
142- /// "--print-passing-details"
143- /// ],
144- /// "cwd": "/home/user/repo-root/",
145- /// "kind": "testOne"
146- /// }
147- /// ```
148- #[ derive( Debug , Clone , PartialEq , Eq ) ]
149- pub struct Runnable {
150- /// The program invoked by the runnable.
151- ///
152- /// For example, this might be `cargo`, `buck`, or `bazel`.
153- pub program : String ,
154- /// The arguments passed to [`Runnable::program`].
155- ///
156- /// The args can contain two template strings: `{label}` and `{test_id}`.
157- /// rust-analyzer will find and replace `{label}` with [`Build::label`] and
158- /// `{test_id}` with the test name.
159- pub args : Vec < String > ,
160- /// The current working directory of the runnable.
161- pub cwd : Utf8PathBuf ,
162- pub kind : RunnableKind ,
163- }
164-
165- /// The kind of runnable.
166- #[ derive( Debug , Clone , PartialEq , Eq ) ]
167- pub enum RunnableKind {
168- Check ,
169-
170- /// Can run a binary.
171- Run ,
172-
173- /// Run a single test.
174- TestOne ,
175- }
176-
17777impl ProjectJson {
17878 /// Create a new ProjectJson instance.
17979 ///
@@ -302,6 +202,106 @@ impl ProjectJson {
302202 }
303203}
304204
205+ /// A crate points to the root module of a crate and lists the dependencies of the crate. This is
206+ /// useful in creating the crate graph.
207+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
208+ pub struct Crate {
209+ pub ( crate ) display_name : Option < CrateDisplayName > ,
210+ pub root_module : AbsPathBuf ,
211+ pub ( crate ) edition : Edition ,
212+ pub ( crate ) version : Option < String > ,
213+ pub ( crate ) deps : Vec < Dep > ,
214+ pub ( crate ) cfg : Vec < CfgAtom > ,
215+ pub ( crate ) target : Option < String > ,
216+ pub ( crate ) env : FxHashMap < String , String > ,
217+ pub ( crate ) proc_macro_dylib_path : Option < AbsPathBuf > ,
218+ pub ( crate ) is_workspace_member : bool ,
219+ pub ( crate ) include : Vec < AbsPathBuf > ,
220+ pub ( crate ) exclude : Vec < AbsPathBuf > ,
221+ pub ( crate ) is_proc_macro : bool ,
222+ pub ( crate ) repository : Option < String > ,
223+ pub build : Option < Build > ,
224+ }
225+
226+ /// Additional, build-specific data about a crate.
227+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
228+ pub struct Build {
229+ /// The name associated with this crate.
230+ ///
231+ /// This is determined by the build system that produced
232+ /// the `rust-project.json` in question. For instance, if buck were used,
233+ /// the label might be something like `//ide/rust/rust-analyzer:rust-analyzer`.
234+ ///
235+ /// Do not attempt to parse the contents of this string; it is a build system-specific
236+ /// identifier similar to [`Crate::display_name`].
237+ pub label : String ,
238+ /// Path corresponding to the build system-specific file defining the crate.
239+ ///
240+ /// It is roughly analogous to [`ManifestPath`], but it should *not* be used with
241+ /// [`crate::ProjectManifest::from_manifest_file`], as the build file may not be
242+ /// be in the `rust-project.json`.
243+ pub build_file : Utf8PathBuf ,
244+ /// The kind of target.
245+ ///
246+ /// Examples (non-exhaustively) include [`TargetKind::Bin`], [`TargetKind::Lib`],
247+ /// and [`TargetKind::Test`]. This information is used to determine what sort
248+ /// of runnable codelens to provide, if any.
249+ pub target_kind : TargetKind ,
250+ }
251+
252+ /// A template-like structure for describing runnables.
253+ ///
254+ /// These are used for running and debugging binaries and tests without encoding
255+ /// build system-specific knowledge into rust-analyzer.
256+ ///
257+ /// # Example
258+ ///
259+ /// Below is an example of a test runnable. `{label}` and `{test_id}`
260+ /// are explained in [`Runnable::args`]'s documentation.
261+ ///
262+ /// ```json
263+ /// {
264+ /// "program": "buck",
265+ /// "args": [
266+ /// "test",
267+ /// "{label}",
268+ /// "--",
269+ /// "{test_id}",
270+ /// "--print-passing-details"
271+ /// ],
272+ /// "cwd": "/home/user/repo-root/",
273+ /// "kind": "testOne"
274+ /// }
275+ /// ```
276+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
277+ pub struct Runnable {
278+ /// The program invoked by the runnable.
279+ ///
280+ /// For example, this might be `cargo`, `buck`, or `bazel`.
281+ pub program : String ,
282+ /// The arguments passed to [`Runnable::program`].
283+ ///
284+ /// The args can contain two template strings: `{label}` and `{test_id}`.
285+ /// rust-analyzer will find and replace `{label}` with [`Build::label`] and
286+ /// `{test_id}` with the test name.
287+ pub args : Vec < String > ,
288+ /// The current working directory of the runnable.
289+ pub cwd : Utf8PathBuf ,
290+ pub kind : RunnableKind ,
291+ }
292+
293+ /// The kind of runnable.
294+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
295+ pub enum RunnableKind {
296+ Check ,
297+
298+ /// Can run a binary.
299+ Run ,
300+
301+ /// Run a single test.
302+ TestOne ,
303+ }
304+
305305#[ derive( Serialize , Deserialize , Debug , Clone , Eq , PartialEq ) ]
306306pub struct ProjectJsonData {
307307 sysroot : Option < Utf8PathBuf > ,
@@ -407,6 +407,29 @@ pub enum TargetKindData {
407407 Lib ,
408408 Test ,
409409}
410+ /// Identifies a crate by position in the crates array.
411+ ///
412+ /// This will differ from `CrateId` when multiple `ProjectJson`
413+ /// workspaces are loaded.
414+ #[ derive( Serialize , Deserialize , Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
415+ #[ serde( transparent) ]
416+ pub struct CrateArrayIdx ( pub usize ) ;
417+
418+ #[ derive( Serialize , Deserialize , Debug , Clone , Eq , PartialEq ) ]
419+ pub ( crate ) struct Dep {
420+ /// Identifies a crate by position in the crates array.
421+ #[ serde( rename = "crate" ) ]
422+ pub ( crate ) krate : CrateArrayIdx ,
423+ #[ serde( serialize_with = "serialize_crate_name" ) ]
424+ #[ serde( deserialize_with = "deserialize_crate_name" ) ]
425+ pub ( crate ) name : CrateName ,
426+ }
427+
428+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Eq ) ]
429+ struct CrateSource {
430+ include_dirs : Vec < Utf8PathBuf > ,
431+ exclude_dirs : Vec < Utf8PathBuf > ,
432+ }
410433
411434impl From < TargetKindData > for TargetKind {
412435 fn from ( data : TargetKindData ) -> Self {
@@ -445,30 +468,6 @@ impl From<RunnableKindData> for RunnableKind {
445468 }
446469}
447470
448- /// Identifies a crate by position in the crates array.
449- ///
450- /// This will differ from `CrateId` when multiple `ProjectJson`
451- /// workspaces are loaded.
452- #[ derive( Serialize , Deserialize , Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
453- #[ serde( transparent) ]
454- pub struct CrateArrayIdx ( pub usize ) ;
455-
456- #[ derive( Serialize , Deserialize , Debug , Clone , Eq , PartialEq ) ]
457- pub ( crate ) struct Dep {
458- /// Identifies a crate by position in the crates array.
459- #[ serde( rename = "crate" ) ]
460- pub ( crate ) krate : CrateArrayIdx ,
461- #[ serde( serialize_with = "serialize_crate_name" ) ]
462- #[ serde( deserialize_with = "deserialize_crate_name" ) ]
463- pub ( crate ) name : CrateName ,
464- }
465-
466- #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq , Eq ) ]
467- struct CrateSource {
468- include_dirs : Vec < Utf8PathBuf > ,
469- exclude_dirs : Vec < Utf8PathBuf > ,
470- }
471-
472471fn deserialize_crate_name < ' de , D > ( de : D ) -> std:: result:: Result < CrateName , D :: Error >
473472where
474473 D : de:: Deserializer < ' de > ,
0 commit comments