|
318 | 318 |
|
319 | 319 | ;; Annotations |
320 | 320 |
|
321 | | -; Start an indentation block from the start of the annotations to the |
322 | | -; end of the enclosing node |
323 | | -(_ |
324 | | - (annot) @prepend_indent_start |
325 | | -) @append_indent_end |
326 | | - |
327 | | -; Start a scope from the node previous to the annotations. |
328 | | -; This properly checks if the annotations were intended to be |
329 | | -; on newlines in such cases as: |
| 321 | +; Start a scope from the node previous to the annotations. This properly checks |
| 322 | +; if the annotations were intended to be on newlines in such cases as: |
| 323 | +; |
330 | 324 | ; id |
331 | 325 | ; | a -> a |
| 326 | +; |
332 | 327 | ; which, without the annotations scope, would consider the annotations to be a |
333 | 328 | ; single line node and format it as such: |
| 329 | +; |
334 | 330 | ; id | a -> a |
335 | 331 | ( |
336 | 332 | (#scope_id! "annotations") |
|
339 | 335 | (annot) @append_end_scope |
340 | 336 | ) |
341 | 337 |
|
342 | | -; Put each annotation -- and the equals sign, if it follows annotations |
343 | | -; -- on a new line, in a multi-line context. |
| 338 | +; Put each annotation on a new line, in a multi-line context. |
344 | 339 | (annot |
345 | 340 | (#scope_id! "annotations") |
346 | 341 | (annot_atom) @prepend_spaced_scoped_softline |
347 | 342 | ) |
348 | 343 |
|
| 344 | +; Add a new line before the last annotation and the following equal sign. |
| 345 | +; |
| 346 | +; [^annotations-followed-by-eq]: Ideally, we would like to add this new |
| 347 | +; line for multi-line annotations only. That is, we would like to have the |
| 348 | +; following formatting: |
| 349 | +; |
| 350 | +; let foo |
| 351 | +; | Array Number |
| 352 | +; | doc "hello" |
| 353 | +; = [ |
| 354 | +; 1, |
| 355 | +; 2, |
| 356 | +; ] |
| 357 | +; in ... |
| 358 | +; |
| 359 | +; But |
| 360 | +; |
| 361 | +; let foo | Array Number = [ |
| 362 | +; 1, |
| 363 | +; 2, |
| 364 | +; ] |
| 365 | +; in ... |
| 366 | +; |
| 367 | +; While adding a scoped line isn't an issue, note that in the examples above, |
| 368 | +; the indentation of what comes after the `=` sign depends on the multi-liness |
| 369 | +; of the annotations (and thus of the multiliness of the "annotations" scope). |
| 370 | +; However, the RHS isn't part of this scope (and we don't want it to be). |
| 371 | +; Unfortunately, this can't be achieved in current Topiary. |
| 372 | +; |
| 373 | +; In the meantime, we always put the `=` sign a new line, whether in single-line |
| 374 | +; or multi-line mode, and always indent the RHS further in presence of |
| 375 | +; annotations. This give the following formatting for the second example: |
| 376 | +; |
| 377 | +; let foo | Array Number |
| 378 | +; = [ |
| 379 | +; 1, |
| 380 | +; 2, |
| 381 | +; ] |
| 382 | +; in ... |
| 383 | +; |
| 384 | +; which isn't optimal but still acceptable. |
349 | 385 | ( |
350 | | - (annot) |
| 386 | + (annot) @append_spaced_softline |
351 | 387 | . |
352 | | - "=" @prepend_spaced_softline |
| 388 | + "=" |
| 389 | +) |
| 390 | + |
| 391 | +; Indent the annotations with respect to the identifier they annotate. |
| 392 | +( |
| 393 | + (annot) @prepend_indent_start @append_indent_end |
| 394 | +) |
| 395 | + |
| 396 | +; Indent the RHS of the let-binding in presence of annotations. |
| 397 | +; |
| 398 | +; Ideally, we would like to indent only when annotations are multi-line, but |
| 399 | +; this isn't current possible; see [^annotations-followed-by-eq]. |
| 400 | +(_ |
| 401 | + (annot) @append_indent_start |
| 402 | + "=" |
| 403 | + (term) @append_indent_end |
353 | 404 | ) |
354 | 405 |
|
355 | 406 | ; Break a multi-line polymorphic type annotation after the type |
|
0 commit comments