Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Semantic modifier to parameter labels #1542

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
}
Expand Down Expand Up @@ -98,5 +104,6 @@ public struct SemanticTokenModifiers: OptionSet, Hashable, Sendable {
.classScope,
.fileScope,
.globalScope,
.argumentLabel,
]
}
2 changes: 1 addition & 1 deletion Sources/SourceKitLSP/Swift/SemanticTokens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ extension SyntaxClassification {
case .docLineComment, .docBlockComment:
return (.comment, .documentation)
case .argumentLabel:
return (.function, [])
return (.function, [.argumentLabel])
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Tests/SourceKitLSPTests/SemanticTokensTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t this token also have a .argumentLabel modifier?

Also in case you see the test as being skipped on your machine, you need to set SOURCEKIT_TOOLCHAIN_PATH to a Swift Development Snapshot as described here: https://github.com/swiftlang/sourcekit-lsp/blob/main/CONTRIBUTING.md#selecting-a-toolchain

Expand Down