diff options
author | gfreezy <[email protected]> | 2018-12-23 16:39:33 +0000 |
---|---|---|
committer | gfreezy <[email protected]> | 2018-12-23 16:39:33 +0000 |
commit | 346638c8098fefd0b6fa3cf81fbdf22ebfaab9be (patch) | |
tree | 9c3065ad2d909786f802fbd1b4c2571cb2287482 | |
parent | 000aacafda209826b9b5aac86d175152d488f05b (diff) |
add serverity to vscode diagnostics
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 5 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_analysis/tests/tests.rs | 3 | ||||
-rw-r--r-- | crates/ra_editor/src/lib.rs | 19 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 15 |
5 files changed, 32 insertions, 12 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index b01382808..e054227a9 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -3,7 +3,7 @@ use std::{ | |||
3 | sync::Arc, | 3 | sync::Arc, |
4 | }; | 4 | }; |
5 | 5 | ||
6 | use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit}; | 6 | use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit, Severity}; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | ast::{self, ArgListOwner, Expr, NameOwner}, | 8 | ast::{self, ArgListOwner, Expr, NameOwner}, |
9 | AstNode, SourceFileNode, | 9 | AstNode, SourceFileNode, |
@@ -364,6 +364,7 @@ impl AnalysisImpl { | |||
364 | .map(|d| Diagnostic { | 364 | .map(|d| Diagnostic { |
365 | range: d.range, | 365 | range: d.range, |
366 | message: d.msg, | 366 | message: d.msg, |
367 | severity: d.severity, | ||
367 | fix: None, | 368 | fix: None, |
368 | }) | 369 | }) |
369 | .collect::<Vec<_>>(); | 370 | .collect::<Vec<_>>(); |
@@ -385,6 +386,7 @@ impl AnalysisImpl { | |||
385 | Diagnostic { | 386 | Diagnostic { |
386 | range: name_node.range(), | 387 | range: name_node.range(), |
387 | message: "unresolved module".to_string(), | 388 | message: "unresolved module".to_string(), |
389 | severity: Some(Severity::Error), | ||
388 | fix: Some(fix), | 390 | fix: Some(fix), |
389 | } | 391 | } |
390 | } | 392 | } |
@@ -407,6 +409,7 @@ impl AnalysisImpl { | |||
407 | Diagnostic { | 409 | Diagnostic { |
408 | range: name_node.range(), | 410 | range: name_node.range(), |
409 | message: "can't declare module at this location".to_string(), | 411 | message: "can't declare module at this location".to_string(), |
412 | severity: Some(Severity::Error), | ||
410 | fix: Some(fix), | 413 | fix: Some(fix), |
411 | } | 414 | } |
412 | } | 415 | } |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 85df9c089..8ab6334a7 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -34,6 +34,7 @@ pub use crate::{ | |||
34 | }; | 34 | }; |
35 | pub use ra_editor::{ | 35 | pub use ra_editor::{ |
36 | FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable, RunnableKind, StructureNode, | 36 | FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable, RunnableKind, StructureNode, |
37 | Severity | ||
37 | }; | 38 | }; |
38 | pub use hir::FnSignatureInfo; | 39 | pub use hir::FnSignatureInfo; |
39 | 40 | ||
@@ -198,6 +199,7 @@ pub struct Diagnostic { | |||
198 | pub message: String, | 199 | pub message: String, |
199 | pub range: TextRange, | 200 | pub range: TextRange, |
200 | pub fix: Option<SourceChange>, | 201 | pub fix: Option<SourceChange>, |
202 | pub severity: Option<Severity>, | ||
201 | } | 203 | } |
202 | 204 | ||
203 | #[derive(Debug)] | 205 | #[derive(Debug)] |
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index 938ca797a..2313e35f5 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs | |||
@@ -82,7 +82,8 @@ fn test_unresolved_module_diagnostic() { | |||
82 | label: "create module", | 82 | label: "create module", |
83 | source_file_edits: [], | 83 | source_file_edits: [], |
84 | file_system_edits: [CreateFile { source_root: SourceRootId(0), path: "foo.rs" }], | 84 | file_system_edits: [CreateFile { source_root: SourceRootId(0), path: "foo.rs" }], |
85 | cursor_position: None }) }]"#, | 85 | cursor_position: None }), |
86 | severity: Some(Error) }]"#, | ||
86 | &diagnostics, | 87 | &diagnostics, |
87 | ); | 88 | ); |
88 | } | 89 | } |
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index 48676f2e8..399bb8fe8 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs | |||
@@ -34,14 +34,16 @@ pub struct HighlightedRange { | |||
34 | #[derive(Debug, Copy, Clone)] | 34 | #[derive(Debug, Copy, Clone)] |
35 | pub enum Severity { | 35 | pub enum Severity { |
36 | Error, | 36 | Error, |
37 | Warning | 37 | Warning, |
38 | Information, | ||
39 | Hint, | ||
38 | } | 40 | } |
39 | 41 | ||
40 | #[derive(Debug)] | 42 | #[derive(Debug)] |
41 | pub struct Diagnostic { | 43 | pub struct Diagnostic { |
42 | pub range: TextRange, | 44 | pub range: TextRange, |
43 | pub msg: String, | 45 | pub msg: String, |
44 | pub severity: Severity, | 46 | pub severity: Option<Severity>, |
45 | } | 47 | } |
46 | 48 | ||
47 | #[derive(Debug)] | 49 | #[derive(Debug)] |
@@ -104,12 +106,13 @@ pub fn diagnostics(file: &SourceFileNode) -> Vec<Diagnostic> { | |||
104 | } | 106 | } |
105 | } | 107 | } |
106 | 108 | ||
107 | let mut errors: Vec<Diagnostic> = file.errors() | 109 | let mut errors: Vec<Diagnostic> = file |
110 | .errors() | ||
108 | .into_iter() | 111 | .into_iter() |
109 | .map(|err| Diagnostic { | 112 | .map(|err| Diagnostic { |
110 | range: location_to_range(err.location()), | 113 | range: location_to_range(err.location()), |
111 | msg: format!("Syntax Error: {}", err), | 114 | msg: format!("Syntax Error: {}", err), |
112 | severity: Severity::Error, | 115 | severity: Some(Severity::Error), |
113 | }) | 116 | }) |
114 | .collect(); | 117 | .collect(); |
115 | 118 | ||
@@ -127,7 +130,7 @@ fn check_unnecessary_braces_in_use_statement(file: &SourceFileNode) -> Vec<Diagn | |||
127 | diagnostics.push(Diagnostic { | 130 | diagnostics.push(Diagnostic { |
128 | range: use_tree_list.syntax().range(), | 131 | range: use_tree_list.syntax().range(), |
129 | msg: format!("Unnecessary braces in use statement"), | 132 | msg: format!("Unnecessary braces in use statement"), |
130 | severity: Severity::Warning, | 133 | severity: Some(Severity::Warning), |
131 | }) | 134 | }) |
132 | } | 135 | } |
133 | } | 136 | } |
@@ -249,9 +252,9 @@ fn main() {} | |||
249 | ); | 252 | ); |
250 | let diagnostics = check_unnecessary_braces_in_use_statement(&file); | 253 | let diagnostics = check_unnecessary_braces_in_use_statement(&file); |
251 | assert_eq_dbg( | 254 | assert_eq_dbg( |
252 | r#"[Diagnostic { range: [12; 15), msg: "Unnecessary braces in use statement", severity: Warning }, | 255 | r#"[Diagnostic { range: [12; 15), msg: "Unnecessary braces in use statement", severity: Some(Warning) }, |
253 | Diagnostic { range: [24; 27), msg: "Unnecessary braces in use statement", severity: Warning }, | 256 | Diagnostic { range: [24; 27), msg: "Unnecessary braces in use statement", severity: Some(Warning) }, |
254 | Diagnostic { range: [61; 64), msg: "Unnecessary braces in use statement", severity: Warning }]"#, | 257 | Diagnostic { range: [61; 64), msg: "Unnecessary braces in use statement", severity: Some(Warning) }]"#, |
255 | &diagnostics, | 258 | &diagnostics, |
256 | ) | 259 | ) |
257 | } | 260 | } |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 252d1ba3e..8e859e8d4 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -8,7 +8,7 @@ use languageserver_types::{ | |||
8 | PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, | 8 | PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, |
9 | WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents, | 9 | WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents, |
10 | }; | 10 | }; |
11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; | 11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition, Severity}; |
12 | use ra_syntax::{TextUnit, text_utils::intersect}; | 12 | use ra_syntax::{TextUnit, text_utils::intersect}; |
13 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 13 | use ra_text_edit::text_utils::contains_offset_nonstrict; |
14 | use rustc_hash::FxHashMap; | 14 | use rustc_hash::FxHashMap; |
@@ -650,7 +650,7 @@ pub fn publish_diagnostics( | |||
650 | .into_iter() | 650 | .into_iter() |
651 | .map(|d| Diagnostic { | 651 | .map(|d| Diagnostic { |
652 | range: d.range.conv_with(&line_index), | 652 | range: d.range.conv_with(&line_index), |
653 | severity: Some(DiagnosticSeverity::Error), | 653 | severity: d.severity.map(to_diagnostic_severity), |
654 | code: None, | 654 | code: None, |
655 | source: Some("rust-analyzer".to_string()), | 655 | source: Some("rust-analyzer".to_string()), |
656 | message: d.message, | 656 | message: d.message, |
@@ -684,3 +684,14 @@ fn highlight(world: &ServerWorld, file_id: FileId) -> Result<Vec<Decoration>> { | |||
684 | .collect(); | 684 | .collect(); |
685 | Ok(res) | 685 | Ok(res) |
686 | } | 686 | } |
687 | |||
688 | fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity { | ||
689 | use ra_analysis::Severity::*; | ||
690 | |||
691 | match severity { | ||
692 | Error => DiagnosticSeverity::Error, | ||
693 | Warning => DiagnosticSeverity::Warning, | ||
694 | Information => DiagnosticSeverity::Information, | ||
695 | Hint => DiagnosticSeverity::Hint, | ||
696 | } | ||
697 | } | ||