Skip to content

Commit 3d40b5d

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

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

Sources/LanguageServerProtocol/SupportTypes/SemanticTokenModifiers.swift

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ 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+
// The following are our LSP extensions
51+
public static let parameterLabel = Self(rawValue: 1 << 21)
52+
5053
public var name: String? {
5154
switch self {
5255
case .declaration: return "declaration"
@@ -70,6 +73,7 @@ public struct SemanticTokenModifiers: OptionSet, Hashable, Sendable {
7073
case .classScope: return "classScope"
7174
case .fileScope: return "fileScope"
7275
case .globalScope: return "globalScope"
76+
case .parameterLabel: return "parameterLabel"
7377
default: return nil
7478
}
7579
}
@@ -98,5 +102,6 @@ public struct SemanticTokenModifiers: OptionSet, Hashable, Sendable {
98102
.classScope,
99103
.fileScope,
100104
.globalScope,
105+
.parameterLabel,
101106
]
102107
}

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, [.parameterLabel])
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, .parameterLabel])
168168
case values.refVarStatic,
169169
values.refVarClass,
170170
values.refVarInstance:

Tests/SourceKitLSPTests/SemanticTokensTests.swift

+1-1
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: .parameterLabel),
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),

0 commit comments

Comments
 (0)