From 4dac3d105dc2645968395113883f84c2e469dc47 Mon Sep 17 00:00:00 2001 From: RasmusNygren Date: Tue, 30 Dec 2025 09:10:14 +0100 Subject: [PATCH] [ty] Add skip_dunders option to CompletionTestBuilder (#22293) Co-authored-by: Micha Reiser --- crates/ty_ide/src/completion.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/ty_ide/src/completion.rs b/crates/ty_ide/src/completion.rs index 21e3951c29..7f08e1390f 100644 --- a/crates/ty_ide/src/completion.rs +++ b/crates/ty_ide/src/completion.rs @@ -2076,6 +2076,7 @@ fn token_suffix_by_kinds( #[cfg(test)] mod tests { use insta::assert_snapshot; + use ruff_python_ast::helpers::is_dunder; use ruff_python_ast::token::{TokenKind, Tokens}; use ruff_python_parser::{Mode, ParseOptions}; use ty_module_resolver::ModuleName; @@ -4027,7 +4028,10 @@ b.a. ", ); - builder.build().not_contains("a").contains("x"); + assert_snapshot!(builder.skip_dunders().build().snapshot(), + @r" + x + "); } #[test] @@ -7538,6 +7542,7 @@ TypedDi settings: CompletionSettings, skip_builtins: bool, skip_keywords: bool, + skip_dunders: bool, type_signatures: bool, imports: bool, module_names: bool, @@ -7559,6 +7564,7 @@ TypedDi .iter() .filter(|c| !self.skip_builtins || !c.builtin) .filter(|c| !self.skip_keywords || c.kind != Some(CompletionKind::Keyword)) + .filter(|c| !self.skip_dunders || !is_dunder(&c.name)) .filter(|c| { self.predicate .as_ref() @@ -7622,6 +7628,16 @@ TypedDi self } + /// When set, dunder completions are skipped. + /// This is useful to reduce noise for snapshot tests + /// when filtering on methods and attributes. + /// + /// Not enabled by default. + fn skip_dunders(mut self) -> CompletionTestBuilder { + self.skip_dunders = true; + self + } + /// When set, type signatures of each completion item are /// included in the snapshot. This is useful when one wants /// to specifically test types, but it usually best to leave @@ -7770,6 +7786,7 @@ TypedDi settings: CompletionSettings::default(), skip_builtins: false, skip_keywords: false, + skip_dunders: false, type_signatures: false, imports: false, module_names: false,