|
356 | 356 | ; Note that this query is disjoint from the other one defining the "annotations" |
357 | 357 | ; scope above, which that only applies when the annotation is the last named |
358 | 358 | ; node of its parent. Thus, only one of the two ever matches. |
| 359 | +; |
| 360 | +; WARNING: currently, splitting the rule in two is useless because we actually |
| 361 | +; add the newline before `=` inconditionally (see |
| 362 | +; [^annotations-followed-by-eq]). However, when this limitation is lifted, the |
| 363 | +; current rule architecture will allow for the desired formatting with minimal |
| 364 | +; change. |
359 | 365 | ( |
360 | 366 | (#scope_id! "annotations") |
361 | 367 | (_) @append_begin_scope |
|
371 | 377 | (annot_atom) @prepend_spaced_scoped_softline |
372 | 378 | ) |
373 | 379 |
|
374 | | -; Add a new line before the last annotation and the following equal sign, if any, |
375 | | -; in a multi-line context. |
| 380 | +; Add a new line before the last annotation and the following equal sign. |
| 381 | +; |
| 382 | +; [^annotations-followed-by-eq]: Ideally, we would like to only add this new |
| 383 | +; line for multi-line annotations only. That is, we would like to have the |
| 384 | +; following formatting: |
| 385 | +; |
| 386 | +; let foo |
| 387 | +; | Array Number |
| 388 | +; | doc "hello" |
| 389 | +; = [ |
| 390 | +; 1, |
| 391 | +; 2, |
| 392 | +; ] |
| 393 | +; in ... |
| 394 | +; |
| 395 | +; But |
| 396 | +; |
| 397 | +; let foo | Array Number = [ |
| 398 | +; 1, |
| 399 | +; 2, |
| 400 | +; ] |
| 401 | +; in ... |
| 402 | +; |
| 403 | +; While adding a scoped line isn't an issue, note that in the examples above, |
| 404 | +; the indentation of what comes after the `=` sign depends on the multi-liness |
| 405 | +; of the annotations (and thus of the multiliness of the "annotations" scope). |
| 406 | +; However, the RHS isn't part of this scope (and we don't want it to be). |
| 407 | +; Unfortunately, this can't be achieved in current Topiary. |
| 408 | +; |
| 409 | +; In the meantime, we always put the `=` sign a new line, whether in single-line |
| 410 | +; or multi-line mode, and always indent the RHS further in presence of |
| 411 | +; annotations. This give the following formatting for the second example: |
| 412 | +; |
| 413 | +; let foo | Array Number |
| 414 | +; = [ |
| 415 | +; 1, |
| 416 | +; 2, |
| 417 | +; ] |
| 418 | +; in ... |
| 419 | +; |
| 420 | +; which isn't optimal but still acceptable. |
376 | 421 | ( |
377 | 422 | (#scope_id! "annotations") |
378 | 423 | (annot) @append_spaced_scoped_softline |
|
387 | 432 | (annot_atom) @prepend_indent_start @append_indent_end |
388 | 433 | ) |
389 | 434 |
|
390 | | -; In multi-line mode, in presence of annotations, we want to indent the |
391 | | -; potential definitions that comes after. |
392 | | -; |
393 | | -; In single-line mode (in the "annotations" scope), we want a packed |
394 | | -; representation: |
395 | | -; |
396 | | -; let foo | Number = [ |
397 | | -; 1, |
398 | | -; 2, |
399 | | -; ] |
400 | | -; in foo |
| 435 | +; Indent the RHS of the let-binding in presence of annotations. |
401 | 436 | ; |
402 | | -; But we want to format a multi-line version as: |
403 | | -; |
404 | | -; let foo |
405 | | -; | Number |
406 | | -; = [ |
407 | | -; 1, |
408 | | -; 2, |
409 | | -; ] |
410 | | -; in foo |
| 437 | +; Ideally, we would like to indent only when annotations are multi-line, but |
| 438 | +; this isn't current possible; see [^annotations-followed-by-eq]. |
411 | 439 | (_ |
412 | | - (annot (#multi_line_scope_only! "annotations")) @prepend_indent_start |
| 440 | + (annot) @append_indent_start |
413 | 441 | . |
414 | 442 | "=" |
415 | 443 | . |
|
0 commit comments