Skip to content

Commit 467f56c

Browse files
committed
Add syntax highlighting for parameter labels
1 parent cf49214 commit 467f56c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Sources/SwiftIDEUtils/SyntaxClassification.swift

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public enum SyntaxClassification {
4747
case stringLiteral
4848
/// An identifier referring to a type.
4949
case type
50+
/// The label of a function parameter or a function call argument.
51+
case parameterLabel
5052
}
5153

5254
extension SyntaxClassification {
@@ -83,6 +85,10 @@ extension SyntaxClassification {
8385
return (.keyword, false)
8486
case \SimpleTypeIdentifierSyntax.name:
8587
return (.type, false)
88+
case \FunctionParameterSyntax.firstName:
89+
return (.parameterLabel, false)
90+
case \LabeledExprSyntax.label:
91+
return (.parameterLabel, false)
8692
default:
8793
return nil
8894
}

Tests/SwiftIDEUtilsTest/ClassificationTests.swift

+25
Original file line numberDiff line numberDiff line change
@@ -577,4 +577,29 @@ public class ClassificationTests: XCTestCase {
577577
]
578578
)
579579
}
580+
581+
public func testParameterLabel() {
582+
assertClassification(
583+
"""
584+
func foo(arg: Int) {}
585+
""",
586+
expected: [
587+
ClassificationSpec(source: "func", kind: .keyword),
588+
ClassificationSpec(source: "foo", kind: .identifier),
589+
ClassificationSpec(source: "arg", kind: .parameterLabel),
590+
ClassificationSpec(source: "Int", kind: .type),
591+
]
592+
)
593+
594+
assertClassification(
595+
"""
596+
foo(arg: 1)
597+
""",
598+
expected: [
599+
ClassificationSpec(source: "foo", kind: .identifier),
600+
ClassificationSpec(source: "arg", kind: .parameterLabel),
601+
ClassificationSpec(source: "1", kind: .integerLiteral),
602+
]
603+
)
604+
}
580605
}

0 commit comments

Comments
 (0)