Skip to content

Commit f90e6e3

Browse files
committed
feat: Add Semantic modifier to parameter labels
1 parent e5d93e1 commit f90e6e3

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

Sources/LanguageServerProtocol/SupportTypes/SemanticTokenModifiers.swift

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public struct SemanticTokenModifiers: OptionSet, Hashable, Sendable {
4747
public static let fileScope = Self(rawValue: 1 << 19)
4848
public static let globalScope = Self(rawValue: 1 << 20)
4949

50+
/// Argument labels in function definitions and function calls
51+
///
52+
/// **(LSP Extension)**
53+
public static let argumentLabel = Self(rawValue: 1 << 21)
54+
5055
public var name: String? {
5156
switch self {
5257
case .declaration: return "declaration"
@@ -70,6 +75,7 @@ public struct SemanticTokenModifiers: OptionSet, Hashable, Sendable {
7075
case .classScope: return "classScope"
7176
case .fileScope: return "fileScope"
7277
case .globalScope: return "globalScope"
78+
case .argumentLabel: return "argumentLabel"
7379
default: return nil
7480
}
7581
}
@@ -98,5 +104,6 @@ public struct SemanticTokenModifiers: OptionSet, Hashable, Sendable {
98104
.classScope,
99105
.fileScope,
100106
.globalScope,
107+
.argumentLabel,
101108
]
102109
}

Sources/SourceKitLSP/Swift/SemanticTokens.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ extension SyntaxClassification {
150150
case .docLineComment, .docBlockComment:
151151
return (.comment, .documentation)
152152
case .argumentLabel:
153-
return (.function, [])
153+
return (.function, [.argumentLabel])
154154
}
155155
}
156156
}

Sources/SourceKitLSP/Swift/SyntaxHighlightingTokenParser.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct SyntaxHighlightingTokenParser {
164164
// therefore we don't use .parameter here (which LSP clients like
165165
// VSCode seem to interpret as variable identifiers, however
166166
// causing a 'wrong highlighting' e.g. of `x` in `f(x y: Int) {}`)
167-
return (.function, [.declaration])
167+
return (.function, [.declaration, .argumentLabel])
168168
case values.refVarStatic,
169169
values.refVarClass,
170170
values.refVarInstance:

Tests/SourceKitLSPTests/SemanticTokensTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ final class SemanticTokensTests: XCTestCase {
335335
expected: [
336336
TokenSpec(marker: "1️⃣", length: 4, kind: .keyword),
337337
TokenSpec(marker: "2️⃣", length: 1, kind: .identifier),
338-
TokenSpec(marker: "3️⃣", length: 1, kind: .function),
338+
TokenSpec(marker: "3️⃣", length: 1, kind: .function, modifiers: .argumentLabel),
339339
TokenSpec(marker: "4️⃣", length: 3, kind: .struct, modifiers: .defaultLibrary),
340340
TokenSpec(marker: "5️⃣", length: 1, kind: .identifier),
341341
TokenSpec(marker: "6️⃣", length: 6, kind: .struct, modifiers: .defaultLibrary),
@@ -905,7 +905,7 @@ final class SemanticTokensTests: XCTestCase {
905905
expected: [
906906
TokenSpec(marker: "1️⃣", length: 4, kind: .keyword),
907907
TokenSpec(marker: "2️⃣", length: 3, kind: .identifier),
908-
TokenSpec(marker: "3️⃣", length: 3, kind: .function),
908+
TokenSpec(marker: "3️⃣", length: 3, kind: .function, modifiers: .argumentLabel),
909909
TokenSpec(marker: "4️⃣", length: 3, kind: .struct, modifiers: .defaultLibrary),
910910
TokenSpec(marker: "5️⃣", length: 3, kind: .function),
911911
TokenSpec(marker: "6️⃣", length: 3, kind: .function),

0 commit comments

Comments
 (0)