diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift b/Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift index ec659cd..a87ebaa 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift @@ -155,8 +155,19 @@ public enum InsertTextFormat: Int, Codable, Hashable, Sendable { case snippet = 2 } +public struct CompletionItemLabelDetails: Codable, Hashable, Sendable { + public let detail: String? + public let description: String? + + public init(detail: String? = nil, description: String? = nil) { + self.detail = detail + self.description = description + } +} + public struct CompletionItem: Codable, Hashable, Sendable { public let label: String + public let labelDetails: CompletionItemLabelDetails? public let kind: CompletionItemKind? public let detail: String? public let documentation: TwoTypeOption? @@ -174,6 +185,7 @@ public struct CompletionItem: Codable, Hashable, Sendable { public init( label: String, + labelDetails: CompletionItemLabelDetails? = nil, kind: CompletionItemKind? = nil, detail: String? = nil, documentation: TwoTypeOption? = nil, @@ -190,6 +202,7 @@ public struct CompletionItem: Codable, Hashable, Sendable { data: LSPAny? = nil ) { self.label = label + self.labelDetails = labelDetails self.kind = kind self.detail = detail self.documentation = documentation diff --git a/Tests/LanguageServerProtocolTests/CompletionItemTests.swift b/Tests/LanguageServerProtocolTests/CompletionItemTests.swift new file mode 100644 index 0000000..baf9a71 --- /dev/null +++ b/Tests/LanguageServerProtocolTests/CompletionItemTests.swift @@ -0,0 +1,15 @@ +import XCTest +import LanguageServerProtocol + +final class CompletionItemTests: XCTestCase { + func testDecodingLabelDetails() throws { + // a textDocument/completion response item shaped per the LSP 3.17 spec + let json = """ + {"label":"map","labelDetails":{"detail":"(transform: (Element) -> T)","description":"[T]"},"kind":3,"insertText":"map"} + """ + let data = try XCTUnwrap(json.data(using: .utf8)) + let item = try JSONDecoder().decode(CompletionItem.self, from: data) + + XCTAssertEqual(item.labelDetails, CompletionItemLabelDetails(detail: "(transform: (Element) -> T)", description: "[T]")) + } +}