aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/diagnostics
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-25 08:13:46 +0100
committerAleksey Kladov <[email protected]>2020-06-25 08:13:46 +0100
commit0ec5d4f55c6a5ac3fadcd48ae17b70379aba17fa (patch)
tree89fb78d856e36225f7f09560020729b1200a8ee6 /crates/rust-analyzer/src/diagnostics
parent5a184fe85517507fd3b07c6fb36b017e558665f7 (diff)
Rename ra_flycheck -> flycheck
Diffstat (limited to 'crates/rust-analyzer/src/diagnostics')
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index ba74f15f3..f379f5ed0 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -2,20 +2,21 @@
2//! `cargo check` json format to the LSP diagnostic format. 2//! `cargo check` json format to the LSP diagnostic format.
3use std::{collections::HashMap, path::Path}; 3use std::{collections::HashMap, path::Path};
4 4
5use flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion};
5use lsp_types::{ 6use lsp_types::{
6 Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, Location, 7 Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, Location,
7 NumberOrString, Position, Range, TextEdit, Url, 8 NumberOrString, Position, Range, TextEdit, Url,
8}; 9};
9use ra_flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion};
10use stdx::format_to; 10use stdx::format_to;
11 11
12use super::DiagnosticsConfig;
13use crate::{lsp_ext, to_proto::url_from_abs_path}; 12use crate::{lsp_ext, to_proto::url_from_abs_path};
14 13
14use super::DiagnosticsConfig;
15
15/// Determines the LSP severity from a diagnostic 16/// Determines the LSP severity from a diagnostic
16fn map_diagnostic_to_severity( 17fn map_diagnostic_to_severity(
17 config: &DiagnosticsConfig, 18 config: &DiagnosticsConfig,
18 val: &ra_flycheck::Diagnostic, 19 val: &flycheck::Diagnostic,
19) -> Option<DiagnosticSeverity> { 20) -> Option<DiagnosticSeverity> {
20 let res = match val.level { 21 let res = match val.level {
21 DiagnosticLevel::Ice => DiagnosticSeverity::Error, 22 DiagnosticLevel::Ice => DiagnosticSeverity::Error,
@@ -95,7 +96,7 @@ fn map_secondary_span_to_related(
95} 96}
96 97
97/// Determines if diagnostic is related to unused code 98/// Determines if diagnostic is related to unused code
98fn is_unused_or_unnecessary(rd: &ra_flycheck::Diagnostic) -> bool { 99fn is_unused_or_unnecessary(rd: &flycheck::Diagnostic) -> bool {
99 match &rd.code { 100 match &rd.code {
100 Some(code) => match code.code.as_str() { 101 Some(code) => match code.code.as_str() {
101 "dead_code" | "unknown_lints" | "unreachable_code" | "unused_attributes" 102 "dead_code" | "unknown_lints" | "unreachable_code" | "unused_attributes"
@@ -107,7 +108,7 @@ fn is_unused_or_unnecessary(rd: &ra_flycheck::Diagnostic) -> bool {
107} 108}
108 109
109/// Determines if diagnostic is related to deprecated code 110/// Determines if diagnostic is related to deprecated code
110fn is_deprecated(rd: &ra_flycheck::Diagnostic) -> bool { 111fn is_deprecated(rd: &flycheck::Diagnostic) -> bool {
111 match &rd.code { 112 match &rd.code {
112 Some(code) => code.code.as_str() == "deprecated", 113 Some(code) => code.code.as_str() == "deprecated",
113 None => false, 114 None => false,
@@ -121,7 +122,7 @@ enum MappedRustChildDiagnostic {
121} 122}
122 123
123fn map_rust_child_diagnostic( 124fn map_rust_child_diagnostic(
124 rd: &ra_flycheck::Diagnostic, 125 rd: &flycheck::Diagnostic,
125 workspace_root: &Path, 126 workspace_root: &Path,
126) -> MappedRustChildDiagnostic { 127) -> MappedRustChildDiagnostic {
127 let spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect(); 128 let spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect();
@@ -183,7 +184,7 @@ pub(crate) struct MappedRustDiagnostic {
183/// If the diagnostic has no primary span this will return `None` 184/// If the diagnostic has no primary span this will return `None`
184pub(crate) fn map_rust_diagnostic_to_lsp( 185pub(crate) fn map_rust_diagnostic_to_lsp(
185 config: &DiagnosticsConfig, 186 config: &DiagnosticsConfig,
186 rd: &ra_flycheck::Diagnostic, 187 rd: &flycheck::Diagnostic,
187 workspace_root: &Path, 188 workspace_root: &Path,
188) -> Vec<MappedRustDiagnostic> { 189) -> Vec<MappedRustDiagnostic> {
189 let primary_spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect(); 190 let primary_spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect();
@@ -286,8 +287,8 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
286mod tests { 287mod tests {
287 use super::*; 288 use super::*;
288 289
289 fn parse_diagnostic(val: &str) -> ra_flycheck::Diagnostic { 290 fn parse_diagnostic(val: &str) -> flycheck::Diagnostic {
290 serde_json::from_str::<ra_flycheck::Diagnostic>(val).unwrap() 291 serde_json::from_str::<flycheck::Diagnostic>(val).unwrap()
291 } 292 }
292 293
293 #[test] 294 #[test]