aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_diagnostics/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-14 16:46:27 +0100
committerAleksey Kladov <[email protected]>2021-06-14 16:46:54 +0100
commit26c978f258ed2af45a6979eefea9860c1eaeacda (patch)
tree6b96b1d2f5ba48148dcfd6442ab9c742696e7847 /crates/ide_diagnostics/src
parenta91071b57be6e64ad2fd277998ada0ae6206457b (diff)
internal: adapt diagnostics to the new rename API
Diffstat (limited to 'crates/ide_diagnostics/src')
-rw-r--r--crates/ide_diagnostics/src/incorrect_case.rs46
1 files changed, 15 insertions, 31 deletions
diff --git a/crates/ide_diagnostics/src/incorrect_case.rs b/crates/ide_diagnostics/src/incorrect_case.rs
index 8e1a93aa7..2cf232d56 100644
--- a/crates/ide_diagnostics/src/incorrect_case.rs
+++ b/crates/ide_diagnostics/src/incorrect_case.rs
@@ -1,5 +1,5 @@
1use hir::{db::AstDatabase, InFile}; 1use hir::{db::AstDatabase, InFile};
2use ide_db::{assists::Assist, base_db::FilePosition}; 2use ide_db::{assists::Assist, defs::NameClass};
3use syntax::AstNode; 3use syntax::AstNode;
4 4
5use crate::{ 5use crate::{
@@ -27,35 +27,26 @@ pub(super) fn incorrect_case(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCas
27} 27}
28 28
29fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCase) -> Option<Vec<Assist>> { 29fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::IncorrectCase) -> Option<Vec<Assist>> {
30 if true {
31 return None;
32 }
33
34 let root = ctx.sema.db.parse_or_expand(d.file)?; 30 let root = ctx.sema.db.parse_or_expand(d.file)?;
35 let name_node = d.ident.to_node(&root); 31 let name_node = d.ident.to_node(&root);
32 let def = NameClass::classify(&ctx.sema, &name_node)?.defined(ctx.sema.db)?;
36 33
37 let name_node = InFile::new(d.file, name_node.syntax()); 34 let name_node = InFile::new(d.file, name_node.syntax());
38 let frange = name_node.original_file_range(ctx.sema.db); 35 let frange = name_node.original_file_range(ctx.sema.db);
39 let _file_position = FilePosition { file_id: frange.file_id, offset: frange.range.start() };
40 36
41 let label = format!("Rename to {}", d.suggested_text); 37 let label = format!("Rename to {}", d.suggested_text);
42 let res = unresolved_fix("change_case", &label, frange.range); 38 let mut res = unresolved_fix("change_case", &label, frange.range);
43 if ctx.resolve.should_resolve(&res.id) { 39 if ctx.resolve.should_resolve(&res.id) {
44 //let source_change = rename_with_semantics(&ctx.sema, file_position, &d.suggested_text); 40 let source_change = def.rename(&ctx.sema, &d.suggested_text);
45 //res.source_change = Some(source_change.ok().unwrap_or_default()); 41 res.source_change = Some(source_change.ok().unwrap_or_default());
46 todo!()
47 } 42 }
48 43
49 Some(vec![res]) 44 Some(vec![res])
50} 45}
51 46
52#[cfg(TODO)] 47#[cfg(test)]
53mod change_case { 48mod change_case {
54 use crate::{ 49 use crate::tests::{check_diagnostics, check_fix};
55 fixture,
56 tests::{check_diagnostics, check_fix},
57 AssistResolveStrategy, DiagnosticsConfig,
58 };
59 50
60 #[test] 51 #[test]
61 fn test_rename_incorrect_case() { 52 fn test_rename_incorrect_case() {
@@ -123,7 +114,7 @@ fn some_fn() {
123 check_diagnostics( 114 check_diagnostics(
124 r#" 115 r#"
125fn foo() { 116fn foo() {
126 const ANOTHER_ITEM$0: &str = "some_item"; 117 const ANOTHER_ITEM: &str = "some_item";
127} 118}
128"#, 119"#,
129 ); 120 );
@@ -155,20 +146,13 @@ impl TestStruct {
155 146
156 #[test] 147 #[test]
157 fn test_single_incorrect_case_diagnostic_in_function_name_issue_6970() { 148 fn test_single_incorrect_case_diagnostic_in_function_name_issue_6970() {
158 let input = r#"fn FOO$0() {}"#; 149 check_diagnostics(
159 let expected = r#"fn foo() {}"#; 150 r#"
160 151fn FOO() {}
161 let (analysis, file_position) = fixture::position(input); 152// ^^^ Function `FOO` should have snake_case name, e.g. `foo`
162 let diagnostics = analysis 153"#,
163 .diagnostics( 154 );
164 &DiagnosticsConfig::default(), 155 check_fix(r#"fn FOO$0() {}"#, r#"fn foo() {}"#);
165 AssistResolveStrategy::All,
166 file_position.file_id,
167 )
168 .unwrap();
169 assert_eq!(diagnostics.len(), 1);
170
171 check_fix(input, expected);
172 } 156 }
173 157
174 #[test] 158 #[test]