Debian Codegraph @

tests/indent/rust.rs

raw symbols SCIP
1 use std::{
2 io::{self, stdout, Stdout, Write},
3 path::PathBuf,
4 sync::Arc,
5 time::Duration,
6 };
7 mod test {
8 fn hello_world() {
9 1 + 1;
10
11 let does_indentation_work = 1;
12
13 // Assignment / destructuring RHS continued on the next line. helix
14 // deliberately indents these continuations only when reindenting an
15 // already-complete expression (an opinionated binary/assignment rule);
16 // typing a newline after `=` does not indent the RHS, because the value
17 // is a sibling the typing-direction walk never reaches. Left commented so
18 // the corpus stays clean in both directions.
19 // let mut really_long_variable_name_using_up_the_line =
20 // really_long_fn_that_should_definitely_go_on_the_next_line();
21 // really_long_variable_name_using_up_the_line =
22 // really_long_fn_that_should_definitely_go_on_the_next_line();
23 // really_long_variable_name_using_up_the_line |=
24 // really_long_fn_that_should_definitely_go_on_the_next_line();
25 //
26 // let (
27 // a_long_variable_name_in_this_tuple,
28 // b_long_variable_name_in_this_tuple,
29 // c_long_variable_name_in_this_tuple,
30 // d_long_variable_name_in_this_tuple,
31 // e_long_variable_name_in_this_tuple,
32 // ): (usize, usize, usize, usize, usize) =
33 // if really_long_fn_that_should_definitely_go_on_the_next_line() {
34 // (03294239434, 1213412342314, 21231234134)
35 // } else {
36 // (0, 1, 2)
37 // };
38
39 let test_function = function_with_param(this_param,
40 that_param
41 );
42
43 let test_function = function_with_param(
44 this_param,
45 that_param
46 );
47
48 let test_function = function_with_proper_indent(param1,
49 param2,
50 );
51
52 let selection = Selection::new(
53 changes
54 .clone()
55 .map(|(start, end, text): (usize, usize, Option<Tendril>)| {
56 let len = text.map(|text| text.len()).unwrap() - 1; // minus newline
57 let pos = start + len;
58 Range::new(pos, pos)
59 })
60 .collect(),
61 0,
62 );
63
64 return;
65 }
66 }
67
68 impl<A, D> MyTrait<A, D> for YourType
69 where
70 A: TraitB + TraitC,
71 D: TraitE + TraitF,
72 {
73
74 }
75 #[test]
76 //
77 match test {
78 Some(a) => 1,
79 None => {
80 unimplemented!()
81 }
82 }
83 std::panic::set_hook(Box::new(move |info| {
84 hook(info);
85 }));
86
87 { { {
88 1
89 }}}
90
91 pub fn change<I>(document: &Document, changes: I) -> Self
92 where
93 I: IntoIterator<Item = Change> + ExactSizeIterator,
94 {
95 [
96 1,
97 2,
98 3,
99 ];
100 (
101 1,
102 2
103 );
104 true
105 }
106
107 trait Greet {
108 fn hello(&self) -> String;
109
110 fn default_greeting() -> String {
111 String::from("hi")
112 }
113 }
114
115 enum Shape {
116 Circle { radius: f64 },
117 Square(f64),
118 Point,
119 }
120
121 fn process(shape: Shape) -> i32 {
122 match shape {
123 Shape::Circle { radius } if radius > 0.0 => {
124 let area = 3.14 * radius * radius;
125 area as i32
126 }
127 Shape::Square(side) => (side * side) as i32,
128 Shape::Point => 0,
129 }
130 }
131
132 fn handle(opt: Option<i32>) {
133 if let Some(value) = opt {
134 println!("{}", value);
135 }
136
137 while let Some(item) = iterator.next() {
138 process(item);
139 }
140
141 let closure = |x: i32| {
142 let doubled = x * 2;
143 doubled + 1
144 };
145
146 let nested: Vec<Vec<i32>> = vec![
147 vec![1, 2],
148 vec![3, 4],
149 ];
150 }
151
152 fn let_else(opt: Option<i32>) -> i32 {
153 let Some(value) = opt else {
154 return 0;
155 };
156 value
157 }
158
159 fn branches(x: i32) -> i32 {
160 if x > 0 {
161 1
162 } else if x < 0 {
163 -1
164 } else {
165 0
166 }
167 }
168
169 async fn await_chain() -> Result<i32, Error> {
170 let value = client
171 .request()
172 .await?
173 .json()
174 .await?;
175 Ok(value)
176 }
177
178 fn block_rhs() -> i32 {
179 let x = {
180 let a = 1;
181 a + 1
182 };
183 x
184 }
185
186 fn labeled() -> i32 {
187 let result = 'outer: loop {
188 loop {
189 break 'outer 42;
190 }
191 };
192 result
193 }
194
195 #[derive(
196 Debug,
197 Clone,
198 )]
199 struct Config {
200 name: String,
201 }
202
203 fn update_syntax() -> Config {
204 Config {
205 name: "x".to_string(),
206 ..Default::default()
207 }
208 }
209
210 fn match_nested(x: i32) -> i32 {
211 match x {
212 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15
213 | 16 | 17 => 1,
214 n if n > 10 => {
215 let doubled = n * 2;
216 doubled
217 }
218 _ => match x {
219 0 => 0,
220 _ => -1,
221 },
222 }
223 }
224
225 fn binary_cont() -> bool {
226 let result = some_long_condition_here
227 && another_condition
228 && third_condition;
229 result
230 }
231
232 fn arm_struct(x: i32) -> Point {
233 match x {
234 0 => Point {
235 x: 0,
236 y: 0,
237 },
238 _ => Point { x: 1, y: 1 },
239 }
240 }
241
242 fn chain_off_multiline_call() {
243 let x = Foo::new(
244 arg1,
245 arg2,
246 )
247 .method()
248 .other();
249 }
250
251 fn complex<T, U>(
252 first: T,
253 second: U,
254 ) -> Result<T, U>
255 where
256 T: Clone,
257 U: Debug,
258 {
259 todo!()
260 }
261
262 fn await_chain_off_multiline_call() -> Result<(), Error> {
263 let v = build_request(
264 url,
265 body,
266 )
267 .send()
268 .await?;
269 Ok(())
270 }
271
272 // Multi-line string / raw-string bodies are literal content: the @opaque rule
273 // preserves their existing leading whitespace instead of reformatting it.
274 fn strings() {
275 let s = "first
276 second
277 indented in string";
278 let r = r#"
279 raw line
280 indented raw"#;
281 println!("{s}{r}");
282 }