Skip to content

Commit f1a5c48

Browse files
committed
Better structure
1 parent 220813d commit f1a5c48

File tree

4 files changed

+15
-20
lines changed

4 files changed

+15
-20
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_flycheck/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ use std::{
1212
use cargo_metadata::Message;
1313
use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender};
1414

15+
pub use cargo_metadata::diagnostic::{
16+
Applicability, Diagnostic, DiagnosticLevel, DiagnosticSpan,
17+
DiagnosticSpanMacroExpansion,
18+
};
19+
1520
#[derive(Clone, Debug, PartialEq, Eq)]
1621
pub enum FlycheckConfig {
1722
CargoCommand { command: String, all_targets: bool, all_features: bool, extra_args: Vec<String> },
@@ -52,7 +57,7 @@ pub enum CheckTask {
5257
ClearDiagnostics,
5358

5459
/// Request adding a diagnostic with fixes included to a file
55-
AddDiagnostic { workspace_root: PathBuf, diagnostic: cargo_metadata::diagnostic::Diagnostic },
60+
AddDiagnostic { workspace_root: PathBuf, diagnostic: Diagnostic },
5661

5762
/// Request check progress notification to client
5863
Status(Status),
@@ -239,12 +244,6 @@ impl FlycheckThread {
239244
}
240245
}
241246

242-
// #[derive(Debug)]
243-
// pub struct DiagnosticWithFixes {
244-
// diagnostic: Diagnostic,
245-
// fixes: Vec<CodeAction>,
246-
// }
247-
248247
enum CheckEvent {
249248
Begin,
250249
Msg(cargo_metadata::Message),

crates/rust-analyzer/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ rustc-hash = "1.1.0"
2929
serde = { version = "1.0.106", features = ["derive"] }
3030
serde_json = "1.0.48"
3131
threadpool = "1.7.1"
32-
cargo_metadata = "0.10.0"
3332

3433
stdx = { path = "../stdx" }
3534

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
//! This module provides the functionality needed to convert diagnostics from
22
//! `cargo check` json format to the LSP diagnostic format.
3-
use cargo_metadata::diagnostic::{
4-
Applicability, Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan,
5-
DiagnosticSpanMacroExpansion,
6-
};
7-
use lsp_types::{
8-
CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag,
9-
Location, NumberOrString, Position, Range, TextEdit, Url, WorkspaceEdit,
10-
};
113
use std::{
124
collections::HashMap,
135
fmt::Write,
146
path::{Component, Path, PathBuf, Prefix},
157
str::FromStr,
168
};
179

10+
use lsp_types::{
11+
CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag,
12+
Location, NumberOrString, Position, Range, TextEdit, Url, WorkspaceEdit,
13+
};
14+
use ra_flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion};
15+
1816
/// Converts a Rust level string to a LSP severity
1917
fn map_level_to_severity(val: DiagnosticLevel) -> Option<DiagnosticSeverity> {
2018
match val {
@@ -91,7 +89,7 @@ fn map_secondary_span_to_related(
9189
}
9290

9391
/// Determines if diagnostic is related to unused code
94-
fn is_unused_or_unnecessary(rd: &RustDiagnostic) -> bool {
92+
fn is_unused_or_unnecessary(rd: &ra_flycheck::Diagnostic) -> bool {
9593
if let Some(code) = &rd.code {
9694
match code.code.as_str() {
9795
"dead_code" | "unknown_lints" | "unreachable_code" | "unused_attributes"
@@ -122,7 +120,7 @@ enum MappedRustChildDiagnostic {
122120
}
123121

124122
fn map_rust_child_diagnostic(
125-
rd: &RustDiagnostic,
123+
rd: &ra_flycheck::Diagnostic,
126124
workspace_root: &PathBuf,
127125
) -> MappedRustChildDiagnostic {
128126
let spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect();
@@ -179,7 +177,7 @@ pub(crate) struct MappedRustDiagnostic {
179177
///
180178
/// If the diagnostic has no primary span this will return `None`
181179
pub(crate) fn map_rust_diagnostic_to_lsp(
182-
rd: &RustDiagnostic,
180+
rd: &ra_flycheck::Diagnostic,
183181
workspace_root: &PathBuf,
184182
) -> Vec<MappedRustDiagnostic> {
185183
let primary_spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect();

0 commit comments

Comments
 (0)