@@ -13,27 +13,26 @@ pub(crate) enum Step {
13
13
14
14
#[ derive( Clone ) ]
15
15
pub ( crate ) struct BuildCtx {
16
- pub force_wide : bool ,
17
- pub indentation : usize ,
18
- pub pos_new : crate :: position :: Position ,
19
- pub pos_old : crate :: position:: Position ,
20
- pub path : String ,
21
- pub vertical : bool ,
16
+ pub force_wide : bool ,
17
+ pub force_wide_success : bool ,
18
+ pub indentation : usize ,
19
+ pub pos_old : crate :: position:: Position ,
20
+ pub path : String ,
21
+ pub vertical : bool ,
22
22
}
23
23
24
24
impl BuildCtx {
25
25
pub fn new (
26
26
force_wide : bool ,
27
27
path : String ,
28
- pos_new : crate :: position:: Position ,
29
28
pos_old : crate :: position:: Position ,
30
29
vertical : bool ,
31
30
) -> BuildCtx {
32
31
BuildCtx {
33
32
force_wide,
33
+ force_wide_success : true ,
34
34
indentation : 0 ,
35
35
path,
36
- pos_new,
37
36
pos_old,
38
37
vertical,
39
38
}
@@ -51,7 +50,6 @@ pub(crate) fn build(
51
50
force_wide,
52
51
path,
53
52
crate :: position:: Position :: default ( ) ,
54
- crate :: position:: Position :: default ( ) ,
55
53
vertical,
56
54
) ;
57
55
@@ -61,8 +59,8 @@ pub(crate) fn build(
61
59
& crate :: builder:: Step :: Format ( element) ,
62
60
) ;
63
61
64
- if build_ctx . force_wide && build_ctx . pos_new . line > 1 {
65
- None
62
+ if force_wide {
63
+ if build_ctx . force_wide_success { Some ( builder . finish ( ) ) } else { None }
66
64
} else {
67
65
Some ( builder. finish ( ) )
68
66
}
@@ -74,7 +72,7 @@ fn build_step(
74
72
75
73
step : & crate :: builder:: Step ,
76
74
) {
77
- if build_ctx. force_wide && build_ctx. pos_new . line > 1 {
75
+ if build_ctx. force_wide && ! build_ctx. force_wide_success {
78
76
return ;
79
77
}
80
78
@@ -120,6 +118,8 @@ fn build_step(
120
118
build_ctx. indentation += 1 ;
121
119
}
122
120
crate :: builder:: Step :: NewLine => {
121
+ build_ctx. force_wide_success = false ;
122
+
123
123
add_token (
124
124
builder,
125
125
build_ctx,
@@ -158,7 +158,6 @@ fn add_token(
158
158
text : & str ,
159
159
) {
160
160
builder. token ( rowan:: SyntaxKind ( kind as u16 ) , text) ;
161
- build_ctx. pos_new . update ( text) ;
162
161
}
163
162
164
163
fn format (
@@ -283,13 +282,7 @@ pub(crate) fn fits_in_single_line(
283
282
build_ctx : & crate :: builder:: BuildCtx ,
284
283
element : rnix:: SyntaxElement ,
285
284
) -> bool {
286
- let line = build_ctx. pos_new . line ;
287
- let maybe_green_node = build ( element, true , build_ctx. path . clone ( ) , false ) ;
288
-
289
- match maybe_green_node {
290
- Some ( _) => build_ctx. pos_new . line == line,
291
- None => false ,
292
- }
285
+ build ( element, true , build_ctx. path . clone ( ) , false ) . is_some ( )
293
286
}
294
287
295
288
pub ( crate ) fn make_isolated_token (
0 commit comments