mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 12:16:11 -05:00
smart diagnostics concatenation
This commit is contained in:
parent
7a3a73c782
commit
27561dd485
6 changed files with 54 additions and 15 deletions
|
@ -13,6 +13,7 @@ use deno_runtime::deno_permissions::PermissionsContainer;
|
|||
|
||||
use crate::args::CliOptions;
|
||||
use crate::module_loader::ModuleLoadPreparer;
|
||||
use crate::tools::check::MaybeDiagnostics;
|
||||
use crate::util::fs::collect_specifiers;
|
||||
use crate::util::path::is_script_ext;
|
||||
|
||||
|
@ -69,7 +70,7 @@ impl MainModuleGraphContainer {
|
|||
&self,
|
||||
specifiers: &[ModuleSpecifier],
|
||||
ext_overwrite: Option<&String>,
|
||||
) -> Result<(), AnyError> {
|
||||
) -> Result<(), MaybeDiagnostics> {
|
||||
let mut graph_permit = self.acquire_update_permit().await;
|
||||
let graph = graph_permit.graph_mut();
|
||||
self
|
||||
|
@ -99,7 +100,7 @@ impl MainModuleGraphContainer {
|
|||
log::warn!("{} No matching files found.", colors::yellow("Warning"));
|
||||
}
|
||||
|
||||
self.check_specifiers(&specifiers, None).await
|
||||
Ok(self.check_specifiers(&specifiers, None).await?)
|
||||
}
|
||||
|
||||
pub fn collect_specifiers(
|
||||
|
|
|
@ -371,6 +371,7 @@ impl ModuleGraphCreator {
|
|||
},
|
||||
)
|
||||
.await
|
||||
.map_err(AnyError::from)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ use crate::resolver::ModuleCodeStringSource;
|
|||
use crate::resolver::NotSupportedKindInNpmError;
|
||||
use crate::resolver::NpmModuleLoader;
|
||||
use crate::tools::check;
|
||||
use crate::tools::check::MaybeDiagnostics;
|
||||
use crate::tools::check::TypeChecker;
|
||||
use crate::util::progress_bar::ProgressBar;
|
||||
use crate::util::text_encoding::code_without_source_map;
|
||||
|
@ -117,7 +118,7 @@ impl ModuleLoadPreparer {
|
|||
lib: TsTypeLib,
|
||||
permissions: PermissionsContainer,
|
||||
ext_overwrite: Option<&String>,
|
||||
) -> Result<(), AnyError> {
|
||||
) -> Result<(), MaybeDiagnostics> {
|
||||
log::debug!("Preparing module load.");
|
||||
let _pb_clear_guard = self.progress_bar.clear_guard();
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ use std::collections::BTreeMap;
|
|||
use std::collections::BTreeSet;
|
||||
use std::collections::HashSet;
|
||||
use std::collections::VecDeque;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
use deno_ast::MediaType;
|
||||
|
@ -107,7 +109,8 @@ pub async fn check(
|
|||
);
|
||||
let dir_count = by_workspace_directory.len();
|
||||
let initial_cwd = cli_options.initial_cwd().to_path_buf();
|
||||
let mut check_errors = vec![];
|
||||
let mut diagnostics = vec![];
|
||||
let mut all_errors = vec![];
|
||||
let mut found_specifiers = false;
|
||||
for (dir_url, (workspace_directory, patterns)) in by_workspace_directory {
|
||||
let (npmrc, _) =
|
||||
|
@ -170,18 +173,24 @@ pub async fn check(
|
|||
.check_specifiers(&specifiers_for_typecheck, None)
|
||||
.await
|
||||
{
|
||||
check_errors.push(err);
|
||||
match err {
|
||||
MaybeDiagnostics::Diagnostics(Diagnostics(d)) => {
|
||||
diagnostics.extend(d)
|
||||
}
|
||||
MaybeDiagnostics::Other(err) => all_errors.push(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found_specifiers {
|
||||
log::warn!("{} No matching files found.", colors::yellow("Warning"));
|
||||
}
|
||||
if !check_errors.is_empty() {
|
||||
// TODO(nayeemrmn): More integrated way of concatenating diagnostics from
|
||||
// different checks.
|
||||
if !diagnostics.is_empty() {
|
||||
all_errors.push(AnyError::from(Diagnostics(diagnostics)));
|
||||
}
|
||||
if !all_errors.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"{}",
|
||||
check_errors
|
||||
all_errors
|
||||
.into_iter()
|
||||
.map(|e| e.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
|
@ -225,9 +234,11 @@ pub async fn check(
|
|||
specifiers
|
||||
};
|
||||
|
||||
main_graph_container
|
||||
.check_specifiers(&specifiers_for_typecheck, None)
|
||||
.await
|
||||
Ok(
|
||||
main_graph_container
|
||||
.check_specifiers(&specifiers_for_typecheck, None)
|
||||
.await?,
|
||||
)
|
||||
}
|
||||
|
||||
/// Options for performing a check of a module graph. Note that the decision to
|
||||
|
@ -249,6 +260,29 @@ pub struct CheckOptions {
|
|||
pub type_check_mode: TypeCheckMode,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MaybeDiagnostics {
|
||||
Diagnostics(Diagnostics),
|
||||
Other(AnyError),
|
||||
}
|
||||
|
||||
impl fmt::Display for MaybeDiagnostics {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
MaybeDiagnostics::Diagnostics(d) => d.fmt(f),
|
||||
MaybeDiagnostics::Other(err) => err.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for MaybeDiagnostics {}
|
||||
|
||||
impl From<AnyError> for MaybeDiagnostics {
|
||||
fn from(err: AnyError) -> Self {
|
||||
MaybeDiagnostics::Other(err)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TypeChecker {
|
||||
caches: Arc<Caches>,
|
||||
cjs_tracker: Arc<TypeCheckingCjsTracker>,
|
||||
|
@ -285,14 +319,14 @@ impl TypeChecker {
|
|||
&self,
|
||||
graph: ModuleGraph,
|
||||
options: CheckOptions,
|
||||
) -> Result<Arc<ModuleGraph>, AnyError> {
|
||||
) -> Result<Arc<ModuleGraph>, MaybeDiagnostics> {
|
||||
let (graph, mut diagnostics) =
|
||||
self.check_diagnostics(graph, options).await?;
|
||||
diagnostics.emit_warnings();
|
||||
if diagnostics.is_empty() {
|
||||
Ok(graph)
|
||||
} else {
|
||||
Err(diagnostics.into())
|
||||
Err(MaybeDiagnostics::Diagnostics(diagnostics))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -274,7 +274,7 @@ impl fmt::Display for Diagnostic {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq)]
|
||||
pub struct Diagnostics(Vec<Diagnostic>);
|
||||
pub struct Diagnostics(pub Vec<Diagnostic>);
|
||||
|
||||
impl Diagnostics {
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -7,3 +7,5 @@ TS2304 [ERROR]: Cannot find name 'localStorage'.
|
|||
localStorage;
|
||||
~~~~~~~~~~~~
|
||||
at file:///[WILDCARD]/member/mod.ts:2:1
|
||||
|
||||
Found 2 errors.
|
||||
|
|
Loading…
Add table
Reference in a new issue