Skip to content

Commit 0d83557

Browse files
committed
Provide semantic highlighting for operators in declarations
Adopts swiftlang/swift#60210 Resolves #595 rdar://97961816
1 parent 69de681 commit 0d83557

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Sources/SourceKitD/sourcekitd_uids.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ public struct sourcekitd_values {
285285
public let syntaxtype_doccomment: sourcekitd_uid_t
286286
public let syntaxtype_doccomment_field: sourcekitd_uid_t
287287
public let syntaxtype_keyword: sourcekitd_uid_t
288+
public let syntaxtype_operator: sourcekitd_uid_t
288289
public let syntaxtype_number: sourcekitd_uid_t
289290
public let syntaxtype_string: sourcekitd_uid_t
290291
public let syntaxtype_string_interpolation_anchor: sourcekitd_uid_t
@@ -388,6 +389,7 @@ public struct sourcekitd_values {
388389
syntaxtype_doccomment = api.uid_get_from_cstr("source.lang.swift.syntaxtype.doccomment")!
389390
syntaxtype_doccomment_field = api.uid_get_from_cstr("source.lang.swift.syntaxtype.doccomment.field")!
390391
syntaxtype_keyword = api.uid_get_from_cstr("source.lang.swift.syntaxtype.keyword")!
392+
syntaxtype_operator = api.uid_get_from_cstr("source.lang.swift.syntaxtype.operator")!
391393
syntaxtype_number = api.uid_get_from_cstr("source.lang.swift.syntaxtype.number")!
392394
syntaxtype_string = api.uid_get_from_cstr("source.lang.swift.syntaxtype.string")!
393395
syntaxtype_string_interpolation_anchor = api.uid_get_from_cstr("source.lang.swift.syntaxtype.string_interpolation_anchor")!

Sources/SourceKitLSP/Swift/SyntaxHighlightingTokenParser.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ struct SyntaxHighlightingTokenParser {
127127
values.ref_function_destructor,
128128
values.ref_function_subscript:
129129
return (.method, [])
130+
case values.syntaxtype_operator:
131+
return (.operator, [])
130132
case values.decl_function_operator_prefix,
131133
values.decl_function_operator_postfix,
132134
values.decl_function_operator_infix:

Tests/SourceKitLSPTests/SemanticTokensTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ final class SemanticTokensTests: XCTestCase {
348348
Token(line: 3, utf16index: 0, length: 3, kind: .keyword),
349349
Token(line: 3, utf16index: 4, length: 1, kind: .identifier),
350350
Token(line: 3, utf16index: 8, length: 1, kind: .variable),
351+
Token(line: 3, utf16index: 10, length: 1, kind: .operator),
351352
Token(line: 3, utf16index: 12, length: 1, kind: .variable),
352353
// func a() {}
353354
Token(line: 5, utf16index: 0, length: 4, kind: .keyword),
@@ -488,6 +489,20 @@ final class SemanticTokensTests: XCTestCase {
488489
])
489490
}
490491

492+
493+
func testOperatorDeclaration() {
494+
let text = """
495+
infix operator ?= :ComparisonPrecedence
496+
"""
497+
let tokens = openAndPerformSemanticTokensRequest(text: text)
498+
XCTAssertEqual(tokens, [
499+
Token(line: 0, utf16index: 0, length: 5, kind: .modifier),
500+
Token(line: 0, utf16index: 6, length: 8, kind: .keyword),
501+
Token(line: 0, utf16index: 15, length: 2, kind: .operator),
502+
Token(line: 0, utf16index: 19, length: 20, kind: .identifier),
503+
])
504+
}
505+
491506
func testEmptyEdit() {
492507
let text = """
493508
let x: String = "test"

0 commit comments

Comments
 (0)