Skip to content
Merged
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
13 changes: 13 additions & 0 deletions Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, MarkupContent>?
Expand All @@ -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<String, MarkupContent>? = nil,
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions Tests/LanguageServerProtocolTests/CompletionItemTests.swift
Original file line number Diff line number Diff line change
@@ -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]"))
}
}