5797: Minor
 r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-08-18 14:22:36 +00:00 committed by GitHub
commit e81c310b62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 36 deletions

View file

@ -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<String>,
pub message: String,
pub range: TextRange,
pub severity: Severity,
pub fix: Option<Fix>,
}
#[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<String>,
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 {

View file

@ -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

View file

@ -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<T> = Result<T, Canceled>;
#[derive(Debug)]
pub struct Diagnostic {
pub name: Option<String>,
pub message: String,
pub range: TextRange,
pub severity: Severity,
pub fix: Option<Fix>,
}
#[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<String>,
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<T> {