mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(lsp): ignore a few more diagnostics for ambient modules (#27949)
Missed a few resolution errors
This commit is contained in:
parent
4101cf4274
commit
f32b5f1ad1
2 changed files with 68 additions and 39 deletions
|
@ -1532,6 +1532,60 @@ fn relative_specifier(specifier: &Url, referrer: &Url) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn maybe_ambient_import_specifier(
|
||||||
|
diagnostic: &DenoDiagnostic,
|
||||||
|
) -> Option<String> {
|
||||||
|
match diagnostic {
|
||||||
|
DenoDiagnostic::NoCache(url) | DenoDiagnostic::NoLocal(url) => {
|
||||||
|
Some(url.to_string())
|
||||||
|
}
|
||||||
|
DenoDiagnostic::ResolutionError(err) => {
|
||||||
|
maybe_ambient_specifier_resolution_err(err)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn maybe_ambient_specifier_resolution_err(
|
||||||
|
err: &ResolutionError,
|
||||||
|
) -> Option<String> {
|
||||||
|
match err {
|
||||||
|
ResolutionError::InvalidDowngrade { .. }
|
||||||
|
| ResolutionError::InvalidJsrHttpsTypesImport { .. }
|
||||||
|
| ResolutionError::InvalidLocalImport { .. } => None,
|
||||||
|
ResolutionError::InvalidSpecifier { error, .. } => match error {
|
||||||
|
SpecifierError::InvalidUrl(..) => None,
|
||||||
|
SpecifierError::ImportPrefixMissing { specifier, .. } => {
|
||||||
|
Some(specifier.to_string())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ResolutionError::ResolverError { error, .. } => match &**error {
|
||||||
|
ResolveError::Specifier(specifier_error) => match specifier_error {
|
||||||
|
SpecifierError::InvalidUrl(..) => None,
|
||||||
|
SpecifierError::ImportPrefixMissing { specifier, .. } => {
|
||||||
|
Some(specifier.to_string())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ResolveError::ImportMap(import_map_error) => {
|
||||||
|
match import_map_error.as_kind() {
|
||||||
|
ImportMapErrorKind::UnmappedBareSpecifier(spec, _) => {
|
||||||
|
Some(spec.clone())
|
||||||
|
}
|
||||||
|
ImportMapErrorKind::JsonParse(_)
|
||||||
|
| ImportMapErrorKind::ImportMapNotObject
|
||||||
|
| ImportMapErrorKind::ImportsFieldNotObject
|
||||||
|
| ImportMapErrorKind::ScopesFieldNotObject
|
||||||
|
| ImportMapErrorKind::ScopePrefixNotObject(_)
|
||||||
|
| ImportMapErrorKind::BlockedByNullEntry(_)
|
||||||
|
| ImportMapErrorKind::SpecifierResolutionFailure { .. }
|
||||||
|
| ImportMapErrorKind::SpecifierBacktracksAbovePrefix { .. } => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ResolveError::Other(..) => None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn diagnose_resolution(
|
fn diagnose_resolution(
|
||||||
snapshot: &language_server::StateSnapshot,
|
snapshot: &language_server::StateSnapshot,
|
||||||
dependency_key: &str,
|
dependency_key: &str,
|
||||||
|
@ -1672,16 +1726,14 @@ fn diagnose_resolution(
|
||||||
}
|
}
|
||||||
// The specifier resolution resulted in an error, so we want to issue a
|
// The specifier resolution resulted in an error, so we want to issue a
|
||||||
// diagnostic for that.
|
// diagnostic for that.
|
||||||
Resolution::Err(err) => match &**err {
|
Resolution::Err(err) => {
|
||||||
ResolutionError::InvalidSpecifier {
|
if maybe_ambient_specifier_resolution_err(err).is_none() {
|
||||||
error: SpecifierError::ImportPrefixMissing { .. },
|
diagnostics.push(DenoDiagnostic::ResolutionError(*err.clone()))
|
||||||
..
|
} else {
|
||||||
} => {
|
|
||||||
deferred_diagnostics
|
deferred_diagnostics
|
||||||
.push(DenoDiagnostic::ResolutionError(*err.clone()));
|
.push(DenoDiagnostic::ResolutionError(*err.clone()));
|
||||||
}
|
}
|
||||||
_ => diagnostics.push(DenoDiagnostic::ResolutionError(*err.clone())),
|
}
|
||||||
},
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
(diagnostics, deferred_diagnostics)
|
(diagnostics, deferred_diagnostics)
|
||||||
|
@ -1773,25 +1825,12 @@ fn diagnose_dependency(
|
||||||
deferred_diagnostics.extend(
|
deferred_diagnostics.extend(
|
||||||
deferred
|
deferred
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|diag| match diag {
|
.filter_map(|diag| {
|
||||||
DenoDiagnostic::NoCache(url) | DenoDiagnostic::NoLocal(url) => Some(
|
maybe_ambient_import_specifier(diag).map(|spec| {
|
||||||
Box::new(
|
import_ranges
|
||||||
import_ranges
|
.iter()
|
||||||
.iter()
|
.map(move |range| (spec.clone(), diag.to_lsp_diagnostic(range)))
|
||||||
.map(|range| (url.to_string(), diag.to_lsp_diagnostic(range))),
|
})
|
||||||
) as Box<dyn Iterator<Item = (String, lsp::Diagnostic)>>,
|
|
||||||
),
|
|
||||||
DenoDiagnostic::ResolutionError(
|
|
||||||
ResolutionError::InvalidSpecifier {
|
|
||||||
error: SpecifierError::ImportPrefixMissing { specifier, .. },
|
|
||||||
..
|
|
||||||
},
|
|
||||||
) => {
|
|
||||||
Some(Box::new(import_ranges.iter().map(|range| {
|
|
||||||
(specifier.clone(), diag.to_lsp_diagnostic(range))
|
|
||||||
})))
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
})
|
})
|
||||||
.flatten(),
|
.flatten(),
|
||||||
);
|
);
|
||||||
|
@ -1817,18 +1856,8 @@ fn diagnose_dependency(
|
||||||
.map(|diag| diag.to_lsp_diagnostic(&range)),
|
.map(|diag| diag.to_lsp_diagnostic(&range)),
|
||||||
);
|
);
|
||||||
deferred_diagnostics.extend(Box::new(deferred.iter().filter_map(|diag| {
|
deferred_diagnostics.extend(Box::new(deferred.iter().filter_map(|diag| {
|
||||||
match diag {
|
maybe_ambient_import_specifier(diag)
|
||||||
DenoDiagnostic::NoCache(url) | DenoDiagnostic::NoLocal(url) => {
|
.map(|spec| (spec, diag.to_lsp_diagnostic(&range)))
|
||||||
Some((url.to_string(), diag.to_lsp_diagnostic(&range)))
|
|
||||||
}
|
|
||||||
DenoDiagnostic::ResolutionError(
|
|
||||||
ResolutionError::InvalidSpecifier {
|
|
||||||
error: SpecifierError::ImportPrefixMissing { specifier, .. },
|
|
||||||
..
|
|
||||||
},
|
|
||||||
) => Some((specifier.clone(), diag.to_lsp_diagnostic(&range))),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
[UNORDERED_START]
|
[UNORDERED_START]
|
||||||
Download http://localhost:4260/chalk
|
Download http://localhost:4260/chalk
|
||||||
Download http://localhost:4260/@denotest%2fdep-cannot-parse
|
Download http://localhost:4260/@denotest%2fdep-cannot-parse
|
||||||
[UNORDERED_END]
|
|
||||||
Download http://localhost:4260/chalk/chalk-5.0.1.tgz
|
Download http://localhost:4260/chalk/chalk-5.0.1.tgz
|
||||||
|
[UNORDERED_END]
|
||||||
Hi
|
Hi
|
||||||
TypeError: Error in @denotest/dep-cannot-parse@1.0.0 parsing version requirement for dependency "@denotest/esm-basic": "unknown-scheme:unknown"
|
TypeError: Error in @denotest/dep-cannot-parse@1.0.0 parsing version requirement for dependency "@denotest/esm-basic": "unknown-scheme:unknown"
|
||||||
0: Invalid version requirement
|
0: Invalid version requirement
|
||||||
|
|
Loading…
Add table
Reference in a new issue