mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-10-31 03:55:09 +00:00 
			
		
		
		
	[ty] Limit shown import paths to at most 5 unless ty runs with -v (#20912)
				
					
				
			This commit is contained in:
		
							parent
							
								
									c8133104e8
								
							
						
					
					
						commit
						9393279f65
					
				
					 11 changed files with 155 additions and 12 deletions
				
			
		|  | @ -12,6 +12,9 @@ pub trait Db: SourceDb { | |||
|     fn rule_selection(&self, file: File) -> &RuleSelection; | ||||
| 
 | ||||
|     fn lint_registry(&self) -> &LintRegistry; | ||||
| 
 | ||||
|     /// Whether ty is running with logging verbosity INFO or higher (`-v` or more).
 | ||||
|     fn verbose(&self) -> bool; | ||||
| } | ||||
| 
 | ||||
| #[cfg(test)] | ||||
|  | @ -126,6 +129,10 @@ pub(crate) mod tests { | |||
|         fn lint_registry(&self) -> &LintRegistry { | ||||
|             default_lint_registry() | ||||
|         } | ||||
| 
 | ||||
|         fn verbose(&self) -> bool { | ||||
|             false | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     #[salsa::db] | ||||
|  |  | |||
|  | @ -4811,22 +4811,29 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { | |||
| 
 | ||||
|             // Add search paths information to the diagnostic
 | ||||
|             // Use the same search paths function that is used in actual module resolution
 | ||||
|             let mut search_paths = | ||||
|                 search_paths(self.db(), ModuleResolveMode::StubsAllowed).peekable(); | ||||
|             let verbose = self.db().verbose(); | ||||
|             let search_paths = search_paths(self.db(), ModuleResolveMode::StubsAllowed); | ||||
| 
 | ||||
|             if search_paths.peek().is_some() { | ||||
|                 diagnostic.info(format_args!( | ||||
|                     "Searched in the following paths during module resolution:" | ||||
|                 )); | ||||
|             diagnostic.info(format_args!( | ||||
|                 "Searched in the following paths during module resolution:" | ||||
|             )); | ||||
| 
 | ||||
|                 for (index, path) in search_paths.enumerate() { | ||||
|             let mut search_paths = search_paths.enumerate(); | ||||
| 
 | ||||
|             while let Some((index, path)) = search_paths.next() { | ||||
|                 if index > 4 && !verbose { | ||||
|                     let more = search_paths.count() + 1; | ||||
|                     diagnostic.info(format_args!( | ||||
|                         "  {}. {} ({})", | ||||
|                         index + 1, | ||||
|                         path, | ||||
|                         path.describe_kind() | ||||
|                         "  ... and {more} more paths. Run with `-v` to see all paths." | ||||
|                     )); | ||||
|                     break; | ||||
|                 } | ||||
|                 diagnostic.info(format_args!( | ||||
|                     "  {}. {} ({})", | ||||
|                     index + 1, | ||||
|                     path, | ||||
|                     path.describe_kind() | ||||
|                 )); | ||||
|             } | ||||
| 
 | ||||
|             diagnostic.info( | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Micha Reiser
						Micha Reiser