diff --git a/crates/ty_ide/src/completion.rs b/crates/ty_ide/src/completion.rs index 30d5fd6616..f74ffac2c9 100644 --- a/crates/ty_ide/src/completion.rs +++ b/crates/ty_ide/src/completion.rs @@ -2184,7 +2184,7 @@ importlib. } fn completions_if(&self, predicate: impl Fn(&str) -> bool) -> String { - let completions = completion(&self.db, self.file, self.cursor_offset); + let completions = completion(&self.db, self.cursor.file, self.cursor.offset); if completions.is_empty() { return "".to_string(); } @@ -2198,7 +2198,7 @@ importlib. #[track_caller] fn assert_completions_include(&self, expected: &str) { - let completions = completion(&self.db, self.file, self.cursor_offset); + let completions = completion(&self.db, self.cursor.file, self.cursor.offset); assert!( completions @@ -2210,7 +2210,7 @@ importlib. #[track_caller] fn assert_completions_do_not_include(&self, unexpected: &str) { - let completions = completion(&self.db, self.file, self.cursor_offset); + let completions = completion(&self.db, self.cursor.file, self.cursor.offset); assert!( completions diff --git a/crates/ty_ide/src/goto.rs b/crates/ty_ide/src/goto.rs index 80d26f8f7d..cac695197d 100644 --- a/crates/ty_ide/src/goto.rs +++ b/crates/ty_ide/src/goto.rs @@ -833,7 +833,8 @@ f(**kwargs) impl CursorTest { fn goto_type_definition(&self) -> String { - let Some(targets) = goto_type_definition(&self.db, self.file, self.cursor_offset) + let Some(targets) = + goto_type_definition(&self.db, self.cursor.file, self.cursor.offset) else { return "No goto target found".to_string(); }; diff --git a/crates/ty_ide/src/hover.rs b/crates/ty_ide/src/hover.rs index 34ce394b9f..af8d5d3328 100644 --- a/crates/ty_ide/src/hover.rs +++ b/crates/ty_ide/src/hover.rs @@ -737,7 +737,7 @@ mod tests { fn hover(&self) -> String { use std::fmt::Write; - let Some(hover) = hover(&self.db, self.file, self.cursor_offset) else { + let Some(hover) = hover(&self.db, self.cursor.file, self.cursor.offset) else { return "Hover provided no content".to_string(); }; @@ -769,7 +769,7 @@ mod tests { ); diagnostic.annotate( Annotation::secondary( - Span::from(source.file()).with_range(TextRange::empty(self.cursor_offset)), + Span::from(source.file()).with_range(TextRange::empty(self.cursor.offset)), ) .message("Cursor offset"), ); diff --git a/crates/ty_ide/src/lib.rs b/crates/ty_ide/src/lib.rs index 017639b664..f7a1168329 100644 --- a/crates/ty_ide/src/lib.rs +++ b/crates/ty_ide/src/lib.rs @@ -213,14 +213,17 @@ mod tests { SearchPathSettings, }; + /// A way to create a simple single-file (named `main.py`) cursor test. + /// + /// Use cases that require multiple files with a `` marker + /// in a file other than `main.py` can use `CursorTest::builder()`. pub(super) fn cursor_test(source: &str) -> CursorTest { CursorTest::builder().source("main.py", source).build() } pub(super) struct CursorTest { pub(super) db: TestDb, - pub(super) cursor_offset: TextSize, - pub(super) file: File, + pub(super) cursor: Cursor, _insta_settings_guard: SettingsBindDropGuard, } @@ -258,6 +261,8 @@ mod tests { } } + /// The file and offset into that file containing + /// a `` marker. pub(super) struct Cursor { pub(super) file: File, pub(super) offset: TextSize, @@ -318,13 +323,10 @@ mod tests { insta_settings.add_filter(r"@Todo\(.+\)", "@Todo"); let insta_settings_guard = insta_settings.bind_to_scope(); - let Cursor { file, offset } = - cursor.expect("at least one source to contain ``"); CursorTest { db, - cursor_offset: offset, - file, + cursor: cursor.expect("at least one source to contain ``"), _insta_settings_guard: insta_settings_guard, } }