mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Minor
This commit is contained in:
parent
0866b1be89
commit
eb81731600
3 changed files with 40 additions and 36 deletions
|
@ -4,7 +4,7 @@
|
||||||
//! macro-expanded files, but we need to present them to the users in terms of
|
//! macro-expanded files, but we need to present them to the users in terms of
|
||||||
//! original files. So we need to map the ranges.
|
//! original files. So we need to map the ranges.
|
||||||
|
|
||||||
mod diagnostics_with_fix;
|
mod fixes;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
@ -19,9 +19,38 @@ use syntax::{
|
||||||
};
|
};
|
||||||
use text_edit::TextEdit;
|
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)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum Severity {
|
pub enum Severity {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
//! Provides a way to attach fixes to the diagnostics.
|
//! Provides a way to attach fixes to the diagnostics.
|
||||||
//! The same module also has all curret custom fixes for the diagnostics implemented.
|
//! 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 base_db::FileId;
|
||||||
use hir::{
|
use hir::{
|
||||||
db::AstDatabase,
|
db::AstDatabase,
|
||||||
|
@ -12,9 +10,15 @@ use ide_db::{
|
||||||
source_change::{FileSystemEdit, SourceFileEdit},
|
source_change::{FileSystemEdit, SourceFileEdit},
|
||||||
RootDatabase,
|
RootDatabase,
|
||||||
};
|
};
|
||||||
use syntax::{algo, ast, AstNode};
|
use syntax::{
|
||||||
|
algo,
|
||||||
|
ast::{self, edit::IndentLevel, make},
|
||||||
|
AstNode,
|
||||||
|
};
|
||||||
use text_edit::TextEdit;
|
use text_edit::TextEdit;
|
||||||
|
|
||||||
|
use crate::diagnostics::Fix;
|
||||||
|
|
||||||
/// A [Diagnostic] that potentially has a fix available.
|
/// A [Diagnostic] that potentially has a fix available.
|
||||||
///
|
///
|
||||||
/// [Diagnostic]: hir::diagnostics::Diagnostic
|
/// [Diagnostic]: hir::diagnostics::Diagnostic
|
|
@ -65,7 +65,7 @@ pub use crate::{
|
||||||
completion::{
|
completion::{
|
||||||
CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat,
|
CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat,
|
||||||
},
|
},
|
||||||
diagnostics::{DiagnosticsConfig, Severity},
|
diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity},
|
||||||
display::NavigationTarget,
|
display::NavigationTarget,
|
||||||
expand_macro::ExpandedMacro,
|
expand_macro::ExpandedMacro,
|
||||||
file_structure::StructureNode,
|
file_structure::StructureNode,
|
||||||
|
@ -99,35 +99,6 @@ pub use text_edit::{Indel, TextEdit};
|
||||||
|
|
||||||
pub type Cancelable<T> = Result<T, Canceled>;
|
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.
|
/// Info associated with a text range.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RangeInfo<T> {
|
pub struct RangeInfo<T> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue