-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial componet * clarinet fmt boilerplate hooked up * refactor functions a bit * add basic formatter blocks * fix build removing clarity-repl cargo flags * remove dep on clarity-repl * fix file path * basic tests working * add comment handling and some max line length logic * settings flags for max line and indentation * remove max line length check for comments * switch to use PSE and refactor the matchings * push settings into display_pse so we can attempt formatting Tuple * fix map/tuple formatting * add nested indentation * fix format_map * fix match and let formatting * handle and/or * golden test prettified * special casing on comments and previous checking * update match formatting * cleanup spacing cruft * fix boolean comments and a bit of pre/post newline logic * add a couple golden files * fix traits spacing * comments golden and fix simple lists * use manifest-path properly * fix key value sugar * use some peekable for inlining comments * cleanup previous_expr unused code * index-of case * add metadata to golden test files * simplify tuple handling and add if-tests * add clarity bitcoin example contract * module out the helpers and ignored source code * remove unused previous_expr * use the ignored and helper mods * fix the indentation nesting and if statements * cleanup inner_content functions * cleanup and change assumptions temporarily * fix list cons and boolean breaks with simplified line-break * make in-place OR dry-run required * fix up trailing parens for inner content * --tabs flag * update golden tests and fix match comments * fix up assumptions in golden * remove unfinished format-ignore handling * remove unneeded allocations * comma after kvs and dedent if body * fix stack overflow for missing define functions * pass source through for ignoring formatting pragma * fix begin tests and use pretty_assertions * add BND contract test TODO: add the intended result when closing parens are handled better * code review changes and special case define-ft * remove wildcard matching from top level * fix indentation and regenerate tests * add warning to cli --------- Co-authored-by: brady.ouren <[email protected]>
- Loading branch information
Showing
29 changed files
with
8,383 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "clarinet-format" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
clarity = { workspace = true} | ||
|
||
[dev-dependencies] | ||
pretty_assertions = "1.3" | ||
|
||
[features] | ||
default = ["cli"] | ||
cli = [ | ||
"clarity/canonical", | ||
"clarity/developer-mode", | ||
"clarity/devtools", | ||
"clarity/log", | ||
] | ||
wasm = [ | ||
"clarity/wasm", | ||
"clarity/developer-mode", | ||
"clarity/devtools", | ||
] | ||
|
||
|
||
[lib] | ||
name = "clarinet_format" | ||
path = "src/lib.rs" | ||
crate-type = ["lib"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use clarity::vm::representations::PreSymbolicExpression; | ||
|
||
/// trim but leaves newlines preserved | ||
pub fn t(input: &str) -> &str { | ||
let start = input | ||
.find(|c: char| !c.is_whitespace() || c == '\n') | ||
.unwrap_or(0); | ||
|
||
let end = input | ||
.rfind(|c: char| !c.is_whitespace() || c == '\n') | ||
.map(|pos| pos + 1) | ||
.unwrap_or(0); | ||
|
||
&input[start..end] | ||
} | ||
/// REMOVE: just grabs the 1st and rest from a PSE | ||
pub fn name_and_args( | ||
exprs: &[PreSymbolicExpression], | ||
) -> Option<(&PreSymbolicExpression, &[PreSymbolicExpression])> { | ||
if exprs.len() >= 2 { | ||
Some((&exprs[1], &exprs[2..])) | ||
} else { | ||
None // Return None if there aren't enough items | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use clarity::vm::representations::PreSymbolicExpression; | ||
|
||
pub fn ignored_exprs(exprs: &[PreSymbolicExpression], source: &str) -> String { | ||
let start = exprs.first().unwrap().span(); | ||
let end = exprs.last().unwrap().span(); | ||
|
||
let start_line = start.start_line as usize; | ||
let end_line = end.end_line as usize; | ||
|
||
let mut result = String::new(); | ||
let mut is_first = true; | ||
|
||
// Look at lines including one before our span starts | ||
for (idx, line) in source | ||
.lines() | ||
.skip(start_line - 1) // Start one line earlier | ||
.take(end_line - (start_line - 1) + 1) | ||
.enumerate() | ||
{ | ||
if !is_first { | ||
result.push('\n'); | ||
} | ||
|
||
if idx == 0 { | ||
// First line (the one with the opening parenthesis) | ||
if let Some(paren_pos) = line.find('(') { | ||
result.push_str(&line[paren_pos..]); | ||
} | ||
} else if idx == end_line - (start_line - 1) { | ||
// Last line - up to end column | ||
let end_column = end.end_column as usize; | ||
if end_column <= line.len() { | ||
result.push_str(&line[..end_column]); | ||
} else { | ||
result.push_str(line); | ||
} | ||
} else { | ||
// Middle lines - complete line | ||
result.push_str(line); | ||
} | ||
|
||
is_first = false; | ||
} | ||
|
||
result | ||
} |
Oops, something went wrong.