Normalize naming of diagnostics

This commit is contained in:
Aleksey Kladov 2020-05-05 20:55:12 +02:00
parent df00da15c4
commit 3908fad1fe
5 changed files with 23 additions and 21 deletions

View file

@ -64,7 +64,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
.unwrap_or_else(|| RelativePath::new(""))
.join(&d.candidate);
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 {
range: sema.diagnostics_range(d).range,
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);
Some(SourceChange::source_file_edit_from(
"fill struct fields",
"Fill struct fields",
file_id,
builder.finish(),
))
@ -117,7 +117,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
let node = d.ast(db);
let replacement = format!("Ok({})", node.syntax());
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 {
range: sema.diagnostics_range(d).range,
message: d.message(),
@ -199,7 +199,7 @@ fn check_struct_shorthand_initialization(
message: "Shorthand struct initialization".to_string(),
severity: Severity::WeakWarning,
fix: Some(SourceChange::source_file_edit(
"use struct shorthand initialization",
"Use struct shorthand initialization",
SourceFileEdit { file_id, edit },
)),
});
@ -606,7 +606,7 @@ mod tests {
range: 0..8,
fix: Some(
SourceChange {
label: "create module",
label: "Create module",
source_file_edits: [],
file_system_edits: [
CreateFile {
@ -655,7 +655,7 @@ mod tests {
range: 224..233,
fix: Some(
SourceChange {
label: "fill struct fields",
label: "Fill struct fields",
source_file_edits: [
SourceFileEdit {
file_id: FileId(

View file

@ -122,7 +122,7 @@ fn rename_mod(
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(
@ -141,7 +141,7 @@ fn rename_reference(
return None;
}
Some(RangeInfo::new(range, SourceChange::source_file_edits("rename", edit)))
Some(RangeInfo::new(range, SourceChange::source_file_edits("Rename", edit)))
}
#[cfg(test)]
@ -530,7 +530,7 @@ mod tests {
RangeInfo {
range: 4..7,
info: SourceChange {
label: "rename",
label: "Rename",
source_file_edits: [
SourceFileEdit {
file_id: FileId(
@ -582,7 +582,7 @@ mod tests {
RangeInfo {
range: 4..7,
info: SourceChange {
label: "rename",
label: "Rename",
source_file_edits: [
SourceFileEdit {
file_id: FileId(
@ -665,7 +665,7 @@ mod tests {
RangeInfo {
range: 8..11,
info: SourceChange {
label: "rename",
label: "Rename",
source_file_edits: [
SourceFileEdit {
file_id: FileId(

View file

@ -35,8 +35,10 @@ impl SourceChange {
/// Creates a new SourceChange with the given label,
/// containing only the given `SourceFileEdits`.
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 {
label: label.into(),
label: label,
source_file_edits: edits,
file_system_edits: vec![],
cursor_position: None,

View file

@ -44,7 +44,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Sour
Some(
SourceChange::source_file_edit(
"on enter",
"On enter",
SourceFileEdit { edit, file_id: position.file_id },
)
.with_cursor(FilePosition { offset: cursor_position, file_id: position.file_id }),

View file

@ -337,7 +337,7 @@ fn main() {}
"arguments": [
{
"cursorPosition": null,
"label": "create module",
"label": "Create module",
"workspaceEdit": {
"documentChanges": [
{
@ -349,9 +349,9 @@ fn main() {}
}
],
"command": "rust-analyzer.applySourceChange",
"title": "create module"
"title": "Create module"
},
"title": "create module"
"title": "Create module"
}
]),
);
@ -420,7 +420,7 @@ fn main() {{}}
"arguments": [
{
"cursorPosition": null,
"label": "create module",
"label": "Create module",
"workspaceEdit": {
"documentChanges": [
{
@ -432,9 +432,9 @@ fn main() {{}}
}
],
"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 },
"textDocument": { "uri": "file:///[..]src/m0.rs" }
},
"label": "on enter",
"label": "On enter",
"workspaceEdit": {
"documentChanges": [
{
@ -552,7 +552,7 @@ version = \"0.0.0\"
"position": { "line": 1, "character": 4 },
"textDocument": { "uri": "file:///[..]src/main.rs" }
},
"label": "on enter",
"label": "On enter",
"workspaceEdit": {
"documentChanges": [
{