Skip to content

Commit f88e1ac

Browse files
committed
Support actor
Imenu, indentation, and beginning-of-defun.
1 parent 471d158 commit f88e1ac

File tree

9 files changed

+85
-52
lines changed

9 files changed

+85
-52
lines changed

swift-mode-beginning-of-defun.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ The cursor must be at the beginning of a statement."
168168
(let ((token (swift-mode:forward-token-or-list))
169169
(defun-keywords
170170
'("import" "typealias" "associatedtype"
171-
"enum" "struct" "protocol" "extension"
171+
"enum" "struct" "actor" "protocol" "extension"
172172
"func" "init" "deinit" "subscript" "get" "set" "willSet" "didSet"
173173
"prefix" "postfix" "infix" "precedencegroup"
174174
"var" "let"
@@ -207,7 +207,7 @@ Return nil otherwise."
207207
(swift-mode:beginning-of-statement)
208208
(member
209209
(swift-mode:token:text (swift-mode:find-defun-keyword-simple))
210-
'("enum" "struct" "class" "protocol" "extension")))))
210+
'("enum" "struct" "actor" "class" "protocol" "extension")))))
211211

212212
(defun swift-mode:beginning-of-statement ()
213213
"Move backward to the beginning of a statement.
@@ -1418,7 +1418,7 @@ of ancestors."
14181418
(cond
14191419
((member keyword-text
14201420
'("typealias" "associatedtype" "precedencegroup" "func"
1421-
"class" "enum" "struct" "protocol" "extension"))
1421+
"class" "enum" "struct" "actor" "protocol" "extension"))
14221422
(swift-mode:forward-token))
14231423

14241424
((member keyword-text '("init" "deinit" "subscript"))

swift-mode-imenu.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Return found declarations in reverse order."
159159
;; Ignores the token otherwise.
160160
))
161161

162-
((member next-text '("struct" "protocol" "extension" "enum"))
162+
((member next-text '("struct" "protocol" "extension" "enum" "actor"))
163163
(setq last-class-token nil)
164164
(let ((declaration
165165
(swift-mode:scan-declarations:handle-struct-like next-token)))

swift-mode-indent.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,8 @@ This function is also used for close-curly-brace."
929929
'("for" "while" "repeat" "switch" "if" "else" "guard"
930930
"defer" "do" "catch"
931931
"get" "set" "willSet" "didSet" "func" "init" "subscript"
932-
"enum" "struct" "class" "extension" "prefix" "postfix" "infix"
933-
"precedencegroup"))
932+
"enum" "struct" "actor" "class" "extension"
933+
"prefix" "postfix" "infix" "precedencegroup"))
934934
(setq is-declaration-or-control-statement-body t)
935935
(goto-char (1+ pos)))
936936

@@ -1497,7 +1497,7 @@ It is a Generic parameter list if:
14971497
\;
14981498
{ } \( \) \[ \]
14991499
"true" "false"
1500-
"class" "struct" "enum" "extension" "func" "operator"
1500+
"class" "struct" "actor" "enum" "extension" "func" "operator"
15011501
"try" "try?" "try!"
15021502
"as" "as?" "as!"
15031503
"is"

swift-mode-lexer.el

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ Return nil otherwise."
480480

481481
;; Suppress implicit semicolon after declaration starters.
482482
((member (swift-mode:token:text previous-token)
483-
'("class" "struct" "protocol" "enum" "extension" "func"
483+
'("class" "struct" "actor" "protocol" "enum" "extension" "func"
484484
"typealias" "associatedtype" "precedencegroup" "operator"))
485485
nil)
486486

@@ -556,7 +556,7 @@ Return nil otherwise."
556556
;;
557557
;; `protocol' is handled by the next rule
558558
((member (swift-mode:token:text next-token)
559-
'("class" "struct" "enum" "extension" "func" "typealias"
559+
'("class" "struct" "actor" "enum" "extension" "func" "typealias"
560560
"associatedtype" "precedencegroup"))
561561
t)
562562

@@ -687,8 +687,8 @@ That is supertype declaration or type declaration of let or var."
687687
(member (swift-mode:token:text
688688
(swift-mode:backquote-identifier-if-after-dot
689689
(swift-mode:backward-token-simple)))
690-
'("class" "extension" "enum" "struct" "protocol" "typealias"
691-
"associatedtype"))))))
690+
'("class" "extension" "enum" "struct" "actor" "protocol"
691+
"typealias" "associatedtype"))))))
692692

693693
(defvar swift-mode:in-recursive-call-of-case-colon-p nil
694694
"Non-nil if `case-colon-p' is being evaluated.")
@@ -740,7 +740,7 @@ Return nil otherwise."
740740
(or (member (swift-mode:token:text (swift-mode:backward-token-simple))
741741
'("init" "subscript"))
742742
(member (swift-mode:token:text (swift-mode:backward-token-simple))
743-
'("typealias" "func" "enum" "struct" "class" "init")))))
743+
'("typealias" "func" "enum" "struct" "actor" "class" "init")))))
744744

745745
(defun swift-mode:fix-operator-type (token)
746746
"Return new operator token with proper token type.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ foo() {
197197
/*{*/struct Foo {
198198
}/*}*/
199199

200+
// /*[*/Actor declarations/*]*/
201+
202+
/*{*/actor Foo {
203+
}/*}*/
204+
200205
// /*[*/Class declarations/*]*/
201206

202207
/*{*/class Foo {
Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
((precedencegroup (identifier "precedenceGroup" 2661 2676) nil)
2-
(operator (identifier "*****" 2621 2626) nil)
3-
(operator (identifier "-----" 2581 2586) nil)
4-
(operator (identifier "+++++" 2542 2547) nil)
5-
(extension (identifier "FooClass" 2377 2385)
6-
((class (identifier "NestedClass1" 2417 2429)
7-
((class (identifier "NestedClass2" 2446 2458)
8-
((class (identifier "NestedClass3" 2479 2491) nil)))))))
9-
(protocol (identifier "FooProtocol" 2117 2128)
10-
((var (identifier "protocolProperty" 2144 2160) nil)
11-
(func (identifier "protocolMethod(a:b:)" 2186 2200) nil)
12-
(init (identifier "init(a:b:c:)" 2228 2232) nil)
13-
(subscript (identifier "subscript(_:bbb:)" 2263 2272) nil)
14-
(associatedtype (identifier "AssociatedType" 2344 2358) nil)))
15-
(struct (identifier "FooStruct" 2088 2097) nil)
16-
(enum (identifier "FooEnum2" 2023 2031)
17-
((case (identifier "case1" 2048 2053) nil)
18-
(case (identifier "case2" 2068 2073) nil)))
19-
(enum (identifier "FooEnum1" 1888 1896)
20-
((case (identifier "case1" 1935 1940) nil)
21-
(case (identifier "case2" 1966 1971) nil)
22-
(case (identifier "case3" 1995 2000) nil)))
23-
(class (identifier "FooClass" 530 538)
24-
((var (identifier "classVariable1" 607 621) nil)
25-
(class (identifier "final" 657 662) nil)
26-
(var (identifier "compuatedProperty" 685 702) nil)
27-
(var (identifier "observedProperty" 844 860) nil)
28-
(typealias (identifier "TypeAlias" 1008 1017) nil)
29-
(func (identifier "function1(aaa:_:ddd:eee:)" 1072 1081) nil)
30-
(func (identifier "function2()" 1269 1278) nil)
31-
(func (identifier "function3(a:)" 1352 1361) nil)
32-
(func (identifier "+(_:_:)" 1496 1497) nil)
33-
(subscript (identifier "subscript(_:bbb:)" 1658 1667) nil)
34-
(init (identifier "init(a:)" 1806 1810) nil)
35-
(init (identifier "init(b:)" 1833 1837) nil)
36-
(deinit (identifier "deinit" 1860 1866) nil)))
37-
(var (identifier "globalVariable2" 493 508) nil)
38-
(var (identifier "globalVariable1" 463 478) nil)
39-
(let (identifier "globalConstant2" 429 444) nil)
40-
(let (identifier "globalConstant1" 399 414) nil))
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)))
24+
(class (identifier "FooClass" 597 605)
25+
((var (identifier "classVariable1" 674 688) nil)
26+
(class (identifier "final" 724 729) nil)
27+
(var (identifier "compuatedProperty" 752 769) nil)
28+
(var (identifier "observedProperty" 911 927) nil)
29+
(typealias (identifier "TypeAlias" 1075 1084) nil)
30+
(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)))
38+
(var (identifier "globalVariable2" 560 575) nil)
39+
(var (identifier "globalVariable1" 530 545) nil)
40+
(let (identifier "globalConstant2" 496 511) nil)
41+
(let (identifier "globalConstant1" 466 481) nil))

test/swift-files/imenu/imenu.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import let FooModule3.importedConstant
99
import var FooModule3.importedVariable
1010
import func FooModule3.importedFunction
1111

12+
// Note that `import actor` is invalid (at least with Swift 5.5).
13+
1214
@AAA let globalConstant1 = 1,
1315
globalConstant2: Int = 2
1416
@AAA var globalVariable1 = 1,
@@ -92,6 +94,9 @@ enum FooEnum2: Int {
9294
struct FooStruct: AAA {
9395
}
9496

97+
actor FooActor: AAA {
98+
}
99+
95100
protocol FooProtocol: AAA {
96101
var protocolProperty: Int { get set}
97102
func protocolMethod(a: Int, b: Int) -> Int

test/swift-files/indent/declarations.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,25 @@ struct Foo
570570
> {
571571
}
572572

573+
// Actor declarations
574+
575+
@A
576+
fileprivate
577+
actor
578+
Foo<A, B>
579+
: Bar<A, B>,
580+
Baz<A, B>,
581+
AAA<A, B>
582+
where
583+
A:
584+
C,
585+
B =
586+
D<E> {
587+
func foo()
588+
func foo()
589+
}
590+
591+
573592
// Protocol declarations
574593

575594
protocol Foo {

test/swift-files/indent/identifiers.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ func foo() {
9494
foo(
9595
struct: 1
9696
)
97+
foo(
98+
actor: 1
99+
)
97100
foo(
98101
subscript: 1
99102
)

0 commit comments

Comments
 (0)