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
Original file line number Diff line number Diff line change
Expand Up @@ -175,45 +175,4 @@ public struct SourceKitSourceItemData: LSPAnyCodable, Codable {
self.outputPath = outputPath
self.copyDestinations = copyDestinations
}

public init?(fromLSPDictionary dictionary: [String: LanguageServerProtocol.LSPAny]) {
if case .string(let language) = dictionary[CodingKeys.language.stringValue] {
self.language = Language(rawValue: language)
}
if case .string(let rawKind) = dictionary[CodingKeys.kind.stringValue] {
self.kind = SourceKitSourceItemKind(rawValue: rawKind)
}
// Backwards compatibility for isHeader
if case .bool(let isHeader) = dictionary["isHeader"], isHeader {
self.kind = .header
}
if case .string(let outputFilePath) = dictionary[CodingKeys.outputPath.stringValue] {
self.outputPath = outputFilePath
}
if case .array(let copyDestinations) = dictionary[CodingKeys.copyDestinations.stringValue] {
self.copyDestinations = copyDestinations.compactMap { entry in
guard case .string(let copyDestination) = entry else {
return nil
}
return try? DocumentURI(string: copyDestination)
}
}
}

public func encodeToLSPAny() -> LanguageServerProtocol.LSPAny {
var result: [String: LSPAny] = [:]
if let language {
result[CodingKeys.language.stringValue] = .string(language.rawValue)
}
if let kind {
result[CodingKeys.kind.stringValue] = .string(kind.rawValue)
}
if let outputPath {
result[CodingKeys.outputPath.stringValue] = .string(outputPath)
}
if let copyDestinations {
result[CodingKeys.copyDestinations.stringValue] = .array(copyDestinations.map { .string($0.stringValue) })
}
return .dictionary(result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,48 +312,4 @@ public struct SourceKitInitializeBuildResponseData: LSPAnyCodable, Codable, Send
self.sourceKitOptionsProvider = sourceKitOptionsProvider
self.watchers = watchers
}

public init?(fromLSPDictionary dictionary: [String: LanguageServerProtocol.LSPAny]) {
if case .string(let indexDatabasePath) = dictionary[CodingKeys.indexDatabasePath.stringValue] {
self.indexDatabasePath = indexDatabasePath
}
if case .string(let indexStorePath) = dictionary[CodingKeys.indexStorePath.stringValue] {
self.indexStorePath = indexStorePath
}
if case .bool(let outputPathsProvider) = dictionary[CodingKeys.outputPathsProvider.stringValue] {
self.outputPathsProvider = outputPathsProvider
}
if case .bool(let prepareProvider) = dictionary[CodingKeys.prepareProvider.stringValue] {
self.prepareProvider = prepareProvider
}
if case .bool(let sourceKitOptionsProvider) = dictionary[CodingKeys.sourceKitOptionsProvider.stringValue] {
self.sourceKitOptionsProvider = sourceKitOptionsProvider
}
if let watchers = dictionary[CodingKeys.watchers.stringValue] {
self.watchers = [FileSystemWatcher](fromLSPArray: watchers)
}
}

public func encodeToLSPAny() -> LanguageServerProtocol.LSPAny {
var result: [String: LSPAny] = [:]
if let indexDatabasePath {
result[CodingKeys.indexDatabasePath.stringValue] = .string(indexDatabasePath)
}
if let indexStorePath {
result[CodingKeys.indexStorePath.stringValue] = .string(indexStorePath)
}
if let outputPathsProvider {
result[CodingKeys.outputPathsProvider.stringValue] = .bool(outputPathsProvider)
}
if let prepareProvider {
result[CodingKeys.prepareProvider.stringValue] = .bool(prepareProvider)
}
if let sourceKitOptionsProvider {
result[CodingKeys.sourceKitOptionsProvider.stringValue] = .bool(sourceKitOptionsProvider)
}
if let watchers {
result[CodingKeys.watchers.stringValue] = watchers.encodeToLSPAny()
}
return .dictionary(result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,11 @@ public struct TestTaskData: Codable, Hashable, Sendable {

/// If `data` contains a string value for the `workDoneProgressTitle` key, then the task's message will be displayed in
/// the client as a work done progress with that title.
public struct WorkDoneProgressTask: LSPAnyCodable {
public struct WorkDoneProgressTask: LSPAnyCodable, Codable {
/// The title with which the work done progress should be created in the client.
public let title: String

public init(title: String) {
self.title = title
}

public init?(fromLSPDictionary dictionary: [String: LanguageServerProtocol.LSPAny]) {
guard case .string(let title) = dictionary["workDoneProgressTitle"] else {
return nil
}
self.title = title
}

public func encodeToLSPAny() -> LanguageServerProtocol.LSPAny {
return .dictionary([
"workDoneProgressTitle": .string(title)
])
}
}
14 changes: 0 additions & 14 deletions Sources/BuildServerProtocol/SupportTypes/BuildTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,4 @@ public struct SourceKitBuildTarget: LSPAnyCodable, Codable {
public init(toolchain: URI? = nil) {
self.toolchain = toolchain
}

public init(fromLSPDictionary dictionary: [String: LanguageServerProtocol.LSPAny]) {
if case .string(let toolchain) = dictionary[CodingKeys.toolchain.stringValue] {
self.toolchain = try? URI(string: toolchain)
}
}

public func encodeToLSPAny() -> LanguageServerProtocol.LSPAny {
var result: [String: LSPAny] = [:]
if let toolchain {
result[CodingKeys.toolchain.stringValue] = .string(toolchain.stringValue)
}
return .dictionary(result)
}
}
1 change: 1 addition & 0 deletions Sources/LanguageServerProtocol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ add_library(LanguageServerProtocol
SupportTypes/LocationLink.swift
SupportTypes/LocationsOrLocationLinksResponse.swift
SupportTypes/LSPAny.swift
SupportTypes/LSPAny+Coding.swift
SupportTypes/MarkupContent.swift
SupportTypes/NotebookCellTextDocumentFilter.swift
SupportTypes/NotebookDocument.swift
Expand Down
1 change: 1 addition & 0 deletions Sources/LanguageServerProtocol/PositionRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public struct PositionRangeArray: CustomCodableWrapper {
}
}

// TODO: Remove this extension after every clients migrated to `@CustomCodable<PositionRange>`.
extension Range: LSPAnyCodable where Bound == Position {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This extension is only used from sourcekit-lsp repo now. They should use @CustomCodable<PositionRange> for the properties instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we replace the TODO then?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd like to keep this PR independent from sourcekit-lsp changes.
I will remove this after sourcekit-lsp PR is merged

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍🏽

public init?(fromLSPDictionary dictionary: [String: LSPAny]) {
guard case .dictionary(let start)? = dictionary[PositionRange.CodingKeys.lowerBound.stringValue],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct CodeActionRequest: TextDocumentRequest, Hashable {
public var context: CodeActionContext

public init(range: Range<Position>, context: CodeActionContext, textDocument: TextDocumentIdentifier) {
self._range = CustomCodable<PositionRange>(wrappedValue: range)
self.range = range
self.context = context
self.textDocument = textDocument
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct ColorPresentationRequest: TextDocumentRequest, Hashable {
public init(textDocument: TextDocumentIdentifier, color: Color, range: Range<Position>) {
self.textDocument = textDocument
self.color = color
self._range = CustomCodable<PositionRange>(wrappedValue: range)
self.range = range

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These are drive-by changes. We don't need to initialize the underlying storage.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct ColorInformation: ResponseType, Hashable {
public var color: Color

public init(range: Range<Position>, color: Color) {
self._range = CustomCodable<PositionRange>(wrappedValue: range)
self.range = range
self.color = color
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public struct DocumentHighlight: ResponseType, Hashable {
public var kind: DocumentHighlightKind?

public init(range: Range<Position>, kind: DocumentHighlightKind?) {
self._range = CustomCodable<PositionRange>(wrappedValue: range)
self.range = range
self.kind = kind
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public struct DocumentSymbol: Hashable, Codable, Sendable {
self.kind = kind
self.tags = tags
self.deprecated = deprecated
self._range = CustomCodable<PositionRange>(wrappedValue: range)
self._selectionRange = CustomCodable<PositionRange>(wrappedValue: selectionRange)
self.range = range
self.selectionRange = selectionRange
self.children = children
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public struct HoverResponse: ResponseType, Hashable {

public init(contents: HoverResponseContents, range: Range<Position>?) {
self.contents = contents
self._range = CustomCodable(wrappedValue: range)
self.range = range
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public struct InlayHintRequest: TextDocumentRequest, Hashable {
range: Range<Position>? = nil
) {
self.textDocument = textDocument
self._range = CustomCodable(wrappedValue: range)
self.range = range
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public struct Diagnostic: Codable, Hashable, Sendable {
data: LSPAny? = nil,
codeActions: [CodeAction]? = nil
) {
self._range = CustomCodable<PositionRange>(wrappedValue: range)
self.range = range
self.severity = severity
self.code = code
self.codeDescription = codeDescription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,7 @@ public struct FileSystemWatcher: Codable, Hashable, Sendable {
}
}

extension FileSystemWatcher: LSPAnyCodable {
public init?(fromLSPDictionary dictionary: [String: LSPAny]) {
guard let globPatternAny = dictionary[CodingKeys.globPattern.stringValue] else { return nil }
guard case .string(let globPattern) = globPatternAny else { return nil }
self.globPattern = globPattern

guard let kindValue = dictionary[CodingKeys.kind.stringValue] else {
self.kind = nil
return
}

switch kindValue {
case .null: self.kind = nil
case .int(let value): self.kind = WatchKind(rawValue: value)
default: return nil
}
}

public func encodeToLSPAny() -> LSPAny {
var encoded = [CodingKeys.globPattern.stringValue: LSPAny.string(globPattern)]
if let kind = kind {
encoded[CodingKeys.kind.stringValue] = LSPAny.int(kind.rawValue)
}
return .dictionary(encoded)
}
}
extension FileSystemWatcher: LSPAnyCodable {}

/// The type of file event a watcher is interested in.
///
Expand Down
Loading
Loading