1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// SPDX-License-Identifier: MIT
/// Intermediate representation node for the Wadler-Lindig pretty printer.
///
/// A `Doc` describes a document structure independent of rendering. The printer
/// decides whether to render `Group` nodes in flat mode (everything on one line)
/// or break mode (line breaks expanded) based on available width.
/// Construct a `Doc::Text` node.
///
/// # Examples
///
/// ```
/// use rlsp_fmt::{text, format, FormatOptions};
///
/// let doc = text("hello");
/// assert_eq!(format(&doc, &FormatOptions::default()), "hello");
/// ```
/// Construct a `Doc::HardLine` node.
///
/// # Examples
///
/// ```
/// use rlsp_fmt::{concat, hard_line, text, format, FormatOptions};
///
/// let doc = concat(vec![text("a"), hard_line(), text("b")]);
/// assert_eq!(format(&doc, &FormatOptions::default()), "a\nb");
/// ```
pub const
/// Construct a `Doc::Line` node (soft break).
///
/// # Examples
///
/// ```
/// use rlsp_fmt::{concat, group, line, text, format, FormatOptions};
///
/// // In a group that fits, Line renders as a space.
/// let doc = group(concat(vec![text("a"), line(), text("b")]));
/// assert_eq!(format(&doc, &FormatOptions::default()), "a b");
/// ```
pub const
/// Construct a `Doc::Indent` node.
///
/// # Examples
///
/// ```
/// use rlsp_fmt::{concat, group, indent, line, text, format, FormatOptions};
///
/// let doc = group(concat(vec![
/// text("key:"),
/// indent(concat(vec![line(), text("value")])),
/// ]));
/// let opts = FormatOptions { print_width: 5, ..Default::default() };
/// assert_eq!(format(&doc, &opts), "key:\n value");
/// ```
/// Construct a `Doc::Group` node.
///
/// # Examples
///
/// ```
/// use rlsp_fmt::{concat, group, line, text, format, FormatOptions};
///
/// // Wide width: group stays flat.
/// let doc = group(concat(vec![text("a"), line(), text("b")]));
/// assert_eq!(format(&doc, &FormatOptions::default()), "a b");
///
/// // Narrow width: group breaks.
/// let opts = FormatOptions { print_width: 1, ..Default::default() };
/// assert_eq!(format(&doc, &opts), "a\nb");
/// ```
/// Construct a `Doc::Concat` node from a vector of documents.
///
/// # Examples
///
/// ```
/// use rlsp_fmt::{concat, text, format, FormatOptions};
///
/// let doc = concat(vec![text("foo"), text("bar")]);
/// assert_eq!(format(&doc, &FormatOptions::default()), "foobar");
/// ```
pub const
/// Construct a `Doc::FlatAlt` node.
///
/// # Examples
///
/// ```
/// use rlsp_fmt::{flat_alt, group, text, format, FormatOptions};
///
/// // In a group that fits, the flat variant is used.
/// let doc = group(flat_alt(text("flat"), text("break")));
/// assert_eq!(format(&doc, &FormatOptions::default()), "flat");
/// ```
/// Intersperse `separator` between each element of `docs`.
///
/// Returns `Doc::Concat([])` if `docs` is empty.
///
/// # Panics
///
/// Does not panic — the `expect` is unreachable after the empty-list guard.
///
/// # Examples
///
/// ```
/// use rlsp_fmt::{join, text, format, FormatOptions};
///
/// let sep = text(", ");
/// let items = vec![text("a"), text("b"), text("c")];
/// let doc = join(&sep, items);
/// assert_eq!(format(&doc, &FormatOptions::default()), "a, b, c");
/// ```