mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
refactor: simplify signature of diagnose_resolution (#19753)
This commit makes the data flow in the `diagnose_dependency` function more obvious.
This commit is contained in:
parent
4f8f258851
commit
abdea44f3a
1 changed files with 35 additions and 30 deletions
|
@ -1082,13 +1082,11 @@ impl DenoDiagnostic {
|
|||
}
|
||||
|
||||
fn diagnose_resolution(
|
||||
lsp_diagnostics: &mut Vec<lsp::Diagnostic>,
|
||||
snapshot: &language_server::StateSnapshot,
|
||||
resolution: &Resolution,
|
||||
is_dynamic: bool,
|
||||
maybe_assert_type: Option<&str>,
|
||||
ranges: Vec<lsp::Range>,
|
||||
) {
|
||||
) -> Vec<DenoDiagnostic> {
|
||||
let mut diagnostics = vec![];
|
||||
match resolution {
|
||||
Resolution::Ok(resolved) => {
|
||||
|
@ -1172,11 +1170,7 @@ fn diagnose_resolution(
|
|||
}
|
||||
_ => (),
|
||||
}
|
||||
for range in ranges {
|
||||
for diagnostic in &diagnostics {
|
||||
lsp_diagnostics.push(diagnostic.to_lsp_diagnostic(&range));
|
||||
}
|
||||
}
|
||||
diagnostics
|
||||
}
|
||||
|
||||
/// Generate diagnostics related to a dependency. The dependency is analyzed to
|
||||
|
@ -1210,8 +1204,15 @@ fn diagnose_dependency(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
let import_ranges: Vec<_> = dependency
|
||||
.imports
|
||||
.iter()
|
||||
.map(|i| documents::to_lsp_range(&i.range))
|
||||
.collect();
|
||||
|
||||
diagnostics.extend(
|
||||
diagnose_resolution(
|
||||
diagnostics,
|
||||
snapshot,
|
||||
if dependency.maybe_code.is_none() {
|
||||
&dependency.maybe_type
|
||||
|
@ -1220,11 +1221,13 @@ fn diagnose_dependency(
|
|||
},
|
||||
dependency.is_dynamic,
|
||||
dependency.maybe_assert_type.as_deref(),
|
||||
dependency
|
||||
.imports
|
||||
)
|
||||
.iter()
|
||||
.map(|i| documents::to_lsp_range(&i.range))
|
||||
.collect(),
|
||||
.flat_map(|diag| {
|
||||
import_ranges
|
||||
.iter()
|
||||
.map(|range| diag.to_lsp_diagnostic(range))
|
||||
}),
|
||||
);
|
||||
// TODO(nayeemrmn): This is a crude way of detecting `@deno-types` which has
|
||||
// a different specifier and therefore needs a separate call to
|
||||
|
@ -1241,13 +1244,15 @@ fn diagnose_dependency(
|
|||
Resolution::Err(error) => documents::to_lsp_range(error.range()),
|
||||
Resolution::None => unreachable!(),
|
||||
};
|
||||
diagnostics.extend(
|
||||
diagnose_resolution(
|
||||
diagnostics,
|
||||
snapshot,
|
||||
&dependency.maybe_type,
|
||||
dependency.is_dynamic,
|
||||
dependency.maybe_assert_type.as_deref(),
|
||||
vec![range],
|
||||
)
|
||||
.iter()
|
||||
.map(|diag| diag.to_lsp_diagnostic(&range)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue