From f90e6e339449503657b1865392a755c26f696b52 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Tue, 2 Jul 2024 09:10:19 -0300 Subject: [PATCH] feat: Add Semantic modifier to parameter labels --- .../SupportTypes/SemanticTokenModifiers.swift | 7 +++++++ Sources/SourceKitLSP/Swift/SemanticTokens.swift | 2 +- .../SourceKitLSP/Swift/SyntaxHighlightingTokenParser.swift | 2 +- Tests/SourceKitLSPTests/SemanticTokensTests.swift | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/LanguageServerProtocol/SupportTypes/SemanticTokenModifiers.swift b/Sources/LanguageServerProtocol/SupportTypes/SemanticTokenModifiers.swift index b623e52d1..2a36c8807 100644 --- a/Sources/LanguageServerProtocol/SupportTypes/SemanticTokenModifiers.swift +++ b/Sources/LanguageServerProtocol/SupportTypes/SemanticTokenModifiers.swift @@ -47,6 +47,11 @@ public struct SemanticTokenModifiers: OptionSet, Hashable, Sendable { public static let fileScope = Self(rawValue: 1 << 19) public static let globalScope = Self(rawValue: 1 << 20) + /// Argument labels in function definitions and function calls + /// + /// **(LSP Extension)** + public static let argumentLabel = Self(rawValue: 1 << 21) + public var name: String? { switch self { case .declaration: return "declaration" @@ -70,6 +75,7 @@ public struct SemanticTokenModifiers: OptionSet, Hashable, Sendable { case .classScope: return "classScope" case .fileScope: return "fileScope" case .globalScope: return "globalScope" + case .argumentLabel: return "argumentLabel" default: return nil } } @@ -98,5 +104,6 @@ public struct SemanticTokenModifiers: OptionSet, Hashable, Sendable { .classScope, .fileScope, .globalScope, + .argumentLabel, ] } diff --git a/Sources/SourceKitLSP/Swift/SemanticTokens.swift b/Sources/SourceKitLSP/Swift/SemanticTokens.swift index 2f3dae96d..4c90d4734 100644 --- a/Sources/SourceKitLSP/Swift/SemanticTokens.swift +++ b/Sources/SourceKitLSP/Swift/SemanticTokens.swift @@ -150,7 +150,7 @@ extension SyntaxClassification { case .docLineComment, .docBlockComment: return (.comment, .documentation) case .argumentLabel: - return (.function, []) + return (.function, [.argumentLabel]) } } } diff --git a/Sources/SourceKitLSP/Swift/SyntaxHighlightingTokenParser.swift b/Sources/SourceKitLSP/Swift/SyntaxHighlightingTokenParser.swift index 71a358b25..6b3bb3078 100644 --- a/Sources/SourceKitLSP/Swift/SyntaxHighlightingTokenParser.swift +++ b/Sources/SourceKitLSP/Swift/SyntaxHighlightingTokenParser.swift @@ -164,7 +164,7 @@ struct SyntaxHighlightingTokenParser { // therefore we don't use .parameter here (which LSP clients like // VSCode seem to interpret as variable identifiers, however // causing a 'wrong highlighting' e.g. of `x` in `f(x y: Int) {}`) - return (.function, [.declaration]) + return (.function, [.declaration, .argumentLabel]) case values.refVarStatic, values.refVarClass, values.refVarInstance: diff --git a/Tests/SourceKitLSPTests/SemanticTokensTests.swift b/Tests/SourceKitLSPTests/SemanticTokensTests.swift index ae8292add..030cb2474 100644 --- a/Tests/SourceKitLSPTests/SemanticTokensTests.swift +++ b/Tests/SourceKitLSPTests/SemanticTokensTests.swift @@ -335,7 +335,7 @@ final class SemanticTokensTests: XCTestCase { expected: [ TokenSpec(marker: "1️⃣", length: 4, kind: .keyword), TokenSpec(marker: "2️⃣", length: 1, kind: .identifier), - TokenSpec(marker: "3️⃣", length: 1, kind: .function), + TokenSpec(marker: "3️⃣", length: 1, kind: .function, modifiers: .argumentLabel), TokenSpec(marker: "4️⃣", length: 3, kind: .struct, modifiers: .defaultLibrary), TokenSpec(marker: "5️⃣", length: 1, kind: .identifier), TokenSpec(marker: "6️⃣", length: 6, kind: .struct, modifiers: .defaultLibrary), @@ -905,7 +905,7 @@ final class SemanticTokensTests: XCTestCase { expected: [ TokenSpec(marker: "1️⃣", length: 4, kind: .keyword), TokenSpec(marker: "2️⃣", length: 3, kind: .identifier), - TokenSpec(marker: "3️⃣", length: 3, kind: .function), + TokenSpec(marker: "3️⃣", length: 3, kind: .function, modifiers: .argumentLabel), TokenSpec(marker: "4️⃣", length: 3, kind: .struct, modifiers: .defaultLibrary), TokenSpec(marker: "5️⃣", length: 3, kind: .function), TokenSpec(marker: "6️⃣", length: 3, kind: .function),