[ty] Add note to unresolved-import hinting to users to configure their Python environment (#18207)
Closes https://github.com/astral-sh/ty/issues/453. ## Summary Add an additional info diagnostic to `unresolved-import` check to hint to users that they should make sure their Python environment is properly configured for ty, linking them to the corresponding doc. This diagnostic is only shown when an import is not relative, e.g., `import maturin` not `import .maturin`. ## Test Plan Updated snapshots with new info message and reran tests.
This commit is contained in:
@@ -3812,11 +3812,16 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||
let Some(builder) = self.context.report_lint(&UNRESOLVED_IMPORT, range) else {
|
||||
return;
|
||||
};
|
||||
builder.into_diagnostic(format_args!(
|
||||
let mut diagnostic = builder.into_diagnostic(format_args!(
|
||||
"Cannot resolve imported module `{}{}`",
|
||||
".".repeat(level as usize),
|
||||
module.unwrap_or_default()
|
||||
));
|
||||
if level == 0 {
|
||||
diagnostic.info(
|
||||
"make sure your Python environment is properly configured: https://github.com/astral-sh/ty/blob/main/docs/README.md#python-environment"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn infer_import_definition(
|
||||
|
||||
Reference in New Issue
Block a user