on master help sign in
Add indent queries for scheme (and reuse them for common-lisp & racket). (#8720)
cb0bc25Triton171
book/src/generated/lang-support.md+3−3
@@ -16,7 +16,7 @@
16| clojure | ✓ | | | `clojure-lsp` |
16| clojure | ✓ | | | `clojure-lsp` |
17| cmake | ✓ | ✓ | ✓ | `cmake-language-server` |
17| cmake | ✓ | ✓ | ✓ | `cmake-language-server` |
18| comment | ✓ | | | |
18| comment | ✓ | | | |
19−| common-lisp | ✓ | | | `cl-lsp` |
19+| common-lisp | ✓ | | ✓ | `cl-lsp` |
20| cpon | ✓ | | ✓ | |
20| cpon | ✓ | | ✓ | |
21| cpp | ✓ | ✓ | ✓ | `clangd` |
21| cpp | ✓ | ✓ | ✓ | `clangd` |
22| crystal | ✓ | ✓ | | `crystalline` |
22| crystal | ✓ | ✓ | | `crystalline` |
@@ -128,7 +128,7 @@
128| python | ✓ | ✓ | ✓ | `pylsp` |
128| python | ✓ | ✓ | ✓ | `pylsp` |
129| qml | ✓ | | ✓ | `qmlls` |
129| qml | ✓ | | ✓ | `qmlls` |
130| r | ✓ | | | `R` |
130| r | ✓ | | | `R` |
131−| racket | ✓ | | | `racket` |
131+| racket | ✓ | | ✓ | `racket` |
132| regex | ✓ | | | |
132| regex | ✓ | | | |
133| rego | ✓ | | | `regols` |
133| rego | ✓ | | | `regols` |
134| rescript | ✓ | ✓ | | `rescript-language-server` |
134| rescript | ✓ | ✓ | | `rescript-language-server` |
@@ -140,7 +140,7 @@
140| rust | ✓ | ✓ | ✓ | `rust-analyzer` |
140| rust | ✓ | ✓ | ✓ | `rust-analyzer` |
141| sage | ✓ | ✓ | | |
141| sage | ✓ | ✓ | | |
142| scala | ✓ | | ✓ | `metals` |
142| scala | ✓ | | ✓ | `metals` |
143−| scheme | ✓ | | | |
143+| scheme | ✓ | | ✓ | |
144| scss | ✓ | | | `vscode-css-language-server` |
144| scss | ✓ | | | `vscode-css-language-server` |
145| slint | ✓ | | ✓ | `slint-lsp` |
145| slint | ✓ | | ✓ | `slint-lsp` |
146| smithy | ✓ | | | `cs` |
146| smithy | ✓ | | | `cs` |
languages.toml+1
@@ -1278,6 +1278,7 @@ roots = []
1278file-types = ["rkt", "rktd", "rktl", "scrbl"]
1278file-types = ["rkt", "rktd", "rktl", "scrbl"]
1279shebangs = ["racket"]
1279shebangs = ["racket"]
1280comment-token = ";"
1280comment-token = ";"
1281+indent = { tab-width = 2, unit = " " }
1281language-servers = [ "racket" ]
1282language-servers = [ "racket" ]
1282grammar = "scheme"
1283grammar = "scheme"
1283
1284
runtime/queries/common-lisp/indents.scmnew file+1
@@ -0,0 +1 @@
1+; inherits: scheme
runtime/queries/racket/indents.scmnew file+1
@@ -0,0 +1 @@
1+; inherits: scheme
runtime/queries/scheme/indents.scmnew file+43
@@ -0,0 +1,43 @@
1+; This roughly follows the description at: https://github.com/ds26gte/scmindent#how-subforms-are-indented
2+
3+; Exclude literals in the first patterns, since different rules apply for them.
4+; Similarly, exclude certain keywords (detected by a regular expression).
5+; If a list has 2 elements on the first line, it is aligned to the second element.
6+(list . (_) @first . (_) @anchor
7+ (#same-line? @first @anchor)
8+ (#set! "scope" "tail")
9+ (#not-kind-eq? @first "boolean") (#not-kind-eq? @first "character") (#not-kind-eq? @first "string") (#not-kind-eq? @first "number")
10+ (#not-match? @first "def.*|let.*|set!")) @align
11+; If the first element in a list is also a list and on a line by itself, the outer list is aligned to it
12+(list . (list) @anchor .
13+ (#set! "scope" "tail")
14+ (#not-kind-eq? @first "boolean") (#not-kind-eq? @first "character") (#not-kind-eq? @first "string") (#not-kind-eq? @first "number")) @align
15+(list . (list) @anchor . (_) @second
16+ (#not-same-line? @anchor @second)
17+ (#set! "scope" "tail")
18+ (#not-kind-eq? @first "boolean") (#not-kind-eq? @first "character") (#not-kind-eq? @first "string") (#not-kind-eq? @first "number")
19+ (#not-match? @first "def.*|let.*|set!")) @align
20+; If the first element in a list is not a list and on a line by itself, the outer list is aligned to
21+; it plus 1 additional space. This cannot currently be modelled exactly by our indent queries,
22+; but the following is equivalent, assuming that:
23+; - the indent width is 2 (the default for scheme)
24+; - There is no space between the opening parenthesis of the list and the first element
25+(list . (_) @first .
26+ (#not-kind-eq? @first "boolean") (#not-kind-eq? @first "character") (#not-kind-eq? @first "string") (#not-kind-eq? @first "number")
27+ (#not-match? @first "def.*|let.*|set!")) @indent
28+(list . (_) @first . (_) @second
29+ (#not-same-line? @first @second)
30+ (#not-kind-eq? @first "boolean") (#not-kind-eq? @first "character") (#not-kind-eq? @first "string") (#not-kind-eq? @first "number")
31+ (#not-match? @first "def.*|let.*|set!")) @indent
32+
33+; If the first element in a list is a literal, align the list to it
34+(list . [(boolean) (character) (string) (number)] @anchor
35+ (#set! "scope" "tail")) @align
36+
37+; If the first element is among a set of predefined keywords, align the list to this element
38+; plus 1 space (using the same workaround as above for now). This is a simplification since actually
39+; the second line of the list should be indented by 2 spaces more in some cases. Supporting this would
40+; be possible but require significantly more patterns.
41+(list . (symbol) @first
42+ (#match? @first "def.*|let.*|set!")) @indent
43+