Skip to content

Commit f555a8b

Browse files
authored
Merge pull request #758 from ahoppen/ahoppen/actor-highlighting
Highlight references to actors like references to classes
2 parents 869fd0a + 7c15ba8 commit f555a8b

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

Sources/SourceKitD/sourcekitd_uids.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ public struct sourcekitd_values {
267267
public let ref_var_local: sourcekitd_uid_t
268268
public let decl_var_parameter: sourcekitd_uid_t
269269
public let decl_module: sourcekitd_uid_t
270+
public let decl_actor: sourcekitd_uid_t
270271
public let decl_class: sourcekitd_uid_t
272+
public let ref_actor: sourcekitd_uid_t
271273
public let ref_class: sourcekitd_uid_t
272274
public let decl_struct: sourcekitd_uid_t
273275
public let ref_struct: sourcekitd_uid_t
@@ -371,6 +373,8 @@ public struct sourcekitd_values {
371373
ref_var_local = api.uid_get_from_cstr("source.lang.swift.ref.var.local")!
372374
decl_var_parameter = api.uid_get_from_cstr("source.lang.swift.decl.var.parameter")!
373375
decl_module = api.uid_get_from_cstr("source.lang.swift.decl.module")!
376+
decl_actor = api.uid_get_from_cstr("source.lang.swift.decl.actor")!
377+
ref_actor = api.uid_get_from_cstr("source.lang.swift.ref.actor")!
374378
decl_class = api.uid_get_from_cstr("source.lang.swift.decl.class")!
375379
ref_class = api.uid_get_from_cstr("source.lang.swift.ref.class")!
376380
decl_struct = api.uid_get_from_cstr("source.lang.swift.decl.struct")!

Sources/SourceKitLSP/Swift/SyntaxHighlightingToken.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public struct SyntaxHighlightingToken: Hashable {
6262
public enum Kind: UInt32, CaseIterable, Hashable {
6363
case namespace = 0
6464
case type
65+
case actor
6566
case `class`
6667
case `enum`
6768
case interface
@@ -91,6 +92,7 @@ public struct SyntaxHighlightingToken: Hashable {
9192
switch self {
9293
case .namespace: return "namespace"
9394
case .type: return "type"
95+
case .actor: return "class" // LSP doesn’t know about actors. Display actors as classes.
9496
case .class: return "class"
9597
case .enum: return "enum"
9698
case .interface: return "interface"

Sources/SourceKitLSP/Swift/SyntaxHighlightingTokenParser.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ struct SyntaxHighlightingTokenParser {
8383
return (.class, [.declaration])
8484
case values.ref_class:
8585
return (.class, [])
86+
case values.decl_actor:
87+
return (.actor, [.declaration])
88+
case values.ref_actor:
89+
return (.actor, [])
8690
case values.decl_struct:
8791
return (.struct, [.declaration])
8892
case values.ref_struct:

Tests/SourceKitLSPTests/SemanticTokensTests.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,33 @@ final class SemanticTokensTests: XCTestCase {
743743
Token(line: 1, utf16index: 8, length: 7, kind: .variable),
744744
])
745745
}
746-
747746

747+
func testActor() {
748+
let text = """
749+
actor MyActor {}
750+
751+
struct MyStruct {}
752+
753+
func t(
754+
x: MyActor,
755+
y: MyStruct
756+
) {}
757+
"""
758+
759+
let tokens = openAndPerformSemanticTokensRequest(text: text)
760+
XCTAssertEqual(tokens, [
761+
Token(line: 0, utf16index: 0, length: 5, kind: .keyword),
762+
Token(line: 0, utf16index: 6, length: 7, kind: .identifier),
763+
Token(line: 2, utf16index: 0, length: 6, kind: .keyword),
764+
Token(line: 2, utf16index: 7, length: 8, kind: .identifier),
765+
Token(line: 4, utf16index: 0, length: 4, kind: .keyword),
766+
Token(line: 4, utf16index: 5, length: 1, kind: .identifier),
767+
Token(line: 5, utf16index: 4, length: 1, kind: .identifier),
768+
Token(line: 5, utf16index: 7, length: 7, kind: .actor),
769+
Token(line: 6, utf16index: 4, length: 1, kind: .identifier),
770+
Token(line: 6, utf16index: 7, length: 8, kind: .struct)
771+
])
772+
}
748773
}
749774

750775
extension Token {

0 commit comments

Comments
 (0)