Skip to content

Commit 34d9409

Browse files
committed
Auto merge of #17831 - Veykril:flycheck-move-to-rust-analyzer, r=Veykril
internal: Move and split flycheck crate into rust-analyzer main crate The crate no longer is about flychecking, it mainly hosts common command process handling shared by flycheck, test explorer and now project discovery. This re-organizes that into the main crate.
2 parents b02c6bf + 6bb29b1 commit 34d9409

File tree

16 files changed

+252
-303
lines changed

16 files changed

+252
-303
lines changed

Cargo.lock

Lines changed: 2 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ debug = 2
5252
# local crates
5353
base-db = { path = "./crates/base-db", version = "0.0.0" }
5454
cfg = { path = "./crates/cfg", version = "0.0.0", features = ["tt"] }
55-
flycheck = { path = "./crates/flycheck", version = "0.0.0" }
5655
hir = { path = "./crates/hir", version = "0.0.0" }
5756
hir-def = { path = "./crates/hir-def", version = "0.0.0" }
5857
hir-expand = { path = "./crates/hir-expand", version = "0.0.0" }

crates/flycheck/Cargo.toml

Lines changed: 0 additions & 31 deletions
This file was deleted.

crates/project-model/src/project_json.rs

Lines changed: 123 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
17777
impl 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)]
306306
pub 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

411434
impl 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-
472471
fn deserialize_crate_name<'de, D>(de: D) -> std::result::Result<CrateName, D::Error>
473472
where
474473
D: de::Deserializer<'de>,

crates/rust-analyzer/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ always-assert = "0.2.0"
4747
walkdir = "2.3.2"
4848
semver.workspace = true
4949
memchr = "2.7.1"
50+
cargo_metadata.workspace = true
51+
process-wrap.workspace = true
5052

5153
cfg.workspace = true
52-
flycheck.workspace = true
5354
hir-def.workspace = true
5455
hir-ty.workspace = true
5556
hir.workspace = true

crates/flycheck/src/command.rs renamed to crates/rust-analyzer/src/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//! Utilities for running a cargo command like `cargo check` or `cargo test` in a separate thread and
2-
//! parse its stdout/stderr.
1+
//! Utilities for running a cargo command like `cargo check` or `cargo test` in a separate thread
2+
//! and parse its stdout/stderr.
33
44
use std::{
55
ffi::OsString,

0 commit comments

Comments
 (0)