Commit bab8ccd
[JavaScript] Code and Data specific indentation rules (#4015)
* [JavaScript] Exclude mappings from normal keyword indentation
Fixes https://forum.sublimetext.com/t/sublime-text-on-the-word-default/72953
This commit applies dedicated (json) indentation rules to JavaScript mappings
to avoid unexpected (un-)indenting of keys, which look like reserved control
structure keywords (e.g.: case, default, if, else, ...).
* [JavaScript] Exclude lists from normal keyword indentation
Same as for mappings, is true for lists. They can contain otherwise reserved
words, which should not be treated by indentation rules.
* [JavaScript] Add key binding for bracket content auto-indentation
This commit applies a key binding from JSON package to auto-indent content
of lists when hitting enter
var = [|]
becomes:
var = [
|
]
* [JavaScript] Handle function calls in mappings or lists
This commit...
1. extends selectors for each syntax (JS, JSX, TS, TSX) to choose correct
indentation rules in nested mappings, lists or functions/lambdas.
2. Adds check for trailing `:` to case/default indentation rule patterns,
as a function called `case()` in a mapping can't be prevented from being
unindented via selectors.
* [JavaScript] Reorganize tests
Merge new tests into existing file
* [JavaScript] Add tests for embedded JS code blocks
* [JavaScript] Remove failing tests
As we need to expect `:` after case/default, those tests no longer work
by intent.
* [JavaScript] Rename indentation rules file
* [JavaScript] Improve indentation rules of tagged template strings
This commit...
1. fixes lines after single-line tagged template string being indented.
before:
var foo = html`<p>content</p>`;
var bar = html`<p>content</p>`;
var baz = html`<p>content</p>`:
after:
var foo = html`<p>content</p>`;
var bar = html`<p>content</p>`;
var baz = html`<p>content</p>`:
2. excludes content of plain string templates from auto-indentation.
As their kind of content is undefined, normal indentation rules may
cause false results.
Tests are added to ensure normal JS statements keep untreated.
Notes:
First and last line of tagged templates is scoped `string.quoted.other`
regardless of embedded syntax highlighting, if only opening or closing
backticks appear.
Hence increasing indentation of tagged template strings' content is handled
by "Indentation Rules - Template Strings".
Decreasing indentation of closing backtick is handled
by normal "Indentation Rules" as those are the ones applied by ST.
It just doesn't work otherwise.
This circumstance helps to reliably distinguish opening and closing
backticks and correctly in- or decrease indentation.
* [JavaScript] Tweak key binding context key order
This commit aligns this PR with #4022.
* [JavaScript] Tweak enter key binding
This commit changes `enter` key binding to "Add Line in Braces" macro,
as it indents line between backticks using indentation rules instead of
forcing it to be indented via `\t`.
This works also, if indentation rules decide not to indent backticked contents.
* [JavaScript] Simplify indentation rules
By utilizing the improved selector scoring of build 4173, we can simply
have the two rules override each other based on the last meta scope on
the stack.
---------
Co-authored-by: FichteFoll <[email protected]>1 parent 00afce9 commit bab8ccd
File tree
7 files changed
+368
-14
lines changed- JavaScript
- tests
7 files changed
+368
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
72 | 92 | | |
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
4 | 11 | | |
5 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
6 | 22 | | |
7 | 23 | | |
8 | 24 | | |
9 | 25 | | |
10 | | - | |
| 26 | + | |
11 | 27 | | |
12 | 28 | | |
13 | 29 | | |
14 | 30 | | |
| 31 | + | |
| 32 | + | |
15 | 33 | | |
16 | 34 | | |
17 | 35 | | |
18 | | - | |
| 36 | + | |
19 | 37 | | |
20 | | - | |
| 38 | + | |
21 | 39 | | |
22 | 40 | | |
23 | 41 | | |
| |||
30 | 48 | | |
31 | 49 | | |
32 | 50 | | |
33 | | - | |
| 51 | + | |
34 | 52 | | |
35 | | - | |
| 53 | + | |
36 | 54 | | |
37 | | - | |
| 55 | + | |
38 | 56 | | |
39 | 57 | | |
40 | 58 | | |
| |||
72 | 90 | | |
73 | 91 | | |
74 | 92 | | |
75 | | - | |
76 | | - | |
77 | 93 | | |
78 | 94 | | |
79 | 95 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
3 | 86 | | |
4 | 87 | | |
5 | 88 | | |
| |||
548 | 631 | | |
549 | 632 | | |
550 | 633 | | |
551 | | - | |
552 | 634 | | |
553 | | - | |
554 | 635 | | |
555 | 636 | | |
556 | 637 | | |
557 | 638 | | |
558 | 639 | | |
559 | | - | |
560 | | - | |
561 | 640 | | |
562 | 641 | | |
563 | 642 | | |
| |||
982 | 1061 | | |
983 | 1062 | | |
984 | 1063 | | |
| 1064 | + | |
| 1065 | + | |
985 | 1066 | | |
986 | 1067 | | |
987 | 1068 | | |
| |||
992 | 1073 | | |
993 | 1074 | | |
994 | 1075 | | |
| 1076 | + | |
| 1077 | + | |
995 | 1078 | | |
996 | 1079 | | |
997 | 1080 | | |
| |||
1026 | 1109 | | |
1027 | 1110 | | |
1028 | 1111 | | |
| 1112 | + | |
| 1113 | + | |
1029 | 1114 | | |
1030 | 1115 | | |
1031 | 1116 | | |
| |||
1038 | 1123 | | |
1039 | 1124 | | |
1040 | 1125 | | |
| 1126 | + | |
| 1127 | + | |
1041 | 1128 | | |
1042 | 1129 | | |
1043 | 1130 | | |
| |||
1053 | 1140 | | |
1054 | 1141 | | |
1055 | 1142 | | |
1056 | | - | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
0 commit comments