@@ -51,30 +51,44 @@ fu! SynXMLish(syns)
51
51
return SynAttrXMLish (get (a: syns , -1 ))
52
52
endfu
53
53
54
- " Check if a synstack has any XMLish attribute.
55
- fu ! SynXMLishAny (syns)
56
- for synattr in a: syns
57
- if SynAttrXMLish (synattr)
58
- return 1
59
- endif
60
- endfor
61
- return 0
62
- endfu
63
-
64
54
" Check if a synstack denotes the end of a JSX block.
65
55
fu ! SynJSXBlockEnd (syns)
66
56
return get (a: syns , -1 ) = ~ ' \%(js\|javascript\)Braces' &&
67
57
\ SynAttrXMLish (get (a: syns , -2 ))
68
58
endfu
69
59
60
+ " Determine how many jsxRegions deep a synstack is.
61
+ fu ! SynJSXDepth (syns)
62
+ return len (filter (copy (a: syns ), ' v:val ==# "jsxRegion"' ))
63
+ endfu
64
+
65
+ " Check whether `cursyn' continues the same jsxRegion as `prevsyn'.
66
+ fu ! SynJSXContinues (cursyn, prevsyn)
67
+ let curdepth = SynJSXDepth (a: cursyn )
68
+ let prevdepth = SynJSXDepth (a: prevsyn )
69
+
70
+ " In most places, we expect the nesting depths to be the same between any
71
+ " two consecutive positions within a jsxRegion (e.g., between a parent and
72
+ " child node, between two JSX attributes, etc.). The exception is between
73
+ " sibling nodes, where after a completed element (with depth N), we return
74
+ " to the parent's nesting (depth N - 1). This case is easily detected,
75
+ " since it is the only time when the top syntax element in the synstack is
76
+ " jsxRegion---specifically, the jsxRegion corresponding to the parent.
77
+ return prevdepth == curdepth ||
78
+ \ (prevdepth == curdepth + 1 && get (a: cursyn , -1 ) == # ' jsxRegion' )
79
+ endfu
80
+
70
81
" Cleverly mix JS and XML indentation.
71
82
fu ! GetJsxIndent ()
72
83
let cursyn = SynSOL (v: lnum )
73
84
let prevsyn = SynEOL (v: lnum - 1 )
74
85
75
- " Use XML indenting if the syntax at the end of the previous line was either
76
- " JSX or was the closing brace of a jsBlock whose parent syntax was JSX.
77
- if (SynXMLish (prevsyn) || SynJSXBlockEnd (prevsyn)) && SynXMLishAny (cursyn)
86
+ " Use XML indenting iff:
87
+ " - the syntax at the end of the previous line was either JSX or was the
88
+ " closing brace of a jsBlock whose parent syntax was JSX; and
89
+ " - the current line continues the same jsxRegion as the previous line.
90
+ if (SynXMLish (prevsyn) || SynJSXBlockEnd (prevsyn)) &&
91
+ \ SynJSXContinues (cursyn, prevsyn)
78
92
let ind = XmlIndentGet (v: lnum , 0 )
79
93
80
94
" Align '/>' and '>' with '<' for multiline tags.
0 commit comments