Skip to content

Commit cb078c2

Browse files
committed
Add semantic highlighting for function parameter labels
1 parent e6cf723 commit cb078c2

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Sources/SourceKitLSP/Swift/SemanticTokens.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ extension SyntaxClassification {
155155
return (.comment, [])
156156
case .docLineComment, .docBlockComment:
157157
return (.comment, .documentation)
158+
case .parameterLabel:
159+
return (.function, [])
158160
}
159161
}
160162
}

Tests/SourceKitLSPTests/SemanticTokensTests.swift

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ final class SemanticTokensTests: XCTestCase {
430430
[
431431
Token(line: 0, utf16index: 0, length: 4, kind: .keyword),
432432
Token(line: 0, utf16index: 5, length: 1, kind: .identifier),
433-
Token(line: 0, utf16index: 7, length: 1, kind: .identifier),
433+
Token(line: 0, utf16index: 7, length: 1, kind: .function),
434434
Token(line: 0, utf16index: 10, length: 3, kind: .struct, modifiers: .defaultLibrary),
435435
Token(line: 0, utf16index: 17, length: 1, kind: .identifier),
436436
Token(line: 0, utf16index: 20, length: 6, kind: .struct, modifiers: .defaultLibrary),
@@ -833,13 +833,34 @@ final class SemanticTokensTests: XCTestCase {
833833
Token(line: 2, utf16index: 7, length: 8, kind: .identifier),
834834
Token(line: 4, utf16index: 0, length: 4, kind: .keyword),
835835
Token(line: 4, utf16index: 5, length: 1, kind: .identifier),
836-
Token(line: 5, utf16index: 4, length: 1, kind: .identifier),
836+
Token(line: 5, utf16index: 4, length: 1, kind: .function),
837837
Token(line: 5, utf16index: 7, length: 7, kind: .actor),
838-
Token(line: 6, utf16index: 4, length: 1, kind: .identifier),
838+
Token(line: 6, utf16index: 4, length: 1, kind: .function),
839839
Token(line: 6, utf16index: 7, length: 8, kind: .struct),
840840
]
841841
)
842842
}
843+
844+
func testArgumentLabels() async throws {
845+
let text = """
846+
func foo(arg: Int) {}
847+
foo(arg: 1)
848+
"""
849+
850+
let tokens = try await openAndPerformSemanticTokensRequest(text: text)
851+
XCTAssertEqual(
852+
tokens,
853+
[
854+
Token(line: 0, utf16index: 0, length: 4, kind: .keyword),
855+
Token(line: 0, utf16index: 5, length: 3, kind: .identifier),
856+
Token(line: 0, utf16index: 9, length: 3, kind: .function),
857+
Token(line: 0, utf16index: 14, length: 3, kind: .struct, modifiers: .defaultLibrary),
858+
Token(line: 1, utf16index: 0, length: 3, kind: .function),
859+
Token(line: 1, utf16index: 4, length: 3, kind: .function),
860+
Token(line: 1, utf16index: 9, length: 1, kind: .number),
861+
]
862+
)
863+
}
843864
}
844865

845866
extension Token {

0 commit comments

Comments
 (0)