mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Normalize naming of diagnostics
This commit is contained in:
parent
df00da15c4
commit
3908fad1fe
5 changed files with 23 additions and 21 deletions
|
@ -64,7 +64,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
|
||||||
.unwrap_or_else(|| RelativePath::new(""))
|
.unwrap_or_else(|| RelativePath::new(""))
|
||||||
.join(&d.candidate);
|
.join(&d.candidate);
|
||||||
let create_file = FileSystemEdit::CreateFile { source_root, path };
|
let create_file = FileSystemEdit::CreateFile { source_root, path };
|
||||||
let fix = SourceChange::file_system_edit("create module", create_file);
|
let fix = SourceChange::file_system_edit("Create module", create_file);
|
||||||
res.borrow_mut().push(Diagnostic {
|
res.borrow_mut().push(Diagnostic {
|
||||||
range: sema.diagnostics_range(d).range,
|
range: sema.diagnostics_range(d).range,
|
||||||
message: d.message(),
|
message: d.message(),
|
||||||
|
@ -92,7 +92,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
|
||||||
algo::diff(&d.ast(db).syntax(), &field_list.syntax()).into_text_edit(&mut builder);
|
algo::diff(&d.ast(db).syntax(), &field_list.syntax()).into_text_edit(&mut builder);
|
||||||
|
|
||||||
Some(SourceChange::source_file_edit_from(
|
Some(SourceChange::source_file_edit_from(
|
||||||
"fill struct fields",
|
"Fill struct fields",
|
||||||
file_id,
|
file_id,
|
||||||
builder.finish(),
|
builder.finish(),
|
||||||
))
|
))
|
||||||
|
@ -117,7 +117,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
|
||||||
let node = d.ast(db);
|
let node = d.ast(db);
|
||||||
let replacement = format!("Ok({})", node.syntax());
|
let replacement = format!("Ok({})", node.syntax());
|
||||||
let edit = TextEdit::replace(node.syntax().text_range(), replacement);
|
let edit = TextEdit::replace(node.syntax().text_range(), replacement);
|
||||||
let fix = SourceChange::source_file_edit_from("wrap with ok", file_id, edit);
|
let fix = SourceChange::source_file_edit_from("Wrap with ok", file_id, edit);
|
||||||
res.borrow_mut().push(Diagnostic {
|
res.borrow_mut().push(Diagnostic {
|
||||||
range: sema.diagnostics_range(d).range,
|
range: sema.diagnostics_range(d).range,
|
||||||
message: d.message(),
|
message: d.message(),
|
||||||
|
@ -199,7 +199,7 @@ fn check_struct_shorthand_initialization(
|
||||||
message: "Shorthand struct initialization".to_string(),
|
message: "Shorthand struct initialization".to_string(),
|
||||||
severity: Severity::WeakWarning,
|
severity: Severity::WeakWarning,
|
||||||
fix: Some(SourceChange::source_file_edit(
|
fix: Some(SourceChange::source_file_edit(
|
||||||
"use struct shorthand initialization",
|
"Use struct shorthand initialization",
|
||||||
SourceFileEdit { file_id, edit },
|
SourceFileEdit { file_id, edit },
|
||||||
)),
|
)),
|
||||||
});
|
});
|
||||||
|
@ -606,7 +606,7 @@ mod tests {
|
||||||
range: 0..8,
|
range: 0..8,
|
||||||
fix: Some(
|
fix: Some(
|
||||||
SourceChange {
|
SourceChange {
|
||||||
label: "create module",
|
label: "Create module",
|
||||||
source_file_edits: [],
|
source_file_edits: [],
|
||||||
file_system_edits: [
|
file_system_edits: [
|
||||||
CreateFile {
|
CreateFile {
|
||||||
|
@ -655,7 +655,7 @@ mod tests {
|
||||||
range: 224..233,
|
range: 224..233,
|
||||||
fix: Some(
|
fix: Some(
|
||||||
SourceChange {
|
SourceChange {
|
||||||
label: "fill struct fields",
|
label: "Fill struct fields",
|
||||||
source_file_edits: [
|
source_file_edits: [
|
||||||
SourceFileEdit {
|
SourceFileEdit {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
|
|
|
@ -122,7 +122,7 @@ fn rename_mod(
|
||||||
source_file_edits.extend(ref_edits);
|
source_file_edits.extend(ref_edits);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(SourceChange::from_edits("rename", source_file_edits, file_system_edits))
|
Some(SourceChange::from_edits("Rename", source_file_edits, file_system_edits))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rename_reference(
|
fn rename_reference(
|
||||||
|
@ -141,7 +141,7 @@ fn rename_reference(
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(RangeInfo::new(range, SourceChange::source_file_edits("rename", edit)))
|
Some(RangeInfo::new(range, SourceChange::source_file_edits("Rename", edit)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -530,7 +530,7 @@ mod tests {
|
||||||
RangeInfo {
|
RangeInfo {
|
||||||
range: 4..7,
|
range: 4..7,
|
||||||
info: SourceChange {
|
info: SourceChange {
|
||||||
label: "rename",
|
label: "Rename",
|
||||||
source_file_edits: [
|
source_file_edits: [
|
||||||
SourceFileEdit {
|
SourceFileEdit {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
|
@ -582,7 +582,7 @@ mod tests {
|
||||||
RangeInfo {
|
RangeInfo {
|
||||||
range: 4..7,
|
range: 4..7,
|
||||||
info: SourceChange {
|
info: SourceChange {
|
||||||
label: "rename",
|
label: "Rename",
|
||||||
source_file_edits: [
|
source_file_edits: [
|
||||||
SourceFileEdit {
|
SourceFileEdit {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
|
@ -665,7 +665,7 @@ mod tests {
|
||||||
RangeInfo {
|
RangeInfo {
|
||||||
range: 8..11,
|
range: 8..11,
|
||||||
info: SourceChange {
|
info: SourceChange {
|
||||||
label: "rename",
|
label: "Rename",
|
||||||
source_file_edits: [
|
source_file_edits: [
|
||||||
SourceFileEdit {
|
SourceFileEdit {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
|
|
|
@ -35,8 +35,10 @@ impl SourceChange {
|
||||||
/// Creates a new SourceChange with the given label,
|
/// Creates a new SourceChange with the given label,
|
||||||
/// containing only the given `SourceFileEdits`.
|
/// containing only the given `SourceFileEdits`.
|
||||||
pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self {
|
pub(crate) fn source_file_edits<L: Into<String>>(label: L, edits: Vec<SourceFileEdit>) -> Self {
|
||||||
|
let label = label.into();
|
||||||
|
assert!(label.starts_with(char::is_uppercase));
|
||||||
SourceChange {
|
SourceChange {
|
||||||
label: label.into(),
|
label: label,
|
||||||
source_file_edits: edits,
|
source_file_edits: edits,
|
||||||
file_system_edits: vec![],
|
file_system_edits: vec![],
|
||||||
cursor_position: None,
|
cursor_position: None,
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
SourceChange::source_file_edit(
|
SourceChange::source_file_edit(
|
||||||
"on enter",
|
"On enter",
|
||||||
SourceFileEdit { edit, file_id: position.file_id },
|
SourceFileEdit { edit, file_id: position.file_id },
|
||||||
)
|
)
|
||||||
.with_cursor(FilePosition { offset: cursor_position, file_id: position.file_id }),
|
.with_cursor(FilePosition { offset: cursor_position, file_id: position.file_id }),
|
||||||
|
|
|
@ -337,7 +337,7 @@ fn main() {}
|
||||||
"arguments": [
|
"arguments": [
|
||||||
{
|
{
|
||||||
"cursorPosition": null,
|
"cursorPosition": null,
|
||||||
"label": "create module",
|
"label": "Create module",
|
||||||
"workspaceEdit": {
|
"workspaceEdit": {
|
||||||
"documentChanges": [
|
"documentChanges": [
|
||||||
{
|
{
|
||||||
|
@ -349,9 +349,9 @@ fn main() {}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"command": "rust-analyzer.applySourceChange",
|
"command": "rust-analyzer.applySourceChange",
|
||||||
"title": "create module"
|
"title": "Create module"
|
||||||
},
|
},
|
||||||
"title": "create module"
|
"title": "Create module"
|
||||||
}
|
}
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
@ -420,7 +420,7 @@ fn main() {{}}
|
||||||
"arguments": [
|
"arguments": [
|
||||||
{
|
{
|
||||||
"cursorPosition": null,
|
"cursorPosition": null,
|
||||||
"label": "create module",
|
"label": "Create module",
|
||||||
"workspaceEdit": {
|
"workspaceEdit": {
|
||||||
"documentChanges": [
|
"documentChanges": [
|
||||||
{
|
{
|
||||||
|
@ -432,9 +432,9 @@ fn main() {{}}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"command": "rust-analyzer.applySourceChange",
|
"command": "rust-analyzer.applySourceChange",
|
||||||
"title": "create module"
|
"title": "Create module"
|
||||||
},
|
},
|
||||||
"title": "create module"
|
"title": "Create module"
|
||||||
}
|
}
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
@ -500,7 +500,7 @@ fn main() {{}}
|
||||||
"position": { "character": 4, "line": 1 },
|
"position": { "character": 4, "line": 1 },
|
||||||
"textDocument": { "uri": "file:///[..]src/m0.rs" }
|
"textDocument": { "uri": "file:///[..]src/m0.rs" }
|
||||||
},
|
},
|
||||||
"label": "on enter",
|
"label": "On enter",
|
||||||
"workspaceEdit": {
|
"workspaceEdit": {
|
||||||
"documentChanges": [
|
"documentChanges": [
|
||||||
{
|
{
|
||||||
|
@ -552,7 +552,7 @@ version = \"0.0.0\"
|
||||||
"position": { "line": 1, "character": 4 },
|
"position": { "line": 1, "character": 4 },
|
||||||
"textDocument": { "uri": "file:///[..]src/main.rs" }
|
"textDocument": { "uri": "file:///[..]src/main.rs" }
|
||||||
},
|
},
|
||||||
"label": "on enter",
|
"label": "On enter",
|
||||||
"workspaceEdit": {
|
"workspaceEdit": {
|
||||||
"documentChanges": [
|
"documentChanges": [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue