mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-13 23:28:13 +00:00
[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:
parent
b302d89da3
commit
a2c87c2bc1
7 changed files with 19 additions and 1 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue