aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_flycheck/src/lib.rs13
-rw-r--r--crates/rust-analyzer/Cargo.toml1
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs20
3 files changed, 15 insertions, 19 deletions
diff --git a/crates/ra_flycheck/src/lib.rs b/crates/ra_flycheck/src/lib.rs
index 178485c9e..541179920 100644
--- a/crates/ra_flycheck/src/lib.rs
+++ b/crates/ra_flycheck/src/lib.rs
@@ -12,6 +12,11 @@ use std::{
12use cargo_metadata::Message; 12use cargo_metadata::Message;
13use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender}; 13use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender};
14 14
15pub use cargo_metadata::diagnostic::{
16 Applicability, Diagnostic, DiagnosticLevel, DiagnosticSpan,
17 DiagnosticSpanMacroExpansion,
18};
19
15#[derive(Clone, Debug, PartialEq, Eq)] 20#[derive(Clone, Debug, PartialEq, Eq)]
16pub enum FlycheckConfig { 21pub enum FlycheckConfig {
17 CargoCommand { command: String, all_targets: bool, all_features: bool, extra_args: Vec<String> }, 22 CargoCommand { command: String, all_targets: bool, all_features: bool, extra_args: Vec<String> },
@@ -52,7 +57,7 @@ pub enum CheckTask {
52 ClearDiagnostics, 57 ClearDiagnostics,
53 58
54 /// Request adding a diagnostic with fixes included to a file 59 /// 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 },
56 61
57 /// Request check progress notification to client 62 /// Request check progress notification to client
58 Status(Status), 63 Status(Status),
@@ -239,12 +244,6 @@ impl FlycheckThread {
239 } 244 }
240} 245}
241 246
242// #[derive(Debug)]
243// pub struct DiagnosticWithFixes {
244// diagnostic: Diagnostic,
245// fixes: Vec<CodeAction>,
246// }
247
248enum CheckEvent { 247enum CheckEvent {
249 Begin, 248 Begin,
250 Msg(cargo_metadata::Message), 249 Msg(cargo_metadata::Message),
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index 21e705597..9b2d29b1d 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -29,7 +29,6 @@ rustc-hash = "1.1.0"
29serde = { version = "1.0.106", features = ["derive"] } 29serde = { version = "1.0.106", features = ["derive"] }
30serde_json = "1.0.48" 30serde_json = "1.0.48"
31threadpool = "1.7.1" 31threadpool = "1.7.1"
32cargo_metadata = "0.10.0"
33 32
34stdx = { path = "../stdx" } 33stdx = { path = "../stdx" }
35 34
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index 0c8108591..5c8d86eb5 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -1,13 +1,5 @@
1//! This module provides the functionality needed to convert diagnostics from 1//! This module provides the functionality needed to convert diagnostics from
2//! `cargo check` json format to the LSP diagnostic format. 2//! `cargo check` json format to the LSP diagnostic format.
3use cargo_metadata::diagnostic::{
4 Applicability, Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan,
5 DiagnosticSpanMacroExpansion,
6};
7use lsp_types::{
8 CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag,
9 Location, NumberOrString, Position, Range, TextEdit, Url, WorkspaceEdit,
10};
11use std::{ 3use std::{
12 collections::HashMap, 4 collections::HashMap,
13 fmt::Write, 5 fmt::Write,
@@ -15,6 +7,12 @@ use std::{
15 str::FromStr, 7 str::FromStr,
16}; 8};
17 9
10use lsp_types::{
11 CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag,
12 Location, NumberOrString, Position, Range, TextEdit, Url, WorkspaceEdit,
13};
14use ra_flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion};
15
18/// Converts a Rust level string to a LSP severity 16/// Converts a Rust level string to a LSP severity
19fn map_level_to_severity(val: DiagnosticLevel) -> Option<DiagnosticSeverity> { 17fn map_level_to_severity(val: DiagnosticLevel) -> Option<DiagnosticSeverity> {
20 match val { 18 match val {
@@ -91,7 +89,7 @@ fn map_secondary_span_to_related(
91} 89}
92 90
93/// Determines if diagnostic is related to unused code 91/// Determines if diagnostic is related to unused code
94fn is_unused_or_unnecessary(rd: &RustDiagnostic) -> bool { 92fn is_unused_or_unnecessary(rd: &ra_flycheck::Diagnostic) -> bool {
95 if let Some(code) = &rd.code { 93 if let Some(code) = &rd.code {
96 match code.code.as_str() { 94 match code.code.as_str() {
97 "dead_code" | "unknown_lints" | "unreachable_code" | "unused_attributes" 95 "dead_code" | "unknown_lints" | "unreachable_code" | "unused_attributes"
@@ -122,7 +120,7 @@ enum MappedRustChildDiagnostic {
122} 120}
123 121
124fn map_rust_child_diagnostic( 122fn map_rust_child_diagnostic(
125 rd: &RustDiagnostic, 123 rd: &ra_flycheck::Diagnostic,
126 workspace_root: &PathBuf, 124 workspace_root: &PathBuf,
127) -> MappedRustChildDiagnostic { 125) -> MappedRustChildDiagnostic {
128 let spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect(); 126 let spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect();
@@ -179,7 +177,7 @@ pub(crate) struct MappedRustDiagnostic {
179/// 177///
180/// If the diagnostic has no primary span this will return `None` 178/// If the diagnostic has no primary span this will return `None`
181pub(crate) fn map_rust_diagnostic_to_lsp( 179pub(crate) fn map_rust_diagnostic_to_lsp(
182 rd: &RustDiagnostic, 180 rd: &ra_flycheck::Diagnostic,
183 workspace_root: &PathBuf, 181 workspace_root: &PathBuf,
184) -> Vec<MappedRustDiagnostic> { 182) -> Vec<MappedRustDiagnostic> {
185 let primary_spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect(); 183 let primary_spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect();