Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1114de0

Browse files
committed
Move flycheck crate into rust-analyzer main crate
1 parent fe4d83c commit 1114de0

File tree

15 files changed

+71
-113
lines changed

15 files changed

+71
-113
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -423,23 +423,6 @@ dependencies = [
423423
"miniz_oxide",
424424
]
425425

426-
[[package]]
427-
name = "flycheck"
428-
version = "0.0.0"
429-
dependencies = [
430-
"cargo_metadata",
431-
"crossbeam-channel",
432-
"paths",
433-
"process-wrap",
434-
"project-model",
435-
"rustc-hash",
436-
"serde",
437-
"serde_json",
438-
"stdx",
439-
"toolchain",
440-
"tracing",
441-
]
442-
443426
[[package]]
444427
name = "form_urlencoded"
445428
version = "1.2.1"
@@ -1650,12 +1633,12 @@ version = "0.0.0"
16501633
dependencies = [
16511634
"always-assert",
16521635
"anyhow",
1636+
"cargo_metadata",
16531637
"cfg",
16541638
"crossbeam-channel",
16551639
"dirs",
16561640
"dissimilar",
16571641
"expect-test",
1658-
"flycheck",
16591642
"hir",
16601643
"hir-def",
16611644
"hir-ty",
@@ -1676,6 +1659,7 @@ dependencies = [
16761659
"parser",
16771660
"paths",
16781661
"proc-macro-api",
1662+
"process-wrap",
16791663
"profile",
16801664
"project-model",
16811665
"rayon",

src/tools/rust-analyzer/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" }

src/tools/rust-analyzer/crates/flycheck/Cargo.toml

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

src/tools/rust-analyzer/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

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{fmt, iter, ops::Not, sync::OnceLock};
77

88
use cfg::{CfgAtom, CfgDiff};
99
use dirs::config_dir;
10-
use flycheck::{CargoOptions, FlycheckConfig};
1110
use hir::Symbol;
1211
use ide::{
1312
AssistConfig, CallableSnippets, CompletionConfig, DiagnosticsConfig, ExprFillDefaultMode,
@@ -37,6 +36,7 @@ use vfs::{AbsPath, AbsPathBuf, VfsPath};
3736
use crate::{
3837
capabilities::ClientCapabilities,
3938
diagnostics::DiagnosticsMapConfig,
39+
flycheck::{CargoOptions, FlycheckConfig},
4040
lsp_ext::{WorkspaceSymbolSearchKind, WorkspaceSymbolSearchScope},
4141
};
4242

@@ -1899,7 +1899,7 @@ impl Config {
18991899
*self.check_workspace(None)
19001900
}
19011901

1902-
pub fn cargo_test_options(&self) -> CargoOptions {
1902+
pub(crate) fn cargo_test_options(&self) -> CargoOptions {
19031903
CargoOptions {
19041904
target_triples: self.cargo_target(None).clone().into_iter().collect(),
19051905
all_targets: false,
@@ -1915,7 +1915,7 @@ impl Config {
19151915
}
19161916
}
19171917

1918-
pub fn flycheck(&self) -> FlycheckConfig {
1918+
pub(crate) fn flycheck(&self) -> FlycheckConfig {
19191919
match &self.check_overrideCommand(None) {
19201920
Some(args) if !args.is_empty() => {
19211921
let mut args = args.clone();
@@ -1925,16 +1925,18 @@ impl Config {
19251925
args,
19261926
extra_env: self.check_extra_env(),
19271927
invocation_strategy: match self.check_invocationStrategy(None) {
1928-
InvocationStrategy::Once => flycheck::InvocationStrategy::Once,
1928+
InvocationStrategy::Once => crate::flycheck::InvocationStrategy::Once,
19291929
InvocationStrategy::PerWorkspace => {
1930-
flycheck::InvocationStrategy::PerWorkspace
1930+
crate::flycheck::InvocationStrategy::PerWorkspace
19311931
}
19321932
},
19331933
invocation_location: match self.check_invocationLocation(None) {
19341934
InvocationLocation::Root => {
1935-
flycheck::InvocationLocation::Root(self.root_path.clone())
1935+
crate::flycheck::InvocationLocation::Root(self.root_path.clone())
1936+
}
1937+
InvocationLocation::Workspace => {
1938+
crate::flycheck::InvocationLocation::Workspace
19361939
}
1937-
InvocationLocation::Workspace => flycheck::InvocationLocation::Workspace,
19381940
},
19391941
}
19401942
}

src/tools/rust-analyzer/crates/rust-analyzer/src/diagnostics/to_proto.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module provides the functionality needed to convert diagnostics from
22
//! `cargo check` json format to the LSP diagnostic format.
33
4-
use flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan};
4+
use crate::flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan};
55
use itertools::Itertools;
66
use rustc_hash::FxHashMap;
77
use stdx::format_to;
@@ -17,8 +17,8 @@ use super::{DiagnosticsMapConfig, Fix};
1717
/// Determines the LSP severity from a diagnostic
1818
fn diagnostic_severity(
1919
config: &DiagnosticsMapConfig,
20-
level: flycheck::DiagnosticLevel,
21-
code: Option<flycheck::DiagnosticCode>,
20+
level: crate::flycheck::DiagnosticLevel,
21+
code: Option<crate::flycheck::DiagnosticCode>,
2222
) -> Option<lsp_types::DiagnosticSeverity> {
2323
let res = match level {
2424
DiagnosticLevel::Ice => lsp_types::DiagnosticSeverity::ERROR,
@@ -181,7 +181,7 @@ enum MappedRustChildDiagnostic {
181181
fn map_rust_child_diagnostic(
182182
config: &DiagnosticsMapConfig,
183183
workspace_root: &AbsPath,
184-
rd: &flycheck::Diagnostic,
184+
rd: &crate::flycheck::Diagnostic,
185185
snap: &GlobalStateSnapshot,
186186
) -> MappedRustChildDiagnostic {
187187
let spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect();
@@ -284,7 +284,7 @@ pub(crate) struct MappedRustDiagnostic {
284284
/// If the diagnostic has no primary span this will return `None`
285285
pub(crate) fn map_rust_diagnostic_to_lsp(
286286
config: &DiagnosticsMapConfig,
287-
rd: &flycheck::Diagnostic,
287+
rd: &crate::flycheck::Diagnostic,
288288
workspace_root: &AbsPath,
289289
snap: &GlobalStateSnapshot,
290290
) -> Vec<MappedRustDiagnostic> {
@@ -537,7 +537,8 @@ mod tests {
537537
}
538538

539539
fn check_with_config(config: DiagnosticsMapConfig, diagnostics_json: &str, expect: ExpectFile) {
540-
let diagnostic: flycheck::Diagnostic = serde_json::from_str(diagnostics_json).unwrap();
540+
let diagnostic: crate::flycheck::Diagnostic =
541+
serde_json::from_str(diagnostics_json).unwrap();
541542
let workspace_root: &AbsPath = Utf8Path::new("/test/").try_into().unwrap();
542543
let (sender, _) = crossbeam_channel::unbounded();
543544
let state = GlobalState::new(

src/tools/rust-analyzer/crates/flycheck/src/lib.rs renamed to src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,42 @@ use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
1313
use rustc_hash::FxHashMap;
1414
use serde::Deserialize;
1515

16-
pub use cargo_metadata::diagnostic::{
16+
pub(crate) use cargo_metadata::diagnostic::{
1717
Applicability, Diagnostic, DiagnosticCode, DiagnosticLevel, DiagnosticSpan,
18-
DiagnosticSpanMacroExpansion,
1918
};
2019
use toolchain::Tool;
2120

2221
mod command;
23-
pub mod project_json;
22+
pub(crate) mod project_json;
2423
mod test_runner;
2524

2625
use command::{CommandHandle, ParseFromLine};
27-
pub use test_runner::{CargoTestHandle, CargoTestMessage, TestState, TestTarget};
26+
pub(crate) use test_runner::{CargoTestHandle, CargoTestMessage, TestState, TestTarget};
2827

2928
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
30-
pub enum InvocationStrategy {
29+
pub(crate) enum InvocationStrategy {
3130
Once,
3231
#[default]
3332
PerWorkspace,
3433
}
3534

3635
#[derive(Clone, Debug, Default, PartialEq, Eq)]
37-
pub enum InvocationLocation {
36+
pub(crate) enum InvocationLocation {
3837
Root(AbsPathBuf),
3938
#[default]
4039
Workspace,
4140
}
4241

4342
#[derive(Clone, Debug, PartialEq, Eq)]
44-
pub struct CargoOptions {
45-
pub target_triples: Vec<String>,
46-
pub all_targets: bool,
47-
pub no_default_features: bool,
48-
pub all_features: bool,
49-
pub features: Vec<String>,
50-
pub extra_args: Vec<String>,
51-
pub extra_env: FxHashMap<String, String>,
52-
pub target_dir: Option<Utf8PathBuf>,
43+
pub(crate) struct CargoOptions {
44+
pub(crate) target_triples: Vec<String>,
45+
pub(crate) all_targets: bool,
46+
pub(crate) no_default_features: bool,
47+
pub(crate) all_features: bool,
48+
pub(crate) features: Vec<String>,
49+
pub(crate) extra_args: Vec<String>,
50+
pub(crate) extra_env: FxHashMap<String, String>,
51+
pub(crate) target_dir: Option<Utf8PathBuf>,
5352
}
5453

5554
impl CargoOptions {
@@ -79,7 +78,7 @@ impl CargoOptions {
7978
}
8079

8180
#[derive(Clone, Debug, PartialEq, Eq)]
82-
pub enum FlycheckConfig {
81+
pub(crate) enum FlycheckConfig {
8382
CargoCommand {
8483
command: String,
8584
options: CargoOptions,
@@ -110,15 +109,15 @@ impl fmt::Display for FlycheckConfig {
110109
/// diagnostics based on the output.
111110
/// The spawned thread is shut down when this struct is dropped.
112111
#[derive(Debug)]
113-
pub struct FlycheckHandle {
112+
pub(crate) struct FlycheckHandle {
114113
// XXX: drop order is significant
115114
sender: Sender<StateChange>,
116115
_thread: stdx::thread::JoinHandle,
117116
id: usize,
118117
}
119118

120119
impl FlycheckHandle {
121-
pub fn spawn(
120+
pub(crate) fn spawn(
122121
id: usize,
123122
sender: Box<dyn Fn(Message) + Send>,
124123
config: FlycheckConfig,
@@ -137,28 +136,28 @@ impl FlycheckHandle {
137136
}
138137

139138
/// Schedule a re-start of the cargo check worker to do a workspace wide check.
140-
pub fn restart_workspace(&self, saved_file: Option<AbsPathBuf>) {
139+
pub(crate) fn restart_workspace(&self, saved_file: Option<AbsPathBuf>) {
141140
self.sender.send(StateChange::Restart { package: None, saved_file }).unwrap();
142141
}
143142

144143
/// Schedule a re-start of the cargo check worker to do a package wide check.
145-
pub fn restart_for_package(&self, package: String) {
144+
pub(crate) fn restart_for_package(&self, package: String) {
146145
self.sender
147146
.send(StateChange::Restart { package: Some(package), saved_file: None })
148147
.unwrap();
149148
}
150149

151150
/// Stop this cargo check worker.
152-
pub fn cancel(&self) {
151+
pub(crate) fn cancel(&self) {
153152
self.sender.send(StateChange::Cancel).unwrap();
154153
}
155154

156-
pub fn id(&self) -> usize {
155+
pub(crate) fn id(&self) -> usize {
157156
self.id
158157
}
159158
}
160159

161-
pub enum Message {
160+
pub(crate) enum Message {
162161
/// Request adding a diagnostic with fixes included to a file
163162
AddDiagnostic { id: usize, workspace_root: AbsPathBuf, diagnostic: Diagnostic },
164163

@@ -193,7 +192,7 @@ impl fmt::Debug for Message {
193192
}
194193

195194
#[derive(Debug)]
196-
pub enum Progress {
195+
pub(crate) enum Progress {
197196
DidStart,
198197
DidCheckCrate(String),
199198
DidFinish(io::Result<()>),
@@ -241,7 +240,7 @@ enum FlycheckStatus {
241240
Finished,
242241
}
243242

244-
pub const SAVED_FILE_PLACEHOLDER: &str = "$saved_file";
243+
pub(crate) const SAVED_FILE_PLACEHOLDER: &str = "$saved_file";
245244

246245
impl FlycheckActor {
247246
fn new(

src/tools/rust-analyzer/crates/flycheck/src/project_json.rs renamed to src/tools/rust-analyzer/crates/rust-analyzer/src/flycheck/project_json.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ use project_model::ProjectJsonData;
77
use serde::{Deserialize, Serialize};
88
use serde_json::Value;
99

10-
use crate::command::{CommandHandle, ParseFromLine};
10+
use crate::flycheck::{CommandHandle, ParseFromLine};
1111

12-
pub const ARG_PLACEHOLDER: &str = "{arg}";
12+
pub(crate) const ARG_PLACEHOLDER: &str = "{arg}";
1313

1414
/// A command wrapper for getting a `rust-project.json`.
1515
///
1616
/// This is analogous to `cargo-metadata`, but for non-Cargo build systems.
17-
pub struct Discover {
17+
pub(crate) struct Discover {
1818
command: Vec<String>,
1919
sender: Sender<DiscoverProjectMessage>,
2020
}
2121

2222
#[derive(PartialEq, Clone, Debug, Serialize)]
2323
#[serde(rename_all = "camelCase")]
24-
pub enum DiscoverArgument {
24+
pub(crate) enum DiscoverArgument {
2525
Path(#[serde(serialize_with = "serialize_abs_pathbuf")] AbsPathBuf),
2626
Buildfile(#[serde(serialize_with = "serialize_abs_pathbuf")] AbsPathBuf),
2727
}
@@ -36,12 +36,12 @@ where
3636

3737
impl Discover {
3838
/// Create a new [Discover].
39-
pub fn new(sender: Sender<DiscoverProjectMessage>, command: Vec<String>) -> Self {
39+
pub(crate) fn new(sender: Sender<DiscoverProjectMessage>, command: Vec<String>) -> Self {
4040
Self { sender, command }
4141
}
4242

4343
/// Spawn the command inside [Discover] and report progress, if any.
44-
pub fn spawn(&self, discover_arg: DiscoverArgument) -> io::Result<DiscoverHandle> {
44+
pub(crate) fn spawn(&self, discover_arg: DiscoverArgument) -> io::Result<DiscoverHandle> {
4545
let command = &self.command[0];
4646
let args = &self.command[1..];
4747

@@ -65,7 +65,7 @@ impl Discover {
6565

6666
/// A handle to a spawned [Discover].
6767
#[derive(Debug)]
68-
pub struct DiscoverHandle {
68+
pub(crate) struct DiscoverHandle {
6969
_handle: CommandHandle<DiscoverProjectMessage>,
7070
}
7171

@@ -81,7 +81,7 @@ enum DiscoverProjectData {
8181
}
8282

8383
#[derive(Debug, PartialEq, Clone)]
84-
pub enum DiscoverProjectMessage {
84+
pub(crate) enum DiscoverProjectMessage {
8585
Finished { project: ProjectJsonData, buildfile: AbsPathBuf },
8686
Error { error: String, source: Option<String> },
8787
Progress { message: String },

0 commit comments

Comments
 (0)