From eb81731600d1bc50efc00e32b9fc2244a2af52ad Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 18 Aug 2020 16:22:01 +0200 Subject: [PATCH] Minor --- crates/ide/src/diagnostics.rs | 35 +++++++++++++++++-- .../{diagnostics_with_fix.rs => fixes.rs} | 10 ++++-- crates/ide/src/lib.rs | 31 +--------------- 3 files changed, 40 insertions(+), 36 deletions(-) rename crates/ide/src/diagnostics/{diagnostics_with_fix.rs => fixes.rs} (98%) diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 89ff554908a..1f85805d223 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -4,7 +4,7 @@ //! macro-expanded files, but we need to present them to the users in terms of //! original files. So we need to map the ranges. -mod diagnostics_with_fix; +mod fixes; use std::cell::RefCell; @@ -19,9 +19,38 @@ use syntax::{ }; use text_edit::TextEdit; -use crate::{Diagnostic, FileId, Fix, SourceFileEdit}; +use crate::{FileId, SourceChange, SourceFileEdit}; -use self::diagnostics_with_fix::DiagnosticWithFix; +use self::fixes::DiagnosticWithFix; + +#[derive(Debug)] +pub struct Diagnostic { + pub name: Option, + pub message: String, + pub range: TextRange, + pub severity: Severity, + pub fix: Option, +} + +#[derive(Debug)] +pub struct Fix { + pub label: String, + pub source_change: SourceChange, + /// Allows to trigger the fix only when the caret is in the range given + pub fix_trigger_range: TextRange, +} + +impl Fix { + fn new( + label: impl Into, + source_change: SourceChange, + fix_trigger_range: TextRange, + ) -> Self { + let label = label.into(); + assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.')); + Self { label, source_change, fix_trigger_range } + } +} #[derive(Debug, Copy, Clone)] pub enum Severity { diff --git a/crates/ide/src/diagnostics/diagnostics_with_fix.rs b/crates/ide/src/diagnostics/fixes.rs similarity index 98% rename from crates/ide/src/diagnostics/diagnostics_with_fix.rs rename to crates/ide/src/diagnostics/fixes.rs index 85b46c9958a..68ae1c23981 100644 --- a/crates/ide/src/diagnostics/diagnostics_with_fix.rs +++ b/crates/ide/src/diagnostics/fixes.rs @@ -1,7 +1,5 @@ //! Provides a way to attach fixes to the diagnostics. //! The same module also has all curret custom fixes for the diagnostics implemented. -use crate::Fix; -use ast::{edit::IndentLevel, make}; use base_db::FileId; use hir::{ db::AstDatabase, @@ -12,9 +10,15 @@ use ide_db::{ source_change::{FileSystemEdit, SourceFileEdit}, RootDatabase, }; -use syntax::{algo, ast, AstNode}; +use syntax::{ + algo, + ast::{self, edit::IndentLevel, make}, + AstNode, +}; use text_edit::TextEdit; +use crate::diagnostics::Fix; + /// A [Diagnostic] that potentially has a fix available. /// /// [Diagnostic]: hir::diagnostics::Diagnostic diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 2a73abba278..f37119e28bd 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -65,7 +65,7 @@ pub use crate::{ completion::{ CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, }, - diagnostics::{DiagnosticsConfig, Severity}, + diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity}, display::NavigationTarget, expand_macro::ExpandedMacro, file_structure::StructureNode, @@ -99,35 +99,6 @@ pub use text_edit::{Indel, TextEdit}; pub type Cancelable = Result; -#[derive(Debug)] -pub struct Diagnostic { - pub name: Option, - pub message: String, - pub range: TextRange, - pub severity: Severity, - pub fix: Option, -} - -#[derive(Debug)] -pub struct Fix { - pub label: String, - pub source_change: SourceChange, - /// Allows to trigger the fix only when the caret is in the range given - pub fix_trigger_range: TextRange, -} - -impl Fix { - pub fn new( - label: impl Into, - source_change: SourceChange, - fix_trigger_range: TextRange, - ) -> Self { - let label = label.into(); - assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.')); - Self { label, source_change, fix_trigger_range } - } -} - /// Info associated with a text range. #[derive(Debug)] pub struct RangeInfo {