Skip to content

Commit 23b9227

Browse files
committed
Support async/await
Imenu and indentation.
1 parent f88e1ac commit 23b9227

File tree

10 files changed

+114
-40
lines changed

10 files changed

+114
-40
lines changed

swift-mode-indent.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,7 @@ It is a Generic parameter list if:
15011501
"try" "try?" "try!"
15021502
"as" "as?" "as!"
15031503
"is"
1504+
"await"
15041505
"in"
15051506
"init" "deinit" "get" "set" "willSet" "didSet" "subscript"
15061507
"for" "case" "default" "while" "let" "var" "repeat" "if" "else"

swift-mode-lexer.el

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ END is the point after the token."
9999

100100
;; Token types is one of the following symbols:
101101
;;
102-
;; - prefix-operator (including try, try?, and try!)
102+
;; - prefix-operator (including try, try?, try!, and await)
103103
;; - postfix-operator
104104
;; - binary-operator (including as, as?, as!, is, =, ., and ->)
105105
;; - attribute (e.g. @objc, @abc(def))
@@ -402,9 +402,9 @@ Return nil otherwise."
402402
(memq (swift-mode:token:type next-token)
403403
'(binary-operator \; \, :))
404404

405-
;; Suppresses implicit semicolon after try, try?, and try!.
405+
;; Suppresses implicit semicolon after try, try?, try!, and await.
406406
(member (swift-mode:token:text previous-token)
407-
'("try" "try?" "try!"))
407+
'("try" "try?" "try!" "await"))
408408

409409
;; Suppress implicit semicolon after open brackets or before close
410410
;; brackets.
@@ -433,7 +433,7 @@ Return nil otherwise."
433433
(member (swift-mode:token:text previous-token)
434434
'("some" "inout" "in" "where"))
435435
(member (swift-mode:token:text next-token)
436-
'("some" "inout" "throws" "rethrows" "in" "where")))
436+
'("some" "inout" "throws" "rethrows" "async" "in" "where")))
437437
nil)
438438

439439
;; Inserts semicolon before open curly bracket.
@@ -779,7 +779,7 @@ Other properties are the same as the TOKEN."
779779
(type
780780
(cond
781781
(is-declaration 'identifier)
782-
((member text '("try" "try?" "try!")) 'prefix-operator)
782+
((member text '("try" "try?" "try!" "await")) 'prefix-operator)
783783
((equal text ".") 'binary-operator)
784784
((and has-preceding-space has-following-space) 'binary-operator)
785785
(has-preceding-space 'prefix-operator)
@@ -925,7 +925,7 @@ This function does not return `implicit-;' or `type-:'."
925925
(forward-char)
926926
(swift-mode:token '> ">" (1- (point)) (point)))
927927

928-
;; Operator (other than as, try, or is)
928+
;; Operator (other than as, try, is, or await)
929929
;;
930930
;; Operators starts with a dot can contains dots. Other operators cannot
931931
;; contain dots.
@@ -1019,6 +1019,11 @@ This function does not return `implicit-;' or `type-:'."
10191019
text
10201020
(- (point) (length text))
10211021
(point)))
1022+
((equal text "await")
1023+
(swift-mode:token 'prefix-operator
1024+
text
1025+
(- (point) (length text))
1026+
(point)))
10221027
(t
10231028
(swift-mode:token 'identifier
10241029
text
@@ -1173,7 +1178,7 @@ This function does not return `implicit-;' or `type-:'."
11731178
(backward-char)
11741179
(swift-mode:token '> ">" (point) (1+ (point))))
11751180

1176-
;; Operator (other than as, try, or is)
1181+
;; Operator (other than as, try, is, or await)
11771182
;;
11781183
;; Operators which starts with a dot can contain other dots. Other
11791184
;; operators cannot contain dots.
@@ -1254,7 +1259,7 @@ This function does not return `implicit-;' or `type-:'."
12541259
text
12551260
(point)
12561261
(+ (point) (length text))))
1257-
((equal text "try")
1262+
((member text '("try" "await"))
12581263
(swift-mode:token 'prefix-operator
12591264
text
12601265
(point)

test/swift-files/beginning-of-defun/beginning-of-defun.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ foo() {
141141
]/*]*/
142142
}
143143
)
144+
async
144145
throws
145146
->
146147
@Foo

test/swift-files/imenu/imenu-expected.el

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
((precedencegroup (identifier "precedenceGroup" 2753 2768) nil)
2-
(operator (identifier "*****" 2713 2718) nil)
3-
(operator (identifier "-----" 2673 2678) nil)
4-
(operator (identifier "+++++" 2634 2639) nil)
5-
(extension (identifier "FooClass" 2469 2477)
6-
((class (identifier "NestedClass1" 2509 2521)
7-
((class (identifier "NestedClass2" 2538 2550)
8-
((class (identifier "NestedClass3" 2571 2583) nil)))))))
9-
(protocol (identifier "FooProtocol" 2209 2220)
10-
((var (identifier "protocolProperty" 2236 2252) nil)
11-
(func (identifier "protocolMethod(a:b:)" 2278 2292) nil)
12-
(init (identifier "init(a:b:c:)" 2320 2324) nil)
13-
(subscript (identifier "subscript(_:bbb:)" 2355 2364) nil)
14-
(associatedtype (identifier "AssociatedType" 2436 2450) nil)))
15-
(actor (identifier "FooActor" 2181 2189) nil)
16-
(struct (identifier "FooStruct" 2155 2164) nil)
17-
(enum (identifier "FooEnum2" 2090 2098)
18-
((case (identifier "case1" 2115 2120) nil)
19-
(case (identifier "case2" 2135 2140) nil)))
20-
(enum (identifier "FooEnum1" 1955 1963)
21-
((case (identifier "case1" 2002 2007) nil)
22-
(case (identifier "case2" 2033 2038) nil)
23-
(case (identifier "case3" 2062 2067) nil)))
1+
((precedencegroup (identifier "precedenceGroup" 2759 2774) nil)
2+
(operator (identifier "*****" 2719 2724) nil)
3+
(operator (identifier "-----" 2679 2684) nil)
4+
(operator (identifier "+++++" 2640 2645) nil)
5+
(extension (identifier "FooClass" 2475 2483)
6+
((class (identifier "NestedClass1" 2515 2527)
7+
((class (identifier "NestedClass2" 2544 2556)
8+
((class (identifier "NestedClass3" 2577 2589) nil)))))))
9+
(protocol (identifier "FooProtocol" 2215 2226)
10+
((var (identifier "protocolProperty" 2242 2258) nil)
11+
(func (identifier "protocolMethod(a:b:)" 2284 2298) nil)
12+
(init (identifier "init(a:b:c:)" 2326 2330) nil)
13+
(subscript (identifier "subscript(_:bbb:)" 2361 2370) nil)
14+
(associatedtype (identifier "AssociatedType" 2442 2456) nil)))
15+
(actor (identifier "FooActor" 2187 2195) nil)
16+
(struct (identifier "FooStruct" 2161 2170) nil)
17+
(enum (identifier "FooEnum2" 2096 2104)
18+
((case (identifier "case1" 2121 2126) nil)
19+
(case (identifier "case2" 2141 2146) nil)))
20+
(enum (identifier "FooEnum1" 1961 1969)
21+
((case (identifier "case1" 2008 2013) nil)
22+
(case (identifier "case2" 2039 2044) nil)
23+
(case (identifier "case3" 2068 2073) nil)))
2424
(class (identifier "FooClass" 597 605)
2525
((var (identifier "classVariable1" 674 688) nil)
2626
(class (identifier "final" 724 729) nil)
2727
(var (identifier "compuatedProperty" 752 769) nil)
2828
(var (identifier "observedProperty" 911 927) nil)
2929
(typealias (identifier "TypeAlias" 1075 1084) nil)
3030
(func (identifier "function1(aaa:_:ddd:eee:)" 1139 1148) nil)
31-
(func (identifier "function2()" 1336 1345) nil)
32-
(func (identifier "function3(a:)" 1419 1428) nil)
33-
(func (identifier "+(_:_:)" 1563 1564) nil)
34-
(subscript (identifier "subscript(_:bbb:)" 1725 1734) nil)
35-
(init (identifier "init(a:)" 1873 1877) nil)
36-
(init (identifier "init(b:)" 1900 1904) nil)
37-
(deinit (identifier "deinit" 1927 1933) nil)))
31+
(func (identifier "function2()" 1342 1351) nil)
32+
(func (identifier "function3(a:)" 1425 1434) nil)
33+
(func (identifier "+(_:_:)" 1569 1570) nil)
34+
(subscript (identifier "subscript(_:bbb:)" 1731 1740) nil)
35+
(init (identifier "init(a:)" 1879 1883) nil)
36+
(init (identifier "init(b:)" 1906 1910) nil)
37+
(deinit (identifier "deinit" 1933 1939) nil)))
3838
(var (identifier "globalVariable2" 560 575) nil)
3939
(var (identifier "globalVariable1" 530 545) nil)
4040
(let (identifier "globalConstant2" 496 511) nil)

test/swift-files/imenu/imenu.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import func FooModule3.importedFunction
4444

4545
@AAA internal typealias TypeAlias<A: AA, B: BB, C: CC> = AAA
4646

47-
@AAA class final func function1<A: AA, B: BB, C: CC>(aaa bbb: Int, _ ccc: Int, ddd: Int = 1, eee: inout Int = 2) throws -> AAA {
47+
@AAA class final func function1<A: AA, B: BB, C: CC>(aaa bbb: Int, _ ccc: Int, ddd: Int = 1, eee: inout Int = 2) async throws -> AAA {
4848
let a = 1
4949
var b = 2
5050

test/swift-files/indent/declarations.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class Foo {
8181
Int,
8282
Int
8383
)
84+
async
8485
throws
8586
->
8687
[
@@ -314,6 +315,7 @@ private
314315
Int
315316
...
316317
)
318+
async
317319
throws
318320
->
319321
[A]

test/swift-files/indent/expressions.swift

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ foo(
1212
&x
1313
)
1414

15-
// Try operators
15+
// Try and await operators
1616

1717
let foo = try
1818
a() + try
@@ -38,6 +38,36 @@ let foo = a+try?
3838
a() + b+try?
3939
b()
4040

41+
42+
let foo = await
43+
a() + await
44+
b()
45+
46+
let foo = a+await
47+
a() +b+await
48+
b()
49+
50+
let foo = try await
51+
a() + try await
52+
b()
53+
54+
let foo = a+try await
55+
a() +b+try await
56+
b()
57+
58+
let foo = try
59+
await
60+
a() + try
61+
await
62+
b()
63+
64+
let foo = a+try
65+
await
66+
a() +b+try
67+
await
68+
b()
69+
70+
4171
// Binary expressions
4272
// See also operators.swift
4373

@@ -305,6 +335,7 @@ let x = { (
305335
x: Int,
306336
y: Int
307337
)
338+
async
308339
throws
309340
->
310341
Foo
@@ -325,6 +356,7 @@ let x = { [
325356
x: Int,
326357
y: Int
327358
)
359+
async
328360
throws
329361
->
330362
Foo
@@ -344,6 +376,7 @@ let x = {
344376
x: Int,
345377
y: Int
346378
)
379+
async
347380
throws
348381
->
349382
Foo

test/swift-files/indent/identifiers.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,15 @@ func foo() {
194194
foo(
195195
throw: 1
196196
)
197+
foo(
198+
async: 1
199+
)
197200
foo(
198201
try: 1
199202
)
203+
foo(
204+
await: 1
205+
)
200206

201207
// Keywords reserved in particular contexts
202208
foo(

test/swift-files/indent/statements.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,17 @@ for
322322
{
323323
}
324324

325+
for
326+
try
327+
await
328+
x
329+
in
330+
xs() {
331+
foo()
332+
foo()
333+
}
334+
335+
325336
// While statements
326337

327338
while foo

test/swift-files/indent/types.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,21 @@ let foo
258258
B
259259
= abc
260260

261+
let foo:
262+
(A, B)
263+
async
264+
throws
265+
->
266+
(A)
267+
async
268+
rethrows
269+
->
270+
(A)
271+
async
272+
->
273+
B
274+
= abc
275+
261276

262277
// Optional types
263278

0 commit comments

Comments
 (0)