aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/diagnostics.rs13
-rw-r--r--crates/ide/src/goto_definition.rs25
-rw-r--r--crates/ide/src/lib.rs30
-rw-r--r--crates/ide/src/references/rename.rs19
4 files changed, 75 insertions, 12 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 3ad30f0c9..b2714cb69 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -895,4 +895,17 @@ impl TestStruct {
895"#, 895"#,
896 ); 896 );
897 } 897 }
898
899 #[test]
900 fn test_single_incorrect_case_diagnostic_in_function_name_issue_6970() {
901 let input = r#"fn FOO<|>() {}"#;
902 let expected = r#"fn foo() {}"#;
903
904 let (analysis, file_position) = fixture::position(input);
905 let diagnostics =
906 analysis.diagnostics(&DiagnosticsConfig::default(), file_position.file_id).unwrap();
907 assert_eq!(diagnostics.len(), 1);
908
909 check_fixes(input, expected);
910 }
898} 911}
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs
index 65e45c920..912144f8b 100644
--- a/crates/ide/src/goto_definition.rs
+++ b/crates/ide/src/goto_definition.rs
@@ -750,6 +750,31 @@ fn test() {
750 } 750 }
751 751
752 #[test] 752 #[test]
753 fn goto_through_included_file() {
754 check(
755 r#"
756//- /main.rs
757#[rustc_builtin_macro]
758macro_rules! include {}
759
760 include!("foo.rs");
761//^^^^^^^^^^^^^^^^^^^
762
763fn f() {
764 foo<|>();
765}
766
767mod confuse_index {
768 pub fn foo() {}
769}
770
771//- /foo.rs
772fn foo() {}
773 "#,
774 );
775 }
776
777 #[test]
753 fn goto_for_type_param() { 778 fn goto_for_type_param() {
754 check( 779 check(
755 r#" 780 r#"
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index dbad9a84f..a75cc85b6 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -490,8 +490,18 @@ impl Analysis {
490 .unwrap_or_default()) 490 .unwrap_or_default())
491 } 491 }
492 492
493 /// Computes assists (aka code actions aka intentions) for the given
494 /// position. Computes enough info to show the lightbulb list in the editor,
495 /// but doesn't compute actual edits, to improve performance.
496 ///
497 /// When the user clicks on the assist, call `resolve_assists` to get the
498 /// edit.
499 pub fn assists(&self, config: &AssistConfig, frange: FileRange) -> Cancelable<Vec<Assist>> {
500 self.with_db(|db| Assist::unresolved(db, config, frange))
501 }
502
493 /// Computes resolved assists with source changes for the given position. 503 /// Computes resolved assists with source changes for the given position.
494 pub fn resolved_assists( 504 pub fn resolve_assists(
495 &self, 505 &self,
496 config: &AssistConfig, 506 config: &AssistConfig,
497 frange: FileRange, 507 frange: FileRange,
@@ -499,16 +509,6 @@ impl Analysis {
499 self.with_db(|db| assists::Assist::resolved(db, config, frange)) 509 self.with_db(|db| assists::Assist::resolved(db, config, frange))
500 } 510 }
501 511
502 /// Computes unresolved assists (aka code actions aka intentions) for the given
503 /// position.
504 pub fn unresolved_assists(
505 &self,
506 config: &AssistConfig,
507 frange: FileRange,
508 ) -> Cancelable<Vec<Assist>> {
509 self.with_db(|db| Assist::unresolved(db, config, frange))
510 }
511
512 /// Computes the set of diagnostics for the given file. 512 /// Computes the set of diagnostics for the given file.
513 pub fn diagnostics( 513 pub fn diagnostics(
514 &self, 514 &self,
@@ -535,6 +535,14 @@ impl Analysis {
535 self.with_db(|db| references::rename::prepare_rename(db, position)) 535 self.with_db(|db| references::rename::prepare_rename(db, position))
536 } 536 }
537 537
538 pub fn will_rename_file(
539 &self,
540 file_id: FileId,
541 new_name_stem: &str,
542 ) -> Cancelable<Option<SourceChange>> {
543 self.with_db(|db| references::rename::will_rename_file(db, file_id, new_name_stem))
544 }
545
538 pub fn structural_search_replace( 546 pub fn structural_search_replace(
539 &self, 547 &self,
540 query: &str, 548 query: &str,
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs
index 4f353852f..854bf194e 100644
--- a/crates/ide/src/references/rename.rs
+++ b/crates/ide/src/references/rename.rs
@@ -6,7 +6,7 @@ use std::{
6}; 6};
7 7
8use hir::{Module, ModuleDef, ModuleSource, Semantics}; 8use hir::{Module, ModuleDef, ModuleSource, Semantics};
9use ide_db::base_db::{AnchoredPathBuf, FileRange, SourceDatabaseExt}; 9use ide_db::base_db::{AnchoredPathBuf, FileId, FileRange, SourceDatabaseExt};
10use ide_db::{ 10use ide_db::{
11 defs::{Definition, NameClass, NameRefClass}, 11 defs::{Definition, NameClass, NameRefClass},
12 RootDatabase, 12 RootDatabase,
@@ -110,6 +110,23 @@ pub(crate) fn rename_with_semantics(
110 } 110 }
111} 111}
112 112
113pub(crate) fn will_rename_file(
114 db: &RootDatabase,
115 file_id: FileId,
116 new_name_stem: &str,
117) -> Option<SourceChange> {
118 let sema = Semantics::new(db);
119 let module = sema.to_module_def(file_id)?;
120
121 let decl = module.declaration_source(db)?;
122 let range = decl.value.name()?.syntax().text_range();
123
124 let position = FilePosition { file_id: decl.file_id.original_file(db), offset: range.start() };
125 let mut change = rename_mod(&sema, position, module, new_name_stem).ok()?.info;
126 change.file_system_edits.clear();
127 Some(change)
128}
129
113fn find_module_at_offset( 130fn find_module_at_offset(
114 sema: &Semantics<RootDatabase>, 131 sema: &Semantics<RootDatabase>,
115 position: FilePosition, 132 position: FilePosition,