Show warning when ignoring modules + restyle warnings slightly
Fixes #916.
This commit is contained in:
parent
81219cfbdd
commit
1ed4fa1c69
|
@ -20,6 +20,7 @@
|
||||||
- **aiken-lang**: fix compiler wrongly requiring MillerLoopResult to be 'serialisable' when manipulated as a top-level value. See #921. @KtorZ
|
- **aiken-lang**: fix compiler wrongly requiring MillerLoopResult to be 'serialisable' when manipulated as a top-level value. See #921. @KtorZ
|
||||||
- **aiken-lang**: fix type-checker oversight regarding serialisation of generics. See #939. @KtorZ
|
- **aiken-lang**: fix type-checker oversight regarding serialisation of generics. See #939. @KtorZ
|
||||||
- **aiken-lang**: fix type-checker not raising error when comparing non-serialisable types. See #940. @KtorZ
|
- **aiken-lang**: fix type-checker not raising error when comparing non-serialisable types. See #940. @KtorZ
|
||||||
|
- **aiken-project**: show a warning when ignoring modules in lib/validator because they have an invalid name. See #916. @KtorZ
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@
|
||||||
- **aiken-lang**: altered internal representation of 2-tuples to distinguish them from pairs. @KtorZ @Microproofs
|
- **aiken-lang**: altered internal representation of 2-tuples to distinguish them from pairs. @KtorZ @Microproofs
|
||||||
- **aiken-lang**: some more code gen cleanup. @Microproofs
|
- **aiken-lang**: some more code gen cleanup. @Microproofs
|
||||||
- **aiken-lang**: new optimization for wrapped builtins found in the stdlib. @Microproofs
|
- **aiken-lang**: new optimization for wrapped builtins found in the stdlib. @Microproofs
|
||||||
|
- **aiken-project**: slightly restyle warnings to be less noisy. @KtorZ
|
||||||
|
|
||||||
|
|
||||||
## v1.0.26-alpha - 2024-03-25
|
## v1.0.26-alpha - 2024-03-25
|
||||||
|
|
|
@ -8,7 +8,10 @@ use aiken_lang::{
|
||||||
use miette::{
|
use miette::{
|
||||||
Diagnostic, EyreContext, LabeledSpan, MietteHandlerOpts, NamedSource, RgbColors, SourceCode,
|
Diagnostic, EyreContext, LabeledSpan, MietteHandlerOpts, NamedSource, RgbColors, SourceCode,
|
||||||
};
|
};
|
||||||
use owo_colors::{OwoColorize, Stream::Stdout};
|
use owo_colors::{
|
||||||
|
OwoColorize,
|
||||||
|
Stream::{Stderr, Stdout},
|
||||||
|
};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
io,
|
io,
|
||||||
|
@ -501,9 +504,9 @@ impl Diagnostic for Error {
|
||||||
|
|
||||||
#[derive(thiserror::Error)]
|
#[derive(thiserror::Error)]
|
||||||
pub enum Warning {
|
pub enum Warning {
|
||||||
#[error("You do not have any validators to build!")]
|
#[error("{}", "You do not have any validators to build!".if_supports_color(Stderr, |s| s.yellow()))]
|
||||||
NoValidators,
|
NoValidators,
|
||||||
#[error("While trying to make sense of your code...")]
|
#[error("{}", "While trying to make sense of your code...".if_supports_color(Stderr, |s| s.yellow()))]
|
||||||
Type {
|
Type {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
src: String,
|
src: String,
|
||||||
|
@ -511,15 +514,18 @@ pub enum Warning {
|
||||||
#[source]
|
#[source]
|
||||||
warning: tipo::error::Warning,
|
warning: tipo::error::Warning,
|
||||||
},
|
},
|
||||||
#[error("{name} is already a dependency.")]
|
#[error("{}", format!("{name} is already a dependency.").if_supports_color(Stderr, |s| s.yellow()))]
|
||||||
DependencyAlreadyExists { name: PackageName },
|
DependencyAlreadyExists { name: PackageName },
|
||||||
|
#[error("{}", format!("Ignoring file with invalid module name at: {path:?}").if_supports_color(Stderr, |s| s.yellow()))]
|
||||||
|
InvalidModuleName { path: PathBuf },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtraData for Warning {
|
impl ExtraData for Warning {
|
||||||
fn extra_data(&self) -> Option<String> {
|
fn extra_data(&self) -> Option<String> {
|
||||||
match self {
|
match self {
|
||||||
Warning::NoValidators { .. } => None,
|
Warning::NoValidators { .. }
|
||||||
Warning::DependencyAlreadyExists { .. } => None,
|
| Warning::DependencyAlreadyExists { .. }
|
||||||
|
| Warning::InvalidModuleName { .. } => None,
|
||||||
Warning::Type { warning, .. } => warning.extra_data(),
|
Warning::Type { warning, .. } => warning.extra_data(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -528,17 +534,17 @@ impl ExtraData for Warning {
|
||||||
impl GetSource for Warning {
|
impl GetSource for Warning {
|
||||||
fn path(&self) -> Option<PathBuf> {
|
fn path(&self) -> Option<PathBuf> {
|
||||||
match self {
|
match self {
|
||||||
Warning::NoValidators => None,
|
Warning::InvalidModuleName { path } | Warning::Type { path, .. } => Some(path.clone()),
|
||||||
Warning::Type { path, .. } => Some(path.clone()),
|
Warning::NoValidators | Warning::DependencyAlreadyExists { .. } => None,
|
||||||
Warning::DependencyAlreadyExists { .. } => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn src(&self) -> Option<String> {
|
fn src(&self) -> Option<String> {
|
||||||
match self {
|
match self {
|
||||||
Warning::NoValidators => None,
|
|
||||||
Warning::Type { src, .. } => Some(src.clone()),
|
Warning::Type { src, .. } => Some(src.clone()),
|
||||||
Warning::DependencyAlreadyExists { .. } => None,
|
Warning::NoValidators
|
||||||
|
| Warning::InvalidModuleName { .. }
|
||||||
|
| Warning::DependencyAlreadyExists { .. } => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -551,46 +557,32 @@ impl Diagnostic for Warning {
|
||||||
fn source_code(&self) -> Option<&dyn SourceCode> {
|
fn source_code(&self) -> Option<&dyn SourceCode> {
|
||||||
match self {
|
match self {
|
||||||
Warning::Type { named, .. } => Some(named),
|
Warning::Type { named, .. } => Some(named),
|
||||||
Warning::NoValidators => None,
|
Warning::NoValidators
|
||||||
Warning::DependencyAlreadyExists { .. } => None,
|
| Warning::InvalidModuleName { .. }
|
||||||
|
| Warning::DependencyAlreadyExists { .. } => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>> {
|
fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>> {
|
||||||
match self {
|
match self {
|
||||||
Warning::Type { warning, .. } => warning.labels(),
|
Warning::Type { warning, .. } => warning.labels(),
|
||||||
Warning::NoValidators => None,
|
Warning::InvalidModuleName { .. }
|
||||||
Warning::DependencyAlreadyExists { .. } => None,
|
| Warning::NoValidators
|
||||||
|
| Warning::DependencyAlreadyExists { .. } => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||||
fn boxed<'a>(s: Box<dyn Display + 'a>) -> Box<dyn Display + 'a> {
|
None
|
||||||
Box::new(format!(
|
|
||||||
" {} {}",
|
|
||||||
"Warning"
|
|
||||||
.if_supports_color(Stdout, |s| s.yellow())
|
|
||||||
.if_supports_color(Stdout, |s| s.bold()),
|
|
||||||
format!("{s}").if_supports_color(Stdout, |s| s.yellow())
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
match self {
|
|
||||||
Warning::Type { warning, .. } => Some(boxed(Box::new(format!(
|
|
||||||
"aiken::check{}",
|
|
||||||
warning.code().map(|s| format!("::{s}")).unwrap_or_default()
|
|
||||||
)))),
|
|
||||||
Warning::NoValidators => Some(boxed(Box::new("aiken::check"))),
|
|
||||||
Warning::DependencyAlreadyExists { .. } => {
|
|
||||||
Some(boxed(Box::new("aiken::packages::already_exists")))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||||
match self {
|
match self {
|
||||||
Warning::Type { warning, .. } => warning.help(),
|
Warning::Type { warning, .. } => warning.help(),
|
||||||
Warning::NoValidators => None,
|
Warning::NoValidators => None,
|
||||||
|
Warning::InvalidModuleName { .. } => Some(Box::new(
|
||||||
|
"Module names are lowercase, (ascii) alpha-numeric and may contain dashes or underscores.",
|
||||||
|
)),
|
||||||
Warning::DependencyAlreadyExists { .. } => Some(Box::new(
|
Warning::DependencyAlreadyExists { .. } => Some(Box::new(
|
||||||
"If you need to change the version, try 'aiken packages upgrade' instead.",
|
"If you need to change the version, try 'aiken packages upgrade' instead.",
|
||||||
)),
|
)),
|
||||||
|
|
|
@ -855,20 +855,28 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aiken_files(&mut self, dir: &Path, kind: ModuleKind) -> Result<(), Error> {
|
fn aiken_files(&mut self, dir: &Path, kind: ModuleKind) -> Result<(), Error> {
|
||||||
let paths = walkdir::WalkDir::new(dir)
|
walkdir::WalkDir::new(dir)
|
||||||
.follow_links(true)
|
.follow_links(true)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.filter(|e| e.file_type().is_file())
|
.filter(|e| e.file_type().is_file())
|
||||||
.map(|d| d.into_path())
|
.try_for_each(|d| {
|
||||||
.filter(move |d| is_aiken_path(d, dir));
|
let path = d.into_path();
|
||||||
|
let keep = is_aiken_path(&path, dir);
|
||||||
|
let ext = path.extension();
|
||||||
|
|
||||||
for path in paths {
|
if !keep && ext.unwrap_or_default() == "ak" {
|
||||||
self.add_module(path, dir, kind)?;
|
self.warnings
|
||||||
|
.push(Warning::InvalidModuleName { path: path.clone() });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if keep {
|
||||||
|
self.add_module(path, dir, kind)
|
||||||
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn add_module(&mut self, path: PathBuf, dir: &Path, kind: ModuleKind) -> Result<(), Error> {
|
fn add_module(&mut self, path: PathBuf, dir: &Path, kind: ModuleKind) -> Result<(), Error> {
|
||||||
let name = self.module_name(dir, &path);
|
let name = self.module_name(dir, &path);
|
||||||
|
|
Loading…
Reference in New Issue