Skip to content

Commit 6c793cf

Browse files
committed
Revert to simpler formatting
1 parent 67413d3 commit 6c793cf

File tree

1 file changed

+51
-23
lines changed

1 file changed

+51
-23
lines changed

topiary-queries/queries/nickel.scm

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@
356356
; Note that this query is disjoint from the other one defining the "annotations"
357357
; scope above, which that only applies when the annotation is the last named
358358
; 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.
359365
(
360366
(#scope_id! "annotations")
361367
(_) @append_begin_scope
@@ -371,8 +377,47 @@
371377
(annot_atom) @prepend_spaced_scoped_softline
372378
)
373379

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.
376421
(
377422
(#scope_id! "annotations")
378423
(annot) @append_spaced_scoped_softline
@@ -387,29 +432,12 @@
387432
(annot_atom) @prepend_indent_start @append_indent_end
388433
)
389434

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.
401436
;
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].
411439
(_
412-
(annot (#multi_line_scope_only! "annotations")) @prepend_indent_start
440+
(annot) @append_indent_start
413441
.
414442
"="
415443
.

0 commit comments

Comments
 (0)