Skip to content

Commit

Permalink
Fix aiken docs constant generation
Browse files Browse the repository at this point in the history
  Fixes #1048.
  • Loading branch information
KtorZ committed Oct 29, 2024
1 parent 2b7ca0e commit 2489e0f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
### Changed

- **aiken**: Rename `--filter_traces` to `--trace_filter` for more consistency with `--trace_level`. An alias for `--filter_traces` still exists for backward compatibility. @KtorZ
- **aiken-project**: Fix `aiken docs` wrongly formatting list constants as tuples. See [#1048](https://github.com/aiken-lang/aiken/issues/1048). @KtorZ
- **aiken-project**: Fix `aiken docs` source linking crashing when generating docs for config modules. See [#1044](https://github.com/aiken-lang/aiken/issues/1044). @KtorZ
- **aiken-project**: Fix `aiken docs` generating very long lines for constants. @KtorZ

### Removed

Expand Down
16 changes: 16 additions & 0 deletions crates/aiken-lang/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ impl<T> From<Vec1Ref<T>> for Vec1<T> {
}

impl TypedExpr {
pub fn is_simple_expr_to_format(&self) -> bool {
match self {
Self::String { .. } | Self::UInt { .. } | Self::ByteArray { .. } | Self::Var { .. } => {
true
}
Self::Pair { fst, snd, .. } => {
fst.is_simple_expr_to_format() && snd.is_simple_expr_to_format()
}
Self::Tuple { elems, .. } => elems.iter().all(|e| e.is_simple_expr_to_format()),
Self::List { elements, .. } if elements.len() <= 3 => {
elements.iter().all(|e| e.is_simple_expr_to_format())
}
_ => false,
}
}

pub fn and_then(self, next: Self) -> Self {
if let TypedExpr::Trace {
tipo,
Expand Down
13 changes: 12 additions & 1 deletion crates/aiken-lang/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,18 @@ impl<'comments> Formatter<'comments> {
.append(wrap_args(elems.iter().map(|e| (self.const_expr(e), false))).group())
}
TypedExpr::List { elements, .. } => {
wrap_args(elements.iter().map(|e| (self.const_expr(e), false))).group()
let comma: fn() -> Document<'a> =
if elements.iter().all(TypedExpr::is_simple_expr_to_format) {
|| flex_break(",", ", ")
} else {
|| break_(",", ", ")
};

list(
join(elements.iter().map(|e| self.const_expr(e)), comma()),
elements.len(),
None,
)
}
TypedExpr::Var { name, .. } => name.to_doc(),
_ => Document::Str(""),
Expand Down
2 changes: 1 addition & 1 deletion crates/aiken-project/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::{
time::{Duration, SystemTime},
};

const MAX_COLUMNS: isize = 999;
const MAX_COLUMNS: isize = 80;
const VERSION: &str = env!("CARGO_PKG_VERSION");

pub mod link_tree;
Expand Down

0 comments on commit 2489e0f

Please sign in to comment.