mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -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(
|
fn diagnose_resolution(
|
||||||
lsp_diagnostics: &mut Vec<lsp::Diagnostic>,
|
|
||||||
snapshot: &language_server::StateSnapshot,
|
snapshot: &language_server::StateSnapshot,
|
||||||
resolution: &Resolution,
|
resolution: &Resolution,
|
||||||
is_dynamic: bool,
|
is_dynamic: bool,
|
||||||
maybe_assert_type: Option<&str>,
|
maybe_assert_type: Option<&str>,
|
||||||
ranges: Vec<lsp::Range>,
|
) -> Vec<DenoDiagnostic> {
|
||||||
) {
|
|
||||||
let mut diagnostics = vec![];
|
let mut diagnostics = vec![];
|
||||||
match resolution {
|
match resolution {
|
||||||
Resolution::Ok(resolved) => {
|
Resolution::Ok(resolved) => {
|
||||||
|
@ -1172,11 +1170,7 @@ fn diagnose_resolution(
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
for range in ranges {
|
diagnostics
|
||||||
for diagnostic in &diagnostics {
|
|
||||||
lsp_diagnostics.push(diagnostic.to_lsp_diagnostic(&range));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate diagnostics related to a dependency. The dependency is analyzed to
|
/// Generate diagnostics related to a dependency. The dependency is analyzed to
|
||||||
|
@ -1210,21 +1204,30 @@ fn diagnose_dependency(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
diagnose_resolution(
|
|
||||||
diagnostics,
|
let import_ranges: Vec<_> = dependency
|
||||||
snapshot,
|
.imports
|
||||||
if dependency.maybe_code.is_none() {
|
.iter()
|
||||||
&dependency.maybe_type
|
.map(|i| documents::to_lsp_range(&i.range))
|
||||||
} else {
|
.collect();
|
||||||
&dependency.maybe_code
|
|
||||||
},
|
diagnostics.extend(
|
||||||
dependency.is_dynamic,
|
diagnose_resolution(
|
||||||
dependency.maybe_assert_type.as_deref(),
|
snapshot,
|
||||||
dependency
|
if dependency.maybe_code.is_none() {
|
||||||
.imports
|
&dependency.maybe_type
|
||||||
.iter()
|
} else {
|
||||||
.map(|i| documents::to_lsp_range(&i.range))
|
&dependency.maybe_code
|
||||||
.collect(),
|
},
|
||||||
|
dependency.is_dynamic,
|
||||||
|
dependency.maybe_assert_type.as_deref(),
|
||||||
|
)
|
||||||
|
.iter()
|
||||||
|
.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
|
// TODO(nayeemrmn): This is a crude way of detecting `@deno-types` which has
|
||||||
// a different specifier and therefore needs a separate call to
|
// 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::Err(error) => documents::to_lsp_range(error.range()),
|
||||||
Resolution::None => unreachable!(),
|
Resolution::None => unreachable!(),
|
||||||
};
|
};
|
||||||
diagnose_resolution(
|
diagnostics.extend(
|
||||||
diagnostics,
|
diagnose_resolution(
|
||||||
snapshot,
|
snapshot,
|
||||||
&dependency.maybe_type,
|
&dependency.maybe_type,
|
||||||
dependency.is_dynamic,
|
dependency.is_dynamic,
|
||||||
dependency.maybe_assert_type.as_deref(),
|
dependency.maybe_assert_type.as_deref(),
|
||||||
vec![range],
|
)
|
||||||
|
.iter()
|
||||||
|
.map(|diag| diag.to_lsp_diagnostic(&range)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue