Skip to content

Commit e81c310

Browse files
bors[bot]matklad
andauthored
Merge #5797
5797: Minor r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 0e66dc6 + eb81731 commit e81c310

File tree

3 files changed

+40
-36
lines changed

3 files changed

+40
-36
lines changed

crates/ide/src/diagnostics.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! macro-expanded files, but we need to present them to the users in terms of
55
//! original files. So we need to map the ranges.
66
7-
mod diagnostics_with_fix;
7+
mod fixes;
88

99
use std::cell::RefCell;
1010

@@ -19,9 +19,38 @@ use syntax::{
1919
};
2020
use text_edit::TextEdit;
2121

22-
use crate::{Diagnostic, FileId, Fix, SourceFileEdit};
22+
use crate::{FileId, SourceChange, SourceFileEdit};
2323

24-
use self::diagnostics_with_fix::DiagnosticWithFix;
24+
use self::fixes::DiagnosticWithFix;
25+
26+
#[derive(Debug)]
27+
pub struct Diagnostic {
28+
pub name: Option<String>,
29+
pub message: String,
30+
pub range: TextRange,
31+
pub severity: Severity,
32+
pub fix: Option<Fix>,
33+
}
34+
35+
#[derive(Debug)]
36+
pub struct Fix {
37+
pub label: String,
38+
pub source_change: SourceChange,
39+
/// Allows to trigger the fix only when the caret is in the range given
40+
pub fix_trigger_range: TextRange,
41+
}
42+
43+
impl Fix {
44+
fn new(
45+
label: impl Into<String>,
46+
source_change: SourceChange,
47+
fix_trigger_range: TextRange,
48+
) -> Self {
49+
let label = label.into();
50+
assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.'));
51+
Self { label, source_change, fix_trigger_range }
52+
}
53+
}
2554

2655
#[derive(Debug, Copy, Clone)]
2756
pub enum Severity {

crates/ide/src/diagnostics/diagnostics_with_fix.rs renamed to crates/ide/src/diagnostics/fixes.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Provides a way to attach fixes to the diagnostics.
22
//! The same module also has all curret custom fixes for the diagnostics implemented.
3-
use crate::Fix;
4-
use ast::{edit::IndentLevel, make};
53
use base_db::FileId;
64
use hir::{
75
db::AstDatabase,
@@ -12,9 +10,15 @@ use ide_db::{
1210
source_change::{FileSystemEdit, SourceFileEdit},
1311
RootDatabase,
1412
};
15-
use syntax::{algo, ast, AstNode};
13+
use syntax::{
14+
algo,
15+
ast::{self, edit::IndentLevel, make},
16+
AstNode,
17+
};
1618
use text_edit::TextEdit;
1719

20+
use crate::diagnostics::Fix;
21+
1822
/// A [Diagnostic] that potentially has a fix available.
1923
///
2024
/// [Diagnostic]: hir::diagnostics::Diagnostic

crates/ide/src/lib.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub use crate::{
6565
completion::{
6666
CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat,
6767
},
68-
diagnostics::{DiagnosticsConfig, Severity},
68+
diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity},
6969
display::NavigationTarget,
7070
expand_macro::ExpandedMacro,
7171
file_structure::StructureNode,
@@ -99,35 +99,6 @@ pub use text_edit::{Indel, TextEdit};
9999

100100
pub type Cancelable<T> = Result<T, Canceled>;
101101

102-
#[derive(Debug)]
103-
pub struct Diagnostic {
104-
pub name: Option<String>,
105-
pub message: String,
106-
pub range: TextRange,
107-
pub severity: Severity,
108-
pub fix: Option<Fix>,
109-
}
110-
111-
#[derive(Debug)]
112-
pub struct Fix {
113-
pub label: String,
114-
pub source_change: SourceChange,
115-
/// Allows to trigger the fix only when the caret is in the range given
116-
pub fix_trigger_range: TextRange,
117-
}
118-
119-
impl Fix {
120-
pub fn new(
121-
label: impl Into<String>,
122-
source_change: SourceChange,
123-
fix_trigger_range: TextRange,
124-
) -> Self {
125-
let label = label.into();
126-
assert!(label.starts_with(char::is_uppercase) && !label.ends_with('.'));
127-
Self { label, source_change, fix_trigger_range }
128-
}
129-
}
130-
131102
/// Info associated with a text range.
132103
#[derive(Debug)]
133104
pub struct RangeInfo<T> {

0 commit comments

Comments
 (0)