mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 20:31:57 +00:00
[ty] Clarify what "cursor" means
This commit does a small refactor to combine the file and cursor offset into a single type. I think this makes it clearer that even if there are multiple files in the cursor test, this one in particular corresponds to the file that contains the `<CURSOR>` marker.
This commit is contained in:
parent
40731f0589
commit
cef1a522dc
4 changed files with 15 additions and 12 deletions
|
|
@ -2184,7 +2184,7 @@ importlib.<CURSOR>
|
|||
}
|
||||
|
||||
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 "<No completions found>".to_string();
|
||||
}
|
||||
|
|
@ -2198,7 +2198,7 @@ importlib.<CURSOR>
|
|||
|
||||
#[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.<CURSOR>
|
|||
|
||||
#[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
|
||||
|
|
|
|||
|
|
@ -833,7 +833,8 @@ f(**kwargs<CURSOR>)
|
|||
|
||||
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();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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 `<CURSOR>` 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 `<CURSOR>` 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 `<CURSOR>`");
|
||||
|
||||
CursorTest {
|
||||
db,
|
||||
cursor_offset: offset,
|
||||
file,
|
||||
cursor: cursor.expect("at least one source to contain `<CURSOR>`"),
|
||||
_insta_settings_guard: insta_settings_guard,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue