Skip to content
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6109dd2
wip expr
eureka-cpu Jul 15, 2022
5c5861b
add files
eureka-cpu Jul 15, 2022
8796821
Merge branch 'master' into eureka-cpu/2300
eureka-cpu Jul 17, 2022
12e356f
fix imports and separate logic into corresponding files
eureka-cpu Jul 17, 2022
7ec5552
resolve errors and organize files
eureka-cpu Jul 17, 2022
c26ecc2
add code_block
eureka-cpu Jul 17, 2022
9222d38
add assignable formatting
eureka-cpu Jul 17, 2022
deb3a9e
add basic formatting of collection expr
eureka-cpu Jul 17, 2022
ff8c402
basic formatting for conditionals
eureka-cpu Jul 17, 2022
c82b8fd
Merge branch 'master' into eureka-cpu/2300
eureka-cpu Jul 19, 2022
9ee653c
add Delimiter basic expressions
eureka-cpu Jul 19, 2022
c6a12aa
test passing
eureka-cpu Jul 26, 2022
a0e215d
resolve merge conflicts, organize methods
eureka-cpu Jul 26, 2022
bacf936
Merge branch 'master' into eureka-cpu/2300
eureka-cpu Jul 29, 2022
aff7db0
add space between } and ( in method calls
eureka-cpu Jul 29, 2022
f473542
resolve merge conflicts
eureka-cpu Aug 2, 2022
29ebea9
add in LineStyle adjustments, update punctuated
eureka-cpu Aug 3, 2022
3bfaf48
Merge branch 'master' into eureka-cpu/2300
eureka-cpu Aug 3, 2022
90facf4
fix reset_line_style test
eureka-cpu Aug 3, 2022
e98bd6e
remove println
eureka-cpu Aug 3, 2022
1971cff
resolve merge conflicts
eureka-cpu Aug 3, 2022
f731bc0
Merge branch 'master' into eureka-cpu/2300
eureka-cpu Aug 4, 2022
5d0eea3
playing around with macros to test expr
eureka-cpu Aug 5, 2022
1847306
fix test output
eureka-cpu Aug 5, 2022
269f8ea
fix struct literal formatting #2467
eureka-cpu Aug 5, 2022
3c4bec1
update tests, tests passing
eureka-cpu Aug 5, 2022
90d1f89
Merge branch 'master' into eureka-cpu/2300
eureka-cpu Aug 5, 2022
7d2b9ec
toml fmt
eureka-cpu Aug 5, 2022
4556023
increase field width accuracy
eureka-cpu Aug 6, 2022
cdecbb8
Merge branch 'master' into eureka-cpu/2300
eureka-cpu Aug 6, 2022
bac33b9
rmv unnecessary impl block from heuristics
eureka-cpu Aug 7, 2022
77f09e9
update docstring in constants
eureka-cpu Aug 7, 2022
a1a4b77
update same comment but in heuristics
eureka-cpu Aug 7, 2022
b1c1c20
add body width to line style check
eureka-cpu Aug 7, 2022
59805eb
fix tests
eureka-cpu Aug 8, 2022
39d39ea
make test storage init weirder
eureka-cpu Aug 8, 2022
5a5cbbe
rmv unused impl from heuristics, and start adding ExprKind to Shape
eureka-cpu Aug 8, 2022
8448f15
wip determining multiline config operations
eureka-cpu Aug 8, 2022
2215e9b
update get_line_style() to use update_line_style in fn body
eureka-cpu Aug 8, 2022
c436ff5
update reset_line_heuristics()
eureka-cpu Aug 8, 2022
a1a382d
fmt
eureka-cpu Aug 8, 2022
42c2bf0
add space at end of toml to satisfy diff
eureka-cpu Aug 8, 2022
dd903eb
organize ty
eureka-cpu Aug 8, 2022
e7f8295
change indent_style to shape, update doc comments
eureka-cpu Aug 8, 2022
9ced638
add shape file
eureka-cpu Aug 8, 2022
4aedfaa
add useful comments and remove unnecessary methods in shape
eureka-cpu Aug 8, 2022
a09791f
get new flow working, tests passing, small adjustments to code organi…
eureka-cpu Aug 8, 2022
85bc1c4
update comments and organize
eureka-cpu Aug 8, 2022
2da01da
Merge branch 'master' into eureka-cpu/2300
eureka-cpu Aug 8, 2022
ebae028
clippy strikes again
eureka-cpu Aug 8, 2022
b2091fb
revert method_chain_width back to just chain_width to encompass field…
eureka-cpu Aug 8, 2022
20b490a
Merge branch 'master' into eureka-cpu/2300
kayagokalp Aug 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions sway-fmt-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ sway-parse = { version = "0.19.2", path = "../sway-parse" }
sway-types = { version = "0.19.2", path = "../sway-types" }
thiserror = "1.0.30"
toml = "0.5"

[dev-dependencies]
forc-util = { path = "../forc-util" }
paste = "1.0"
prettydiff = "0.6"
2 changes: 1 addition & 1 deletion sway-fmt-v2/src/config/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::constants::DEFAULT_MAX_COMMENT_WIDTH;

use super::user_opts::CommentsOptions;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Comments {
/// Break comments to fit on the line.
pub wrap_comments: bool,
Expand Down
42 changes: 17 additions & 25 deletions sway-fmt-v2/src/config/heuristics.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Configuration options related to heuristics.
use crate::constants::{
DEFAULT_ARRAY_WIDTH, DEFAULT_ATTR_FN_LIKE_WIDTH, DEFAULT_CHAIN_WIDTH, DEFAULT_FN_CALL_WIDTH,
DEFAULT_MAX_LINE_WIDTH, DEFAULT_SINGLE_LINE_IF_ELSE_WIDTH, DEFAULT_STRUCTURE_LIT_WIDTH,
DEFAULT_STRUCTURE_VAR_WIDTH,
DEFAULT_ATTR_FN_LIKE_WIDTH, DEFAULT_CHAIN_WIDTH, DEFAULT_COLLECTION_WIDTH,
DEFAULT_FN_CALL_WIDTH, DEFAULT_MAX_LINE_WIDTH, DEFAULT_SINGLE_LINE_IF_ELSE_WIDTH,
DEFAULT_STRUCTURE_LIT_WIDTH, DEFAULT_STRUCTURE_VAR_WIDTH,
};
use serde::{Deserialize, Serialize};

use super::{user_opts::HeuristicsOptions, whitespace::Whitespace};
use super::user_opts::HeuristicsOptions;

#[derive(Debug, Copy, Clone)]
pub struct Heuristics {
Expand Down Expand Up @@ -51,17 +51,17 @@ pub enum HeuristicsPreferences {
}

impl HeuristicsPreferences {
pub fn to_width_heuristics(self, ws_opts: &Whitespace) -> WidthHeuristics {
pub fn to_width_heuristics(self, max_width: usize) -> WidthHeuristics {
match self {
HeuristicsPreferences::Off => WidthHeuristics::off(),
HeuristicsPreferences::Max => WidthHeuristics::max(ws_opts.max_width),
HeuristicsPreferences::Scaled => WidthHeuristics::scaled(ws_opts.max_width),
HeuristicsPreferences::Max => WidthHeuristics::max(max_width),
HeuristicsPreferences::Scaled => WidthHeuristics::scaled(max_width),
}
}
}

/// 'small' heuristic values
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Copy)]
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Copy)]
pub struct WidthHeuristics {
// Maximum width of the args of a function call before falling back
// to vertical formatting.
Expand All @@ -72,25 +72,19 @@ pub struct WidthHeuristics {
// Maximum width in the body of a user-defined structure literal before falling back to
// vertical formatting.
pub(crate) structure_lit_width: usize,
// Maximum width in the body of a user-defined structure field before falling back
// Maximum width of a user-defined structure field before falling back
// to vertical formatting.
pub(crate) structure_field_width: usize,
// Maximum width of an array literal before falling back to vertical
// Maximum width of a collection literal before falling back to vertical
// formatting.
pub(crate) array_width: usize,
pub(crate) collection_width: usize,
// Maximum length of a chain to fit on a single line.
pub(crate) chain_width: usize,
// Maximum line length for single line if-else expressions. A value
// of zero means always break if-else expressions.
pub(crate) single_line_if_else_max_width: usize,
}

impl std::fmt::Display for WidthHeuristics {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

impl WidthHeuristics {
/// Using this WidthHeuristics means we ignore heuristics.
pub fn off() -> WidthHeuristics {
Expand All @@ -99,7 +93,7 @@ impl WidthHeuristics {
attr_fn_like_width: usize::max_value(),
structure_lit_width: 0,
structure_field_width: 0,
array_width: usize::max_value(),
collection_width: usize::max_value(),
chain_width: usize::max_value(),
single_line_if_else_max_width: 0,
}
Expand All @@ -111,7 +105,7 @@ impl WidthHeuristics {
attr_fn_like_width: max_width,
structure_lit_width: max_width,
structure_field_width: max_width,
array_width: max_width,
collection_width: max_width,
chain_width: max_width,
single_line_if_else_max_width: max_width,
}
Expand All @@ -135,7 +129,7 @@ impl WidthHeuristics {
as usize,
structure_field_width: (DEFAULT_STRUCTURE_VAR_WIDTH as f32 * max_width_ratio).round()
as usize,
array_width: (DEFAULT_ARRAY_WIDTH as f32 * max_width_ratio).round() as usize,
collection_width: (DEFAULT_COLLECTION_WIDTH as f32 * max_width_ratio).round() as usize,
chain_width: (DEFAULT_CHAIN_WIDTH as f32 * max_width_ratio).round() as usize,
single_line_if_else_max_width: (DEFAULT_SINGLE_LINE_IF_ELSE_WIDTH as f32
* max_width_ratio)
Expand All @@ -144,10 +138,8 @@ impl WidthHeuristics {
}
}

impl ::std::str::FromStr for WidthHeuristics {
type Err = &'static str;

fn from_str(_: &str) -> Result<Self, Self::Err> {
Err("WidthHeuristics is not parsable")
impl Default for WidthHeuristics {
fn default() -> Self {
Self::scaled(100)
}
}
2 changes: 1 addition & 1 deletion sway-fmt-v2/src/config/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
};

/// A finalized `swayfmt` config.
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct Config {
pub whitespace: Whitespace,
pub imports: Imports,
Expand Down
2 changes: 1 addition & 1 deletion sway-fmt-v2/src/config/ordering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use super::user_opts::OrderingOptions;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Ordering {
/// Reorder import and extern crate statements alphabetically.
pub reorder_imports: bool,
Expand Down
2 changes: 1 addition & 1 deletion sway-fmt-v2/src/config/user_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use super::user_opts::StructuresOptions;

/// Styling preferences for user-defined structures like `struct`s or `enum`s.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Structures {
/// Align fields of user-defined structures if their diffs fit within threshold.
pub field_alignment: FieldAlignment,
Expand Down
4 changes: 2 additions & 2 deletions sway-fmt-v2/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub const DEFAULT_FN_CALL_WIDTH: usize = 60;
pub const DEFAULT_ATTR_FN_LIKE_WIDTH: usize = 70;
/// Default max width in the body of a user-defined structure literal before falling back to vertical formatting.
pub const DEFAULT_STRUCTURE_LIT_WIDTH: usize = 18;
/// Default max width in the body of a user-defined structure field before falling back to vertical formatting.
/// Default max width of a user-defined structure field before falling back to vertical formatting.
pub const DEFAULT_STRUCTURE_VAR_WIDTH: usize = 35;
/// Default Maximum width of an array literal before falling back to vertical formatting.
pub const DEFAULT_ARRAY_WIDTH: usize = 60;
pub const DEFAULT_COLLECTION_WIDTH: usize = 60;
/// Defalt width threshold for an array element to be considered short.
pub const DEFAULT_SHORT_ARRAY_ELEM_WIDTH_THRESHOLD: usize = 10;
/// Default max length of a chain to fit on a single line.
Expand Down
Loading