diff --git a/.swift-format.json b/.swift-format.json new file mode 100644 index 0000000..5fd4073 --- /dev/null +++ b/.swift-format.json @@ -0,0 +1,7 @@ +{ + "indentation" : { + "tabs" : 1 + }, + "tabWidth" : 4, + "version" : 1 +} diff --git a/Sources/LanguageServerProtocol/Additions/AsyncStreamPolyfill.swift b/Sources/LanguageServerProtocol/Additions/AsyncStreamPolyfill.swift index 4837897..a2f76a4 100644 --- a/Sources/LanguageServerProtocol/Additions/AsyncStreamPolyfill.swift +++ b/Sources/LanguageServerProtocol/Additions/AsyncStreamPolyfill.swift @@ -2,45 +2,50 @@ import Foundation #if compiler(<5.9) -// @available(SwiftStdlib 5.1, *) -extension AsyncStream { - /// Initializes a new ``AsyncStream`` and an ``AsyncStream/Continuation``. - /// - /// - Parameters: - /// - elementType: The element type of the stream. - /// - limit: The buffering policy that the stream should use. - /// - Returns: A tuple containing the stream and its continuation. The continuation should be passed to the - /// producer while the stream should be passed to the consumer. - // @backDeployed(before: SwiftStdlib 5.9) - static func makeStream( - of elementType: Element.Type = Element.self, - bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded - ) -> (stream: AsyncStream, continuation: AsyncStream.Continuation) { - var continuation: AsyncStream.Continuation! - let stream = AsyncStream(bufferingPolicy: limit) { continuation = $0 } - return (stream: stream, continuation: continuation!) + // @available(SwiftStdlib 5.1, *) + extension AsyncStream { + /// Initializes a new ``AsyncStream`` and an ``AsyncStream/Continuation``. + /// + /// - Parameters: + /// - elementType: The element type of the stream. + /// - limit: The buffering policy that the stream should use. + /// - Returns: A tuple containing the stream and its continuation. The continuation should be passed to the + /// producer while the stream should be passed to the consumer. + // @backDeployed(before: SwiftStdlib 5.9) + static func makeStream( + of elementType: Element.Type = Element.self, + bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded + ) -> (stream: AsyncStream, continuation: AsyncStream.Continuation) { + var continuation: AsyncStream.Continuation! + let stream = AsyncStream(bufferingPolicy: limit) { continuation = $0 } + return (stream: stream, continuation: continuation!) + } } -} -// @available(SwiftStdlib 5.1, *) -extension AsyncThrowingStream { - /// Initializes a new ``AsyncThrowingStream`` and an ``AsyncThrowingStream/Continuation``. - /// - /// - Parameters: - /// - elementType: The element type of the stream. - /// - failureType: The failure type of the stream. - /// - limit: The buffering policy that the stream should use. - /// - Returns: A tuple containing the stream and its continuation. The continuation should be passed to the - /// producer while the stream should be passed to the consumer. - // @backDeployed(before: SwiftStdlib 5.9) - static func makeStream( - of elementType: Element.Type = Element.self, - throwing failureType: Failure.Type = Failure.self, - bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded - ) -> (stream: AsyncThrowingStream, continuation: AsyncThrowingStream.Continuation) where Failure == Error { - var continuation: AsyncThrowingStream.Continuation! - let stream = AsyncThrowingStream(bufferingPolicy: limit) { continuation = $0 } - return (stream: stream, continuation: continuation!) + // @available(SwiftStdlib 5.1, *) + extension AsyncThrowingStream { + /// Initializes a new ``AsyncThrowingStream`` and an ``AsyncThrowingStream/Continuation``. + /// + /// - Parameters: + /// - elementType: The element type of the stream. + /// - failureType: The failure type of the stream. + /// - limit: The buffering policy that the stream should use. + /// - Returns: A tuple containing the stream and its continuation. The continuation should be passed to the + /// producer while the stream should be passed to the consumer. + // @backDeployed(before: SwiftStdlib 5.9) + static func makeStream( + of elementType: Element.Type = Element.self, + throwing failureType: Failure.Type = Failure.self, + bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded + ) -> ( + stream: AsyncThrowingStream, + continuation: AsyncThrowingStream.Continuation + ) where Failure == Error { + var continuation: AsyncThrowingStream.Continuation! + let stream = AsyncThrowingStream(bufferingPolicy: limit) { + continuation = $0 + } + return (stream: stream, continuation: continuation!) + } } -} #endif diff --git a/Sources/LanguageServerProtocol/Additions/NSRegularExpression+Matching.swift b/Sources/LanguageServerProtocol/Additions/NSRegularExpression+Matching.swift index 3cbcb03..3cd9e1b 100644 --- a/Sources/LanguageServerProtocol/Additions/NSRegularExpression+Matching.swift +++ b/Sources/LanguageServerProtocol/Additions/NSRegularExpression+Matching.swift @@ -1,29 +1,31 @@ import Foundation extension NSRegularExpression { - func matches(inFullString string: String, options: NSRegularExpression.MatchingOptions = []) -> [NSTextCheckingResult] { - let range = NSMakeRange(0, string.utf16.count) + func matches(inFullString string: String, options: NSRegularExpression.MatchingOptions = []) + -> [NSTextCheckingResult] + { + let range = NSMakeRange(0, string.utf16.count) - return matches(in: string, options: options, range: range) - } + return matches(in: string, options: options, range: range) + } } extension NSTextCheckingResult { - func range(at index: Int, in string: String) -> Range? { - let nsRange = range(at: index) + func range(at index: Int, in string: String) -> Range? { + let nsRange = range(at: index) - return Range(nsRange, in: string) - } + return Range(nsRange, in: string) + } - func stringValue(at index: Int, in string: String) -> Substring? { - guard let captureRange = range(at: index, in: string) else { - return nil - } + func stringValue(at index: Int, in string: String) -> Substring? { + guard let captureRange = range(at: index, in: string) else { + return nil + } - return string[captureRange] - } + return string[captureRange] + } - func intValue(at index: Int, in string: String) -> Int? { - return stringValue(at: index, in: string).flatMap { Int($0) } - } + func intValue(at index: Int, in string: String) -> Int? { + return stringValue(at: index, in: string).flatMap { Int($0) } + } } diff --git a/Sources/LanguageServerProtocol/Additions/ServerCapabilities+Extensions.swift b/Sources/LanguageServerProtocol/Additions/ServerCapabilities+Extensions.swift index a523fed..5e00632 100644 --- a/Sources/LanguageServerProtocol/Additions/ServerCapabilities+Extensions.swift +++ b/Sources/LanguageServerProtocol/Additions/ServerCapabilities+Extensions.swift @@ -1,133 +1,138 @@ import Foundation -public extension Registration { - var requestMethod: ClientRequest.Method? { - return ClientRequest.Method(rawValue: method) - } - - var notificationMethod: ClientNotification.Method? { - return ClientNotification.Method(rawValue: method) - } +extension Registration { + public var requestMethod: ClientRequest.Method? { + return ClientRequest.Method(rawValue: method) + } + + public var notificationMethod: ClientNotification.Method? { + return ClientNotification.Method(rawValue: method) + } } -public extension Unregistration { - var requestMethod: ClientRequest.Method? { - return ClientRequest.Method(rawValue: method) - } +extension Unregistration { + public var requestMethod: ClientRequest.Method? { + return ClientRequest.Method(rawValue: method) + } - var notificationMethod: ClientNotification.Method? { - return ClientNotification.Method(rawValue: method) - } + public var notificationMethod: ClientNotification.Method? { + return ClientNotification.Method(rawValue: method) + } } -public extension ServerCapabilities { - mutating func applyRegistrations(_ registrations: [Registration]) throws { - try registrations.forEach({ try applyRegistration($0) }) - } - - mutating func applyRegistration(_ registration: Registration) throws { - switch registration.requestMethod { - case .textDocumentSemanticTokens: - let data = try JSONEncoder().encode(registration.registerOptions) - let options = try JSONDecoder().decode(TwoTypeOption.self, from: data) - - self.semanticTokensProvider = options - return - case .textDocumentCompletion: - let data = try JSONEncoder().encode(registration.registerOptions) - let options = try JSONDecoder().decode(CompletionOptions.self, from: data) - - self.completionProvider = options - return - default: - break - } - - switch registration.notificationMethod { - case .workspaceDidChangeWatchedFiles: - break - default: - break - } - } - - mutating func applyUnregistrations(_ unregistrations: [Unregistration]) throws { - try unregistrations.forEach({ try applyUnregistration($0) }) - } - - mutating func applyUnregistration(_ unregistration: Unregistration) throws { - switch unregistration.requestMethod { - case .textDocumentSemanticTokens: - self.semanticTokensProvider = nil - return - case .textDocumentCompletion: - self.completionProvider = nil - return - default: - break - } - - switch unregistration.notificationMethod { - case .workspaceDidChangeWatchedFiles: - break - default: - break - } - } +extension ServerCapabilities { + public mutating func applyRegistrations(_ registrations: [Registration]) throws { + try registrations.forEach({ try applyRegistration($0) }) + } + + public mutating func applyRegistration(_ registration: Registration) throws { + switch registration.requestMethod { + case .textDocumentSemanticTokens: + let data = try JSONEncoder().encode(registration.registerOptions) + let options = try JSONDecoder().decode( + TwoTypeOption.self, + from: data) + + self.semanticTokensProvider = options + return + case .textDocumentCompletion: + let data = try JSONEncoder().encode(registration.registerOptions) + let options = try JSONDecoder().decode(CompletionOptions.self, from: data) + + self.completionProvider = options + return + default: + break + } + + switch registration.notificationMethod { + case .workspaceDidChangeWatchedFiles: + break + default: + break + } + } + + public mutating func applyUnregistrations(_ unregistrations: [Unregistration]) throws { + try unregistrations.forEach({ try applyUnregistration($0) }) + } + + public mutating func applyUnregistration(_ unregistration: Unregistration) throws { + switch unregistration.requestMethod { + case .textDocumentSemanticTokens: + self.semanticTokensProvider = nil + return + case .textDocumentCompletion: + self.completionProvider = nil + return + default: + break + } + + switch unregistration.notificationMethod { + case .workspaceDidChangeWatchedFiles: + break + default: + break + } + } } -public extension TwoTypeOption where T == TextDocumentSyncOptions, U == TextDocumentSyncKind { - var effectiveOptions: TextDocumentSyncOptions { - switch self { - case .optionA(let value): - return value - case .optionB(let changeKind): - return TextDocumentSyncOptions(openClose: false, change: changeKind, willSave: false, willSaveWaitUntil: false, save: nil) - } - } +extension TwoTypeOption where T == TextDocumentSyncOptions, U == TextDocumentSyncKind { + public var effectiveOptions: TextDocumentSyncOptions { + switch self { + case .optionA(let value): + return value + case .optionB(let changeKind): + return TextDocumentSyncOptions( + openClose: false, change: changeKind, willSave: false, willSaveWaitUntil: false, + save: nil) + } + } } -public extension TwoTypeOption where T == SemanticTokensOptions, U == SemanticTokensRegistrationOptions { - var effectiveOptions: SemanticTokensOptions { - switch self { - case .optionA(let options): - return options - case .optionB(let registrationOptions): - return SemanticTokensOptions(workDoneProgress: registrationOptions.workDoneProgress, - legend: registrationOptions.legend, - range: registrationOptions.range, - full: registrationOptions.full) - } - } +extension TwoTypeOption where T == SemanticTokensOptions, U == SemanticTokensRegistrationOptions { + public var effectiveOptions: SemanticTokensOptions { + switch self { + case .optionA(let options): + return options + case .optionB(let registrationOptions): + return SemanticTokensOptions( + workDoneProgress: registrationOptions.workDoneProgress, + legend: registrationOptions.legend, + range: registrationOptions.range, + full: registrationOptions.full) + } + } } -public extension SemanticTokensClientCapabilities.Requests.RangeOption { - var supported: Bool { - switch self { - case .optionA(let value): - return value - case .optionB(_): - return true - } - } +extension SemanticTokensClientCapabilities.Requests.RangeOption { + public var supported: Bool { + switch self { + case .optionA(let value): + return value + case .optionB(_): + return true + } + } } -public extension SemanticTokensClientCapabilities.Requests.FullOption { - var supported: Bool { - switch self { - case .optionA(let value): - return value - case .optionB(_): - return true - } - } - - var deltaSupported: Bool { - switch self { - case .optionA(_): - return false - case .optionB(let full): - return full.delta ?? false - } - } +extension SemanticTokensClientCapabilities.Requests.FullOption { + public var supported: Bool { + switch self { + case .optionA(let value): + return value + case .optionB(_): + return true + } + } + + public var deltaSupported: Bool { + switch self { + case .optionA(_): + return false + case .optionB(let full): + return full.delta ?? false + } + } } diff --git a/Sources/LanguageServerProtocol/Additions/Snippet.swift b/Sources/LanguageServerProtocol/Additions/Snippet.swift index 470a1a5..d62d4f6 100644 --- a/Sources/LanguageServerProtocol/Additions/Snippet.swift +++ b/Sources/LanguageServerProtocol/Additions/Snippet.swift @@ -1,165 +1,165 @@ import Foundation public struct Snippet { - public enum Element: Equatable { - case text(String) - case tabstop(Int) - case placeholder(Int, String) - case choice(Int, [String]) - case variable(String, String) - case variableTransform(String, String, String, String) - } - - public let value: String - - public init(value: String) { - self.value = value - } + public enum Element: Equatable { + case text(String) + case tabstop(Int) + case placeholder(Int, String) + case choice(Int, [String]) + case variable(String, String) + case variableTransform(String, String, String, String) + } + + public let value: String + + public init(value: String) { + self.value = value + } } extension Snippet { - public var elementRanges: [NSRange] { - let regex = try! NSRegularExpression(pattern: #"\$(\w+|\{([^$]+)\})"#) + public var elementRanges: [NSRange] { + let regex = try! NSRegularExpression(pattern: #"\$(\w+|\{([^$]+)\})"#) - return regex.matches(inFullString: value).map({ $0.range }) - } + return regex.matches(inFullString: value).map({ $0.range }) + } - public func enumerateElements(block: (Element) -> Void) { - let ranges = elementRanges + public func enumerateElements(block: (Element) -> Void) { + let ranges = elementRanges - var location = 0 + var location = 0 - for range in ranges { - let textRange = NSMakeRange(location, range.location - location) + for range in ranges { + let textRange = NSMakeRange(location, range.location - location) - if let v = subvalue(for: textRange) { - block(textElement(for: v)) - } + if let v = subvalue(for: textRange) { + block(textElement(for: v)) + } - if let content = subvalue(for: range) { - if let elem = element(for: content) { - block(elem) - } - } + if let content = subvalue(for: range) { + if let elem = element(for: content) { + block(elem) + } + } - location = NSMaxRange(range) - } + location = NSMaxRange(range) + } - let lastTextRange = NSMakeRange(location, value.utf16.count - location) + let lastTextRange = NSMakeRange(location, value.utf16.count - location) - if let v = subvalue(for: lastTextRange) { - block(textElement(for: v)) - } - } + if let v = subvalue(for: lastTextRange) { + block(textElement(for: v)) + } + } - public var elements: [Snippet.Element] { - var list = [Snippet.Element]() + public var elements: [Snippet.Element] { + var list = [Snippet.Element]() - enumerateElements { (element) in - list.append(element) - } + enumerateElements { (element) in + list.append(element) + } - return list - } + return list + } - private func subvalue(for range: NSRange) -> String? { - if range.length == 0 { - return nil - } + private func subvalue(for range: NSRange) -> String? { + if range.length == 0 { + return nil + } - guard let stringRange = Range(range, in: value) else { - return nil - } + guard let stringRange = Range(range, in: value) else { + return nil + } - return String(value[stringRange]) - } + return String(value[stringRange]) + } } extension Snippet { - private func element(for content: String) -> Element? { - if let elem = tabstop(for: content) { - return elem - } + private func element(for content: String) -> Element? { + if let elem = tabstop(for: content) { + return elem + } - if let elem = placeholder(for: content) { - return elem - } + if let elem = placeholder(for: content) { + return elem + } - return nil - } + return nil + } - private func textElement(for content: String) -> Element { - let adjustedValue = content.replacingOccurrences(of: "\\", with: "") + private func textElement(for content: String) -> Element { + let adjustedValue = content.replacingOccurrences(of: "\\", with: "") - return Element.text(adjustedValue) - } + return Element.text(adjustedValue) + } - private func tabstop(for content: String) -> Element? { - let regex = try! NSRegularExpression(pattern: "\\$(\\d+)") + private func tabstop(for content: String) -> Element? { + let regex = try! NSRegularExpression(pattern: "\\$(\\d+)") - let matches = regex.matches(inFullString: content) + let matches = regex.matches(inFullString: content) - guard matches.count == 1 else { - return nil - } + guard matches.count == 1 else { + return nil + } - guard let tabstopValueRange = matches[0].range(at: 1, in: content) else { - return nil - } + guard let tabstopValueRange = matches[0].range(at: 1, in: content) else { + return nil + } - guard let tabstopValue = Int(content[tabstopValueRange]) else { - return nil - } + guard let tabstopValue = Int(content[tabstopValueRange]) else { + return nil + } - return Element.tabstop(tabstopValue) - } + return Element.tabstop(tabstopValue) + } - private func placeholder(for content: String) -> Element? { - let regex = try! NSRegularExpression(pattern: #"\$\{(\d+):(.*)\}"#) + private func placeholder(for content: String) -> Element? { + let regex = try! NSRegularExpression(pattern: #"\$\{(\d+):(.*)\}"#) - let matches = regex.matches(inFullString: content) + let matches = regex.matches(inFullString: content) - guard matches.count == 1 else { - return nil - } + guard matches.count == 1 else { + return nil + } - guard let numberRange = matches[0].range(at: 1, in: content) else { - return nil - } + guard let numberRange = matches[0].range(at: 1, in: content) else { + return nil + } - guard let numberValue = Int(content[numberRange]) else { - return nil - } + guard let numberValue = Int(content[numberRange]) else { + return nil + } - let innerContentsRange = matches[0].range(at: 2, in: content) + let innerContentsRange = matches[0].range(at: 2, in: content) - let innerContentValue = innerContentsRange.flatMap { String(content[$0]) } ?? "" - let adjustedValue = innerContentValue.replacingOccurrences(of: "\\", with: "") + let innerContentValue = innerContentsRange.flatMap { String(content[$0]) } ?? "" + let adjustedValue = innerContentValue.replacingOccurrences(of: "\\", with: "") - return Element.placeholder(numberValue, adjustedValue) - } + return Element.placeholder(numberValue, adjustedValue) + } } extension Snippet { - public static func parsePlaceholderValue(_ value: String) -> (String, String) { - guard let regex = try? NSRegularExpression(pattern: "(\\w+)\\b(.+)") else { - return (value, value) - } + public static func parsePlaceholderValue(_ value: String) -> (String, String) { + guard let regex = try? NSRegularExpression(pattern: "(\\w+)\\b(.+)") else { + return (value, value) + } - let matches = regex.matches(inFullString: value) - let match = matches.first + let matches = regex.matches(inFullString: value) + let match = matches.first - guard let contentRange = match?.range(at: 1, in: value) else { - return (value, value) - } + guard let contentRange = match?.range(at: 1, in: value) else { + return (value, value) + } - guard let labelRange = match?.range(at: 2, in: value) else { - return (value, value) - } + guard let labelRange = match?.range(at: 2, in: value) else { + return (value, value) + } - let content = String(value[contentRange]) - let label = String(value[labelRange]) + let content = String(value[contentRange]) + let label = String(value[labelRange]) - return (label, content) - } + return (label, content) + } } diff --git a/Sources/LanguageServerProtocol/Additions/TokenRepresentation.swift b/Sources/LanguageServerProtocol/Additions/TokenRepresentation.swift index de16b09..c23358c 100644 --- a/Sources/LanguageServerProtocol/Additions/TokenRepresentation.swift +++ b/Sources/LanguageServerProtocol/Additions/TokenRepresentation.swift @@ -61,7 +61,7 @@ public final class TokenRepresentation { /// - Returns: Ranges affected by the new data (currently unimplemented). public func applyEdits(_ edits: [SemanticTokensEdit]) -> [LSPRange] { // sort high to low - let descendingEdits = edits.sorted(by: {a, b in a.start > b.start }) + let descendingEdits = edits.sorted(by: { a, b in a.start > b.start }) for edit in descendingEdits { let start = Int(edit.start) @@ -99,13 +99,13 @@ public final class TokenRepresentation { lastLine = line - let charDelta = Int(data[i+1]) + let charDelta = Int(data[i + 1]) let startingChar = lastStartChar ?? 0 let startChar = (lineDelta == 0 ? startingChar : 0) + charDelta lastStartChar = startChar - let length = Int(data[i+2]) + let length = Int(data[i + 2]) let start = Position(line: line, character: startChar) if start >= range.end { @@ -118,7 +118,7 @@ public final class TokenRepresentation { } let tokenRange = LSPRange(start: start, end: end) - let typeIndex = Int(data[i+3]) + let typeIndex = Int(data[i + 3]) if let token = makeToken(range: tokenRange, typeIndex: typeIndex) { tokens.append(token) diff --git a/Sources/LanguageServerProtocol/BaseProtocol.swift b/Sources/LanguageServerProtocol/BaseProtocol.swift index 737b632..4bae044 100644 --- a/Sources/LanguageServerProtocol/BaseProtocol.swift +++ b/Sources/LanguageServerProtocol/BaseProtocol.swift @@ -10,65 +10,65 @@ public typealias DocumentUri = String public typealias ProgressToken = TwoTypeOption public struct CancelParams: Hashable, Codable, Sendable { - public var id: TwoTypeOption + public var id: TwoTypeOption - public init(id: Int) { - self.id = .optionA(id) - } + public init(id: Int) { + self.id = .optionA(id) + } - public init(id: String) { - self.id = .optionB(id) - } + public init(id: String) { + self.id = .optionB(id) + } } public struct ProgressParams: Hashable, Codable, Sendable { - public var token: ProgressToken - public var value: LSPAny? + public var token: ProgressToken + public var value: LSPAny? } public struct LogTraceParams: Hashable, Codable, Sendable { - public var string: String - public var verbose: String? + public var string: String + public var verbose: String? } public enum TraceValue: String, Hashable, Codable, Sendable { - case off - case messages - case verbose + case off + case messages + case verbose } public struct SetTraceParams: Hashable, Codable, Sendable { - public var value: TraceValue + public var value: TraceValue - public init(value: TraceValue) { - self.value = value - } + public init(value: TraceValue) { + self.value = value + } } public struct ValueSet: Hashable, Codable { - public var valueSet: [T] + public var valueSet: [T] - public init(valueSet: [T]) { - self.valueSet = valueSet - } + public init(valueSet: [T]) { + self.valueSet = valueSet + } - public init(value: T) { - self.valueSet = [value] - } + public init(value: T) { + self.valueSet = [value] + } } extension ValueSet: ExpressibleByArrayLiteral { - public typealias ArrayLiteralElement = T + public typealias ArrayLiteralElement = T - public init(arrayLiteral elements: T...) { - self.valueSet = elements - } + public init(arrayLiteral elements: T...) { + self.valueSet = elements + } } -public extension ValueSet where T: CaseIterable { - static var all: ValueSet { - return ValueSet(valueSet: Array(T.allCases)) - } +extension ValueSet where T: CaseIterable { + public static var all: ValueSet { + return ValueSet(valueSet: Array(T.allCases)) + } } extension ValueSet: Sendable where T: Sendable { @@ -80,8 +80,8 @@ public enum LanguageIdentifier: String, Codable, CaseIterable, Sendable { case bibtex case clojure = "clojure" case coffeescript - case c - case cpp + case c + case cpp case csharp case css case diff @@ -92,7 +92,7 @@ public enum LanguageIdentifier: String, Codable, CaseIterable, Sendable { case fsharp case gitcommit case gitrebase - case go + case go case groovy case handlebars case html @@ -100,31 +100,31 @@ public enum LanguageIdentifier: String, Codable, CaseIterable, Sendable { case java case javascript case javascriptreact - case json + case json case latex case less case lua case makefile case markdown - case objc = "objective-c" - case objcpp = "objective-cpp" + case objc = "objective-c" + case objcpp = "objective-cpp" case perl case perl6 - case php + case php case powershell case pug = "jade" case python case r case razor - case ruby - case rust + case ruby + case rust case scss case sass case scala case shaderlab case shellscript case sql - case swift + case swift case typescript case typescriptreact case tex @@ -135,11 +135,12 @@ public enum LanguageIdentifier: String, Codable, CaseIterable, Sendable { } public struct DocumentFilter: Codable, Hashable, Sendable { - public let language: LanguageIdentifier? - public let scheme: String? - public let pattern: String? + public let language: LanguageIdentifier? + public let scheme: String? + public let pattern: String? - public init(language: LanguageIdentifier? = nil, scheme: String? = nil, pattern: String? = nil) { + public init(language: LanguageIdentifier? = nil, scheme: String? = nil, pattern: String? = nil) + { self.language = language self.scheme = scheme self.pattern = pattern @@ -149,19 +150,19 @@ public struct DocumentFilter: Codable, Hashable, Sendable { public typealias DocumentSelector = [DocumentFilter] public struct TextDocumentIdentifier: Codable, Hashable, Sendable { - public var uri: DocumentUri + public var uri: DocumentUri - public init(uri: DocumentUri) { - self.uri = uri - } + public init(uri: DocumentUri) { + self.uri = uri + } - public init(path: String) { - self.uri = URL(fileURLWithPath: path).absoluteString - } + public init(path: String) { + self.uri = URL(fileURLWithPath: path).absoluteString + } } extension TextDocumentIdentifier: CustomStringConvertible { - public var description: String { - return uri.description - } + public var description: String { + return uri.description + } } diff --git a/Sources/LanguageServerProtocol/BasicStructures.swift b/Sources/LanguageServerProtocol/BasicStructures.swift index ceb719d..5262842 100644 --- a/Sources/LanguageServerProtocol/BasicStructures.swift +++ b/Sources/LanguageServerProtocol/BasicStructures.swift @@ -2,85 +2,85 @@ import Foundation import JSONRPC public struct Position: Codable, Hashable, Sendable { - public static let zero = Position(line: 0, character: 0) + public static let zero = Position(line: 0, character: 0) - public let line: Int - public let character: Int + public let line: Int + public let character: Int - public init(line: Int, character: Int) { - self.line = line - self.character = character - } + public init(line: Int, character: Int) { + self.line = line + self.character = character + } - public init(_ pair: (Int, Int)) { - self.line = pair.0 - self.character = pair.1 - } + public init(_ pair: (Int, Int)) { + self.line = pair.0 + self.character = pair.1 + } } extension Position: CustomStringConvertible { - public var description: String { - return "{\(line), \(character)}" - } + public var description: String { + return "{\(line), \(character)}" + } } extension Position: Comparable { - public static func < (lhs: Position, rhs: Position) -> Bool { - if lhs.line == rhs.line { - return lhs.character < rhs.character - } + public static func < (lhs: Position, rhs: Position) -> Bool { + if lhs.line == rhs.line { + return lhs.character < rhs.character + } - return lhs.line < rhs.line - } + return lhs.line < rhs.line + } } public struct LSPRange: Codable, Hashable, Sendable { - public static let zero = LSPRange(start: .zero, end: .zero) + public static let zero = LSPRange(start: .zero, end: .zero) - public let start: Position - public let end: Position + public let start: Position + public let end: Position - public init(start: Position, end: Position) { - self.start = start - self.end = end - } + public init(start: Position, end: Position) { + self.start = start + self.end = end + } - public init(startPair: (Int, Int), endPair: (Int, Int)) { - self.start = Position(startPair) - self.end = Position(endPair) - } + public init(startPair: (Int, Int), endPair: (Int, Int)) { + self.start = Position(startPair) + self.end = Position(endPair) + } - public func contains(_ position: Position) -> Bool { - return position > start && position < end - } + public func contains(_ position: Position) -> Bool { + return position > start && position < end + } - public func intersects(_ other: LSPRange) -> Bool { - return contains(other.start) || contains(other.end) - } + public func intersects(_ other: LSPRange) -> Bool { + return contains(other.start) || contains(other.end) + } - public var isEmpty: Bool { - return start == end - } + public var isEmpty: Bool { + return start == end + } } extension LSPRange: CustomStringConvertible { - public var description: String { - return "(\(start), \(end))" - } + public var description: String { + return "(\(start), \(end))" + } } public struct TextDocumentItem: Codable, Hashable, Sendable { - public let uri: DocumentUri - public let languageId: String - public let version: Int - public let text: String + public let uri: DocumentUri + public let languageId: String + public let version: Int + public let text: String - public init(uri: DocumentUri, languageId: LanguageIdentifier, version: Int, text: String) { - self.uri = uri + public init(uri: DocumentUri, languageId: LanguageIdentifier, version: Int, text: String) { + self.uri = uri self.languageId = languageId.rawValue - self.version = version - self.text = text - } + self.version = version + self.text = text + } public init(uri: DocumentUri, languageId: String, version: Int, text: String) { self.uri = uri @@ -91,26 +91,26 @@ public struct TextDocumentItem: Codable, Hashable, Sendable { } public struct VersionedTextDocumentIdentifier: Codable, Hashable, Sendable { - public let uri: DocumentUri - public let version: Int? + public let uri: DocumentUri + public let version: Int? - public init(uri: DocumentUri, version: Int?) { - self.uri = uri - self.version = version - } + public init(uri: DocumentUri, version: Int?) { + self.uri = uri + self.version = version + } } extension VersionedTextDocumentIdentifier: CustomStringConvertible { - public var description: String { - let vString = version.map { String($0) } ?? "" + public var description: String { + let vString = version.map { String($0) } ?? "" - return "\(uri.description): Version \(vString)" - } + return "\(uri.description): Version \(vString)" + } } public struct Location: Codable, Hashable, Sendable { - public let uri: DocumentUri - public let range: LSPRange + public let uri: DocumentUri + public let range: LSPRange public init(uri: DocumentUri, range: LSPRange) { self.uri = uri @@ -119,94 +119,97 @@ public struct Location: Codable, Hashable, Sendable { } public struct Command: Codable, Hashable, Sendable { - public let title: String - public let command: String - public let arguments: [LSPAny]? + public let title: String + public let command: String + public let arguments: [LSPAny]? } public enum SymbolKind: Int, CaseIterable, Hashable, Codable, Sendable { - case file = 1 - case module = 2 - case namespace = 3 - case package = 4 - case `class` = 5 - case method = 6 - case property = 7 - case field = 8 - case constructor = 9 - case `enum` = 10 - case interface = 11 - case function = 12 - case variable = 13 - case constant = 14 - case string = 15 - case number = 16 - case boolean = 17 - case array = 18 - case object = 19 - case key = 20 - case null = 21 - case enumMember = 22 - case `struct` = 23 - case event = 24 - case `operator` = 25 - case typeParameter = 26 + case file = 1 + case module = 2 + case namespace = 3 + case package = 4 + case `class` = 5 + case method = 6 + case property = 7 + case field = 8 + case constructor = 9 + case `enum` = 10 + case interface = 11 + case function = 12 + case variable = 13 + case constant = 14 + case string = 15 + case number = 16 + case boolean = 17 + case array = 18 + case object = 19 + case key = 20 + case null = 21 + case enumMember = 22 + case `struct` = 23 + case event = 24 + case `operator` = 25 + case typeParameter = 26 } public enum MarkupKind: String, Codable, Hashable, Sendable { - case plaintext - case markdown + case plaintext + case markdown } public struct TextDocumentPositionParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier - public let position: Position + public let textDocument: TextDocumentIdentifier + public let position: Position - public init(textDocument: TextDocumentIdentifier, position: Position) { - self.textDocument = textDocument - self.position = position - } + public init(textDocument: TextDocumentIdentifier, position: Position) { + self.textDocument = textDocument + self.position = position + } - public init(uri: DocumentUri, position: Position) { - let textDocId = TextDocumentIdentifier(uri: uri) + public init(uri: DocumentUri, position: Position) { + let textDocId = TextDocumentIdentifier(uri: uri) - self.init(textDocument: textDocId, position: position) - } + self.init(textDocument: textDocId, position: position) + } } public struct LanguageStringPair: Codable, Hashable, Sendable { - public let language: LanguageIdentifier - public let value: String + public let language: LanguageIdentifier + public let value: String } public typealias MarkedString = TwoTypeOption -public extension MarkedString { - var value: String { - switch self { - case .optionA(let string): - return string - case .optionB(let pair): - return pair.value - } - } +extension MarkedString { + public var value: String { + switch self { + case .optionA(let string): + return string + case .optionB(let pair): + return pair.value + } + } } public struct MarkupContent: Codable, Hashable, Sendable { - public let kind: MarkupKind - public let value: String + public let kind: MarkupKind + public let value: String } public struct LocationLink: Codable, Hashable, Sendable { - public init(originSelectionRange: LSPRange? = nil, targetUri: String, targetRange: LSPRange, targetSelectionRange: LSPRange) { + public init( + originSelectionRange: LSPRange? = nil, targetUri: String, targetRange: LSPRange, + targetSelectionRange: LSPRange + ) { self.originSelectionRange = originSelectionRange self.targetUri = targetUri self.targetRange = targetRange self.targetSelectionRange = targetSelectionRange } - public let originSelectionRange: LSPRange? - public let targetUri: String - public let targetRange: LSPRange - public let targetSelectionRange: LSPRange + public let originSelectionRange: LSPRange? + public let targetUri: String + public let targetRange: LSPRange + public let targetSelectionRange: LSPRange } diff --git a/Sources/LanguageServerProtocol/Client.swift b/Sources/LanguageServerProtocol/Client.swift index 1d9d52b..a5871ce 100644 --- a/Sources/LanguageServerProtocol/Client.swift +++ b/Sources/LanguageServerProtocol/Client.swift @@ -1,9 +1,9 @@ import Foundation public struct Registration: Codable, Hashable, Sendable { - public var id: String - public var method: String - public var registerOptions: LSPAny? + public var id: String + public var method: String + public var registerOptions: LSPAny? public init(id: String, method: String, registerOptions: LSPAny? = nil) { self.id = id @@ -13,60 +13,60 @@ public struct Registration: Codable, Hashable, Sendable { } extension Registration { - var registerOptionsData: Data? { - return try? JSONEncoder().encode(registerOptions) - } + var registerOptionsData: Data? { + return try? JSONEncoder().encode(registerOptions) + } - func reintrepretOptions(_ type: T.Type) throws -> T { - let data = try JSONEncoder().encode(registerOptions) + func reintrepretOptions(_ type: T.Type) throws -> T { + let data = try JSONEncoder().encode(registerOptions) - return try JSONDecoder().decode(type.self, from: data) - } + return try JSONDecoder().decode(type.self, from: data) + } - func decodeServerRegistration() throws -> ServerRegistration { - guard let regMethod = ServerRegistration.Method(rawValue: method) else { - throw ServerError.unhandledRegistrationMethod(method) - } + func decodeServerRegistration() throws -> ServerRegistration { + guard let regMethod = ServerRegistration.Method(rawValue: method) else { + throw ServerError.unhandledRegistrationMethod(method) + } - switch regMethod { - case .workspaceDidChangeWatchedFiles: - let options = try reintrepretOptions(DidChangeWatchedFilesRegistrationOptions.self) + switch regMethod { + case .workspaceDidChangeWatchedFiles: + let options = try reintrepretOptions(DidChangeWatchedFilesRegistrationOptions.self) - return .workspaceDidChangeWatchedFiles(options) - case .workspaceDidChangeConfiguration: - return .workspaceDidChangeConfiguration - case .workspaceDidChangeWorkspaceFolders: - return .workspaceDidChangeWorkspaceFolders - case .textDocumentSemanticTokens: - let options = try reintrepretOptions(SemanticTokensRegistrationOptions.self) + return .workspaceDidChangeWatchedFiles(options) + case .workspaceDidChangeConfiguration: + return .workspaceDidChangeConfiguration + case .workspaceDidChangeWorkspaceFolders: + return .workspaceDidChangeWorkspaceFolders + case .textDocumentSemanticTokens: + let options = try reintrepretOptions(SemanticTokensRegistrationOptions.self) - return .textDocumentSemanticTokens(options) + return .textDocumentSemanticTokens(options) - } - } + } + } - public var serverRegistration: ServerRegistration? { - return try? decodeServerRegistration() - } + public var serverRegistration: ServerRegistration? { + return try? decodeServerRegistration() + } } public struct RegistrationParams: Codable, Hashable, Sendable { - public var registrations: [Registration] + public var registrations: [Registration] public init(registrations: [Registration]) { self.registrations = registrations } - public var serverRegistrations: [ServerRegistration] { - return registrations.compactMap({ $0.serverRegistration }) - } + public var serverRegistrations: [ServerRegistration] { + return registrations.compactMap({ $0.serverRegistration }) + } } public struct Unregistration: Codable, Hashable, Sendable { - public var id: String - public var method: String + public var id: String + public var method: String } public struct UnregistrationParams: Codable, Hashable, Sendable { - public var unregistrations: [Unregistration] + public var unregistrations: [Unregistration] } diff --git a/Sources/LanguageServerProtocol/Client/JSONRPCServerConnection.swift b/Sources/LanguageServerProtocol/Client/JSONRPCServerConnection.swift index f9ebf53..33fa15f 100644 --- a/Sources/LanguageServerProtocol/Client/JSONRPCServerConnection.swift +++ b/Sources/LanguageServerProtocol/Client/JSONRPCServerConnection.swift @@ -29,14 +29,13 @@ public actor JSONRPCServerConnection: ServerConnection { for await event in seq { - switch event { case let .notification(notification, data): self.handleNotification(notification, data: data) case let .request(request, handler, data): self.handleRequest(request, data: data, handler: handler) case .error: - break // TODO? + break // TODO? } } @@ -83,7 +82,8 @@ public actor JSONRPCServerConnection: ServerConnection { } } - public func sendRequest(_ request: ClientRequest) async throws -> Response where Response : Decodable & Sendable { + public func sendRequest(_ request: ClientRequest) async throws -> Response + where Response: Decodable & Sendable { let method = request.method.rawValue switch request { @@ -188,7 +188,9 @@ public actor JSONRPCServerConnection: ServerConnection { } } - private func decodeNotificationParams(_ type: Params.Type, from data: Data) throws -> Params where Params : Decodable { + private func decodeNotificationParams(_ type: Params.Type, from data: Data) throws + -> Params where Params: Decodable + { let note = try JSONDecoder().decode(JSONRPCNotification.self, from: data) guard let params = note.params else { @@ -250,7 +252,8 @@ public actor JSONRPCServerConnection: ServerConnection { } } - private func decodeRequestParams(_ type: Params.Type, from data: Data) throws -> Params where Params : Decodable { + private func decodeRequestParams(_ type: Params.Type, from data: Data) throws -> Params + where Params: Decodable { let req = try JSONDecoder().decode(JSONRPCRequest.self, from: data) guard let params = req.params else { @@ -260,7 +263,9 @@ public actor JSONRPCServerConnection: ServerConnection { return params } - private nonisolated func makeErrorOnlyHandler(_ handler: @escaping JSONRPCEvent.RequestHandler) -> ServerRequest.ErrorOnlyHandler { + private nonisolated func makeErrorOnlyHandler(_ handler: @escaping JSONRPCEvent.RequestHandler) + -> ServerRequest.ErrorOnlyHandler + { return { if let error = $0 { await handler(.failure(error)) @@ -270,7 +275,9 @@ public actor JSONRPCServerConnection: ServerConnection { } } - private nonisolated func makeHandler(_ handler: @escaping JSONRPCEvent.RequestHandler) -> ServerRequest.Handler { + private nonisolated func makeHandler(_ handler: @escaping JSONRPCEvent.RequestHandler) + -> ServerRequest.Handler + { return { let loweredResult = $0.map({ $0 as Encodable & Sendable }) @@ -278,7 +285,9 @@ public actor JSONRPCServerConnection: ServerConnection { } } - private func handleRequest(_ anyRequest: AnyJSONRPCRequest, data: Data, handler: @escaping JSONRPCEvent.RequestHandler) { + private func handleRequest( + _ anyRequest: AnyJSONRPCRequest, data: Data, handler: @escaping JSONRPCEvent.RequestHandler + ) { let methodName = anyRequest.method let id = anyRequest.id @@ -294,12 +303,14 @@ public actor JSONRPCServerConnection: ServerConnection { yield(id: id, request: ServerRequest.workspaceConfiguration(params, reqHandler)) case .workspaceFolders: - let reqHandler: ServerRequest.Handler = makeHandler(handler) + let reqHandler: ServerRequest.Handler = makeHandler( + handler) yield(id: id, request: ServerRequest.workspaceFolders(reqHandler)) case .workspaceApplyEdit: let params = try decodeRequestParams(ApplyWorkspaceEditParams.self, from: data) - let reqHandler: ServerRequest.Handler = makeHandler(handler) + let reqHandler: ServerRequest.Handler = makeHandler( + handler) yield(id: id, request: ServerRequest.workspaceApplyEdit(params, reqHandler)) case .clientRegisterCapability: @@ -322,7 +333,8 @@ public actor JSONRPCServerConnection: ServerConnection { yield(id: id, request: ServerRequest.workspaceSemanticTokenRefresh(reqHandler)) case .windowShowMessageRequest: let params = try decodeRequestParams(ShowMessageRequestParams.self, from: data) - let reqHandler: ServerRequest.Handler = makeHandler(handler) + let reqHandler: ServerRequest.Handler = makeHandler( + handler) yield(id: id, request: ServerRequest.windowShowMessageRequest(params, reqHandler)) case .windowShowDocument: @@ -334,7 +346,8 @@ public actor JSONRPCServerConnection: ServerConnection { let params = try decodeRequestParams(WorkDoneProgressCreateParams.self, from: data) let reqHandler = makeErrorOnlyHandler(handler) - yield(id: id, request: ServerRequest.windowWorkDoneProgressCreate(params, reqHandler)) + yield( + id: id, request: ServerRequest.windowWorkDoneProgressCreate(params, reqHandler)) } diff --git a/Sources/LanguageServerProtocol/Client/MockServer.swift b/Sources/LanguageServerProtocol/Client/MockServer.swift index 8d7ceed..65a8015 100644 --- a/Sources/LanguageServerProtocol/Client/MockServer.swift +++ b/Sources/LanguageServerProtocol/Client/MockServer.swift @@ -26,7 +26,8 @@ public actor MockServer: ServerConnection { public init() { (self.eventSequence, self.eventContinuation) = EventSequence.makeStream() - (self.sentMessageSequence, self.sentMessageContinuation) = ClientMessageSequence.makeStream() + (self.sentMessageSequence, self.sentMessageContinuation) = + ClientMessageSequence.makeStream() } deinit { @@ -38,7 +39,8 @@ public actor MockServer: ServerConnection { sentMessageContinuation.yield(.notification(notif)) } - public func sendRequest(_ request: ClientRequest) async throws -> Response where Response : Decodable, Response : Sendable { + public func sendRequest(_ request: ClientRequest) async throws -> Response + where Response: Decodable, Response: Sendable { sentMessageContinuation.yield(.request(request)) if mockResponses.isEmpty { @@ -71,7 +73,8 @@ extension MockServer { } /// Simulate a server response. - public func sendMockResponse(_ response: Response) throws where Response : Encodable, Response : Sendable { + public func sendMockResponse(_ response: Response) throws + where Response: Encodable, Response: Sendable { let data = try JSONEncoder().encode(response) sendMockResponse(data) @@ -79,7 +82,7 @@ extension MockServer { /// Simulate a server request. public func sendMockRequest(_ request: ServerRequest) { - eventContinuation.yield(.request(id: .numericId(0) , request: request)) + eventContinuation.yield(.request(id: .numericId(0), request: request)) } /// Simulate a server notification. diff --git a/Sources/LanguageServerProtocol/Client/ServerConnection.swift b/Sources/LanguageServerProtocol/Client/ServerConnection.swift index 9312478..edd30e5 100644 --- a/Sources/LanguageServerProtocol/Client/ServerConnection.swift +++ b/Sources/LanguageServerProtocol/Client/ServerConnection.swift @@ -9,7 +9,8 @@ public protocol ServerConnection { var eventSequence: EventSequence { get } func sendNotification(_ notif: ClientNotification) async throws - func sendRequest(_ request: ClientRequest) async throws -> Response + func sendRequest(_ request: ClientRequest) async throws + -> Response } extension ServerConnection { @@ -18,283 +19,346 @@ extension ServerConnection { } } -public extension ServerConnection { - func initialize(params: InitializeParams) async throws -> InitializationResponse { +extension ServerConnection { + public func initialize(params: InitializeParams) async throws -> InitializationResponse { return try await sendRequest(.initialize(params, ClientRequest.NullHandler)) } - func initialized(params: InitializedParams) async throws { + public func initialized(params: InitializedParams) async throws { try await sendNotification(.initialized(params)) } - func shutdown() async throws { + public func shutdown() async throws { try await sendRequestWithErrorOnlyResult(.shutdown(ClientRequest.NullHandler)) } - func exit() async throws { + public func exit() async throws { try await sendNotification(.exit) } - func cancelRequest(params: CancelParams) async throws { - try await sendNotification(.protocolCancelRequest(params)) - } + public func cancelRequest(params: CancelParams) async throws { + try await sendNotification(.protocolCancelRequest(params)) + } - func setTrace(params: SetTraceParams) async throws { - try await sendNotification(.protocolSetTrace(params)) - } + public func setTrace(params: SetTraceParams) async throws { + try await sendNotification(.protocolSetTrace(params)) + } - func textDocumentDidOpen(params: DidOpenTextDocumentParams) async throws { + public func textDocumentDidOpen(params: DidOpenTextDocumentParams) async throws { try await sendNotification(.textDocumentDidOpen(params)) - } + } - @available(*, deprecated, renamed: "textDocumentDidOpen", message: "This method has been renamed to better match the spec.") - func didOpenTextDocument(params: DidOpenTextDocumentParams) async throws { + @available( + *, deprecated, renamed: "textDocumentDidOpen", + message: "This method has been renamed to better match the spec." + ) + public func didOpenTextDocument(params: DidOpenTextDocumentParams) async throws { try await textDocumentDidOpen(params: params) } - func textDocumentDidChange(params: DidChangeTextDocumentParams) async throws { + public func textDocumentDidChange(params: DidChangeTextDocumentParams) async throws { try await sendNotification(.textDocumentDidChange(params)) - } + } - @available(*, deprecated, renamed: "textDocumentDidChange", message: "This method has been renamed to better match the spec.") - func didChangeTextDocument(params: DidChangeTextDocumentParams) async throws { + @available( + *, deprecated, renamed: "textDocumentDidChange", + message: "This method has been renamed to better match the spec." + ) + public func didChangeTextDocument(params: DidChangeTextDocumentParams) async throws { try await textDocumentDidChange(params: params) } - func textDocumentDidClose(params: DidCloseTextDocumentParams) async throws { + public func textDocumentDidClose(params: DidCloseTextDocumentParams) async throws { try await sendNotification(.textDocumentDidClose(params)) - } + } - @available(*, deprecated, renamed: "didCloseTextDocument", message: "This method has been renamed to better match the spec.") - func didCloseTextDocument(params: DidCloseTextDocumentParams) async throws { + @available( + *, deprecated, renamed: "didCloseTextDocument", + message: "This method has been renamed to better match the spec." + ) + public func didCloseTextDocument(params: DidCloseTextDocumentParams) async throws { try await textDocumentDidClose(params: params) } - func textDocumentWillSave(params: WillSaveTextDocumentParams) async throws { + public func textDocumentWillSave(params: WillSaveTextDocumentParams) async throws { try await sendNotification(.textDocumentWillSave(params)) - } + } - @available(*, deprecated, renamed: "textDocumentWillSave", message: "This method has been renamed to better match the spec.") - func willSaveTextDocument(params: WillSaveTextDocumentParams) async throws { + @available( + *, deprecated, renamed: "textDocumentWillSave", + message: "This method has been renamed to better match the spec." + ) + public func willSaveTextDocument(params: WillSaveTextDocumentParams) async throws { try await textDocumentWillSave(params: params) } - func textDocumentWillSaveWaitUntil(params: WillSaveTextDocumentParams) async throws -> WillSaveWaitUntilResponse { + public func textDocumentWillSaveWaitUntil(params: WillSaveTextDocumentParams) async throws + -> WillSaveWaitUntilResponse + { try await sendRequest(.textDocumentWillSaveWaitUntil(params, ClientRequest.NullHandler)) } - func textDocumentDidSave(params: DidSaveTextDocumentParams) async throws { + public func textDocumentDidSave(params: DidSaveTextDocumentParams) async throws { try await sendNotification(.textDocumentDidSave(params)) - } + } - func workspaceDidChangeWatchedFiles(params: DidChangeWatchedFilesParams) async throws { - try await sendNotification(.workspaceDidChangeWatchedFiles(params)) - } + public func workspaceDidChangeWatchedFiles(params: DidChangeWatchedFilesParams) async throws { + try await sendNotification(.workspaceDidChangeWatchedFiles(params)) + } - @available(*, deprecated, renamed: "workspaceDidChangeWatchedFiles", message: "This method has been renamed to better match the spec.") - func didChangeWatchedFiles(params: DidChangeWatchedFilesParams) async throws { + @available( + *, deprecated, renamed: "workspaceDidChangeWatchedFiles", + message: "This method has been renamed to better match the spec." + ) + public func didChangeWatchedFiles(params: DidChangeWatchedFilesParams) async throws { try await workspaceDidChangeWatchedFiles(params: params) } - func callHierarchyIncomingCalls(params: CallHierarchyIncomingCallsParams) async throws -> CallHierarchyIncomingCallsResponse { + public func callHierarchyIncomingCalls(params: CallHierarchyIncomingCallsParams) async throws + -> CallHierarchyIncomingCallsResponse + { try await sendRequest(.callHierarchyIncomingCalls(params, ClientRequest.NullHandler)) } - func callHierarchyOutgoingCalls(params: CallHierarchyOutgoingCallsParams) async throws -> CallHierarchyOutgoingCallsResponse { + public func callHierarchyOutgoingCalls(params: CallHierarchyOutgoingCallsParams) async throws + -> CallHierarchyOutgoingCallsResponse + { try await sendRequest(.callHierarchyOutgoingCalls(params, ClientRequest.NullHandler)) } - func completion(params: CompletionParams) async throws -> CompletionResponse { - try await sendRequest(.completion(params, ClientRequest.NullHandler)) - } + public func completion(params: CompletionParams) async throws -> CompletionResponse { + try await sendRequest(.completion(params, ClientRequest.NullHandler)) + } - func hover(params: TextDocumentPositionParams) async throws -> HoverResponse { - try await sendRequest(.hover(params, ClientRequest.NullHandler)) - } + public func hover(params: TextDocumentPositionParams) async throws -> HoverResponse { + try await sendRequest(.hover(params, ClientRequest.NullHandler)) + } - func signatureHelp(params: TextDocumentPositionParams) async throws -> SignatureHelpResponse { - try await sendRequest(.signatureHelp(params, ClientRequest.NullHandler)) - } + public func signatureHelp(params: TextDocumentPositionParams) async throws + -> SignatureHelpResponse + { + try await sendRequest(.signatureHelp(params, ClientRequest.NullHandler)) + } - func declaration(params: TextDocumentPositionParams) async throws -> DeclarationResponse { - try await sendRequest(.declaration(params, ClientRequest.NullHandler)) - } + public func declaration(params: TextDocumentPositionParams) async throws -> DeclarationResponse + { + try await sendRequest(.declaration(params, ClientRequest.NullHandler)) + } - func definition(params: TextDocumentPositionParams) async throws -> DefinitionResponse { - try await sendRequest(.definition(params, ClientRequest.NullHandler)) - } + public func definition(params: TextDocumentPositionParams) async throws -> DefinitionResponse { + try await sendRequest(.definition(params, ClientRequest.NullHandler)) + } - func typeDefinition(params: TextDocumentPositionParams) async throws -> TypeDefinitionResponse { - try await sendRequest(.typeDefinition(params, ClientRequest.NullHandler)) - } + public func typeDefinition(params: TextDocumentPositionParams) async throws + -> TypeDefinitionResponse + { + try await sendRequest(.typeDefinition(params, ClientRequest.NullHandler)) + } - func implementation(params: TextDocumentPositionParams) async throws -> ImplementationResponse { - try await sendRequest(.implementation(params, ClientRequest.NullHandler)) - } + public func implementation(params: TextDocumentPositionParams) async throws + -> ImplementationResponse + { + try await sendRequest(.implementation(params, ClientRequest.NullHandler)) + } - func documentSymbol(params: DocumentSymbolParams) async throws -> DocumentSymbolResponse { - try await sendRequest(.documentSymbol(params, ClientRequest.NullHandler)) - } + public func documentSymbol(params: DocumentSymbolParams) async throws -> DocumentSymbolResponse + { + try await sendRequest(.documentSymbol(params, ClientRequest.NullHandler)) + } - func prepareCallHierarchy(params: CallHierarchyPrepareParams) async throws -> CallHierarchyPrepareResponse { - try await sendRequest(.prepareCallHierarchy(params, ClientRequest.NullHandler)) - } + public func prepareCallHierarchy(params: CallHierarchyPrepareParams) async throws + -> CallHierarchyPrepareResponse + { + try await sendRequest(.prepareCallHierarchy(params, ClientRequest.NullHandler)) + } - func prepareRename(params: PrepareRenameParams) async throws -> PrepareRenameResponse { - try await sendRequest(.prepareRename(params, ClientRequest.NullHandler)) - } + public func prepareRename(params: PrepareRenameParams) async throws -> PrepareRenameResponse { + try await sendRequest(.prepareRename(params, ClientRequest.NullHandler)) + } - func prepareTypeHeirarchy(params: TypeHierarchyPrepareParams) async throws -> PrepareTypeHeirarchyResponse { + public func prepareTypeHeirarchy(params: TypeHierarchyPrepareParams) async throws + -> PrepareTypeHeirarchyResponse + { try await sendRequest(.prepareTypeHierarchy(params, ClientRequest.NullHandler)) } - func rename(params: RenameParams) async throws -> RenameResponse { - try await sendRequest(.rename(params, ClientRequest.NullHandler)) - } - - func formatting(params: DocumentFormattingParams) async throws -> FormattingResult { - try await sendRequest(.formatting(params, ClientRequest.NullHandler)) - } + public func rename(params: RenameParams) async throws -> RenameResponse { + try await sendRequest(.rename(params, ClientRequest.NullHandler)) + } - func rangeFormatting(params: DocumentRangeFormattingParams) async throws -> FormattingResult { - try await sendRequest(.rangeFormatting(params, ClientRequest.NullHandler)) - } + public func formatting(params: DocumentFormattingParams) async throws -> FormattingResult { + try await sendRequest(.formatting(params, ClientRequest.NullHandler)) + } - func onTypeFormatting(params: DocumentOnTypeFormattingParams) async throws -> FormattingResult { - try await sendRequest(.onTypeFormatting(params, ClientRequest.NullHandler)) - } + public func rangeFormatting(params: DocumentRangeFormattingParams) async throws + -> FormattingResult + { + try await sendRequest(.rangeFormatting(params, ClientRequest.NullHandler)) + } - func references(params: ReferenceParams) async throws -> ReferenceResponse { - try await sendRequest(.references(params, ClientRequest.NullHandler)) - } + public func onTypeFormatting(params: DocumentOnTypeFormattingParams) async throws + -> FormattingResult + { + try await sendRequest(.onTypeFormatting(params, ClientRequest.NullHandler)) + } - func foldingRange(params: FoldingRangeParams) async throws -> FoldingRangeResponse { - try await sendRequest(.foldingRange(params, ClientRequest.NullHandler)) - } + public func references(params: ReferenceParams) async throws -> ReferenceResponse { + try await sendRequest(.references(params, ClientRequest.NullHandler)) + } - func semanticTokensFull(params: SemanticTokensParams) async throws -> SemanticTokensResponse { - try await sendRequest(.semanticTokensFull(params, ClientRequest.NullHandler)) - } + public func foldingRange(params: FoldingRangeParams) async throws -> FoldingRangeResponse { + try await sendRequest(.foldingRange(params, ClientRequest.NullHandler)) + } - func semanticTokensFullDelta(params: SemanticTokensDeltaParams) async throws -> SemanticTokensDeltaResponse { - try await sendRequest(.semanticTokensFullDelta(params, ClientRequest.NullHandler)) - } + public func semanticTokensFull(params: SemanticTokensParams) async throws + -> SemanticTokensResponse + { + try await sendRequest(.semanticTokensFull(params, ClientRequest.NullHandler)) + } - func semanticTokensRange(params: SemanticTokensRangeParams) async throws -> SemanticTokensResponse { - try await sendRequest(.semanticTokensRange(params, ClientRequest.NullHandler)) - } + public func semanticTokensFullDelta(params: SemanticTokensDeltaParams) async throws + -> SemanticTokensDeltaResponse + { + try await sendRequest(.semanticTokensFullDelta(params, ClientRequest.NullHandler)) + } + public func semanticTokensRange(params: SemanticTokensRangeParams) async throws + -> SemanticTokensResponse + { + try await sendRequest(.semanticTokensRange(params, ClientRequest.NullHandler)) + } - func customRequest(method: String, params: LSPAny) async throws -> Response { - try await sendRequest(.custom(method, params, ClientRequest.NullHandler)) - } + public func customRequest(method: String, params: LSPAny) + async throws -> Response + { + try await sendRequest(.custom(method, params, ClientRequest.NullHandler)) + } } // Workspace notifications -public extension ServerConnection { - func didChangeWorkspaceFolders(params: DidChangeWorkspaceFoldersParams) async throws { - try await sendNotification(.workspaceDidChangeWorkspaceFolders(params)) - } +extension ServerConnection { + public func didChangeWorkspaceFolders(params: DidChangeWorkspaceFoldersParams) async throws { + try await sendNotification(.workspaceDidChangeWorkspaceFolders(params)) + } - func didChangeConfiguration(params: DidChangeConfigurationParams) async throws { + public func didChangeConfiguration(params: DidChangeConfigurationParams) async throws { try await sendNotification(.workspaceDidChangeConfiguration(params)) - } + } - func didCreateFiles(params: CreateFilesParams) async throws { + public func didCreateFiles(params: CreateFilesParams) async throws { try await sendNotification(.workspaceDidCreateFiles(params)) - } + } - func didRenameFiles(params: RenameFilesParams) async throws { + public func didRenameFiles(params: RenameFilesParams) async throws { try await sendNotification(.workspaceDidRenameFiles(params)) - } + } - func didDeleteFiles(params: DeleteFilesParams) async throws { + public func didDeleteFiles(params: DeleteFilesParams) async throws { try await sendNotification(.workspaceDidDeleteFiles(params)) - } + } } // Workspace Requests -public extension ServerConnection { - func inlayHintRefresh() async throws { - try await sendRequestWithErrorOnlyResult(.workspaceInlayHintRefresh(ClientRequest.NullHandler)) +extension ServerConnection { + public func inlayHintRefresh() async throws { + try await sendRequestWithErrorOnlyResult( + .workspaceInlayHintRefresh(ClientRequest.NullHandler)) } - func willCreateFiles(params: CreateFilesParams) async throws -> WorkspaceWillCreateFilesResponse { - try await sendRequest(.workspaceWillCreateFiles(params, ClientRequest.NullHandler)) - } + public func willCreateFiles(params: CreateFilesParams) async throws + -> WorkspaceWillCreateFilesResponse + { + try await sendRequest(.workspaceWillCreateFiles(params, ClientRequest.NullHandler)) + } - func willRenameFiles(params: RenameFilesParams) async throws -> WorkspaceWillRenameFilesResponse { - try await sendRequest(.workspaceWillRenameFiles(params, ClientRequest.NullHandler)) - } + public func willRenameFiles(params: RenameFilesParams) async throws + -> WorkspaceWillRenameFilesResponse + { + try await sendRequest(.workspaceWillRenameFiles(params, ClientRequest.NullHandler)) + } - func willDeleteFiles(params: DeleteFilesParams) async throws -> WorkspaceWillDeleteFilesResponse { - try await sendRequest(.workspaceWillDeleteFiles(params, ClientRequest.NullHandler)) - } + public func willDeleteFiles(params: DeleteFilesParams) async throws + -> WorkspaceWillDeleteFilesResponse + { + try await sendRequest(.workspaceWillDeleteFiles(params, ClientRequest.NullHandler)) + } - func executeCommand(params: ExecuteCommandParams) async throws -> ExecuteCommandResponse { - try await sendRequest(.workspaceExecuteCommand(params, ClientRequest.NullHandler)) - } + public func executeCommand(params: ExecuteCommandParams) async throws -> ExecuteCommandResponse + { + try await sendRequest(.workspaceExecuteCommand(params, ClientRequest.NullHandler)) + } - func workspaceSymbol(params: WorkspaceSymbolParams) async throws -> WorkspaceSymbolResponse { - try await sendRequest(.workspaceSymbol(params, ClientRequest.NullHandler)) - } + public func workspaceSymbol(params: WorkspaceSymbolParams) async throws + -> WorkspaceSymbolResponse + { + try await sendRequest(.workspaceSymbol(params, ClientRequest.NullHandler)) + } - func workspaceSymbolResolve(params: WorkspaceSymbol) async throws -> WorkspaceSymbolResponse { - try await sendRequest(.workspaceSymbolResolve(params, ClientRequest.NullHandler)) - } + public func workspaceSymbolResolve(params: WorkspaceSymbol) async throws + -> WorkspaceSymbolResponse + { + try await sendRequest(.workspaceSymbolResolve(params, ClientRequest.NullHandler)) + } } // Language Features -public extension ServerConnection { - func documentHighlight(params: DocumentHighlightParams) async throws -> DocumentHighlightResponse { - try await sendRequest(.documentHighlight(params, ClientRequest.NullHandler)) - } +extension ServerConnection { + public func documentHighlight(params: DocumentHighlightParams) async throws + -> DocumentHighlightResponse + { + try await sendRequest(.documentHighlight(params, ClientRequest.NullHandler)) + } - func codeAction(params: CodeActionParams) async throws -> CodeActionResponse { + public func codeAction(params: CodeActionParams) async throws -> CodeActionResponse { try await sendRequest(.codeAction(params, ClientRequest.NullHandler)) } - func codeActionResolve(params: CodeAction) async throws -> CodeAction { + public func codeActionResolve(params: CodeAction) async throws -> CodeAction { try await sendRequest(.codeActionResolve(params, ClientRequest.NullHandler)) } - func codeLens(params: CodeLensParams) async throws -> CodeLensResponse { - try await sendRequest(.codeLens(params, ClientRequest.NullHandler)) - } + public func codeLens(params: CodeLensParams) async throws -> CodeLensResponse { + try await sendRequest(.codeLens(params, ClientRequest.NullHandler)) + } - func codeLensResolve(params: CodeLens) async throws -> CodeLensResolveResponse { - try await sendRequest(.codeLensResolve(params, ClientRequest.NullHandler)) - } + public func codeLensResolve(params: CodeLens) async throws -> CodeLensResolveResponse { + try await sendRequest(.codeLensResolve(params, ClientRequest.NullHandler)) + } - func diagnostics(params: DocumentDiagnosticParams) async throws -> DocumentDiagnosticReport { + public func diagnostics(params: DocumentDiagnosticParams) async throws + -> DocumentDiagnosticReport + { try await sendRequest(.diagnostics(params, ClientRequest.NullHandler)) } - func selectionRange(params: SelectionRangeParams) async throws -> SelectionRangeResponse { - try await sendRequest(.selectionRange(params, ClientRequest.NullHandler)) - } + public func selectionRange(params: SelectionRangeParams) async throws -> SelectionRangeResponse + { + try await sendRequest(.selectionRange(params, ClientRequest.NullHandler)) + } - func documentLink(params: DocumentLinkParams) async throws -> DocumentLinkResponse { - try await sendRequest(.documentLink(params, ClientRequest.NullHandler)) - } + public func documentLink(params: DocumentLinkParams) async throws -> DocumentLinkResponse { + try await sendRequest(.documentLink(params, ClientRequest.NullHandler)) + } - func documentLinkResolve(params: DocumentLink) async throws -> DocumentLink { - try await sendRequest(.documentLinkResolve(params, ClientRequest.NullHandler)) - } + public func documentLinkResolve(params: DocumentLink) async throws -> DocumentLink { + try await sendRequest(.documentLinkResolve(params, ClientRequest.NullHandler)) + } - func documentColor(params: DocumentColorParams) async throws -> DocumentColorResponse { - try await sendRequest(.documentColor(params, ClientRequest.NullHandler)) - } + public func documentColor(params: DocumentColorParams) async throws -> DocumentColorResponse { + try await sendRequest(.documentColor(params, ClientRequest.NullHandler)) + } - func colorPresentation(params: ColorPresentationParams) async throws -> ColorPresentationResponse { - try await sendRequest(.colorPresentation(params, ClientRequest.NullHandler)) - } + public func colorPresentation(params: ColorPresentationParams) async throws + -> ColorPresentationResponse + { + try await sendRequest(.colorPresentation(params, ClientRequest.NullHandler)) + } - func inlayHint(params: InlayHintParams) async throws -> InlayHintResponse { + public func inlayHint(params: InlayHintParams) async throws -> InlayHintResponse { try await sendRequest(.inlayHint(params, ClientRequest.NullHandler)) } - func inlayHintResolve(params: InlayHint) async throws -> InlayHint { + public func inlayHintResolve(params: InlayHint) async throws -> InlayHint { try await sendRequest(.inlayHintResolve(params, ClientRequest.NullHandler)) } } diff --git a/Sources/LanguageServerProtocol/ClientCapabilities.swift b/Sources/LanguageServerProtocol/ClientCapabilities.swift index d2db485..ffb2ed2 100644 --- a/Sources/LanguageServerProtocol/ClientCapabilities.swift +++ b/Sources/LanguageServerProtocol/ClientCapabilities.swift @@ -1,46 +1,49 @@ import Foundation public struct DynamicRegistrationClientCapabilities: Codable, Hashable, Sendable { - public var dynamicRegistration: Bool? + public var dynamicRegistration: Bool? - public init(dynamicRegistration: Bool) { - self.dynamicRegistration = dynamicRegistration - } + public init(dynamicRegistration: Bool) { + self.dynamicRegistration = dynamicRegistration + } } public struct DynamicRegistrationLinkSupportClientCapabilities: Codable, Hashable, Sendable { - public var dynamicRegistration: Bool? - public var linkSupport: Bool? + public var dynamicRegistration: Bool? + public var linkSupport: Bool? - public init(dynamicRegistration: Bool, linkSupport: Bool) { - self.dynamicRegistration = dynamicRegistration - self.linkSupport = linkSupport - } + public init(dynamicRegistration: Bool, linkSupport: Bool) { + self.dynamicRegistration = dynamicRegistration + self.linkSupport = linkSupport + } } public enum ResourceOperationKind: String, Codable, Hashable, Sendable { - case create - case rename - case delete + case create + case rename + case delete } public enum FailureHandlingKind: String, Codable, Hashable, Sendable { - case abort - case transactional - case textOnlyTransactional - case undo + case abort + case transactional + case textOnlyTransactional + case undo } public struct WorkspaceClientCapabilityEdit: Codable, Hashable, Sendable { - public let documentChanges: Bool? - public let resourceOperations: [ResourceOperationKind] - public let failureHandling: FailureHandlingKind? - - public init(documentChanges: Bool?, resourceOperations: [ResourceOperationKind], failureHandling: FailureHandlingKind?) { - self.documentChanges = documentChanges - self.resourceOperations = resourceOperations - self.failureHandling = failureHandling - } + public let documentChanges: Bool? + public let resourceOperations: [ResourceOperationKind] + public let failureHandling: FailureHandlingKind? + + public init( + documentChanges: Bool?, resourceOperations: [ResourceOperationKind], + failureHandling: FailureHandlingKind? + ) { + self.documentChanges = documentChanges + self.resourceOperations = resourceOperations + self.failureHandling = failureHandling + } } public typealias DidChangeConfigurationClientCapabilities = GenericDynamicRegistration @@ -48,244 +51,259 @@ public typealias DidChangeConfigurationClientCapabilities = GenericDynamicRegist public typealias DidChangeWatchedFilesClientCapabilities = GenericDynamicRegistration public struct ShowDocumentClientCapabilities: Hashable, Codable, Sendable { - public var support: Bool + public var support: Bool } public struct ShowMessageRequestClientCapabilities: Hashable, Codable, Sendable { - public struct MessageActionItemCapabilities: Hashable, Codable, Sendable { - public var additionalPropertiesSupport: Bool - } + public struct MessageActionItemCapabilities: Hashable, Codable, Sendable { + public var additionalPropertiesSupport: Bool + } - public var messageActionItem: MessageActionItemCapabilities + public var messageActionItem: MessageActionItemCapabilities - init(messageActionItem: MessageActionItemCapabilities) { - self.messageActionItem = messageActionItem - } + init(messageActionItem: MessageActionItemCapabilities) { + self.messageActionItem = messageActionItem + } } public struct WindowClientCapabilities: Hashable, Codable, Sendable { - public var workDoneProgress: Bool - public var showMessage: ShowMessageRequestClientCapabilities - public var showDocument: ShowDocumentClientCapabilities - - public init(workDoneProgress: Bool, showMessage: ShowMessageRequestClientCapabilities, showDocument: ShowDocumentClientCapabilities) { - self.workDoneProgress = workDoneProgress - self.showMessage = showMessage - self.showDocument = showDocument - } + public var workDoneProgress: Bool + public var showMessage: ShowMessageRequestClientCapabilities + public var showDocument: ShowDocumentClientCapabilities + + public init( + workDoneProgress: Bool, showMessage: ShowMessageRequestClientCapabilities, + showDocument: ShowDocumentClientCapabilities + ) { + self.workDoneProgress = workDoneProgress + self.showMessage = showMessage + self.showDocument = showDocument + } } public struct RegularExpressionsClientCapabilities: Hashable, Codable, Sendable { - public var engine: String - public var version: String? + public var engine: String + public var version: String? - public init(engine: String, version: String? = nil) { - self.engine = engine - self.version = version - } + public init(engine: String, version: String? = nil) { + self.engine = engine + self.version = version + } } public struct MarkdownClientCapabilities: Hashable, Codable, Sendable { - public var parser: String - public var version: String? - public var allowedTags: [String]? - - public init(parser: String, version: String? = nil, allowedTags: [String]? = nil) { - self.parser = parser - self.version = version - self.allowedTags = allowedTags - } + public var parser: String + public var version: String? + public var allowedTags: [String]? + + public init(parser: String, version: String? = nil, allowedTags: [String]? = nil) { + self.parser = parser + self.version = version + self.allowedTags = allowedTags + } } public struct GeneralClientCapabilities: Hashable, Codable, Sendable { - public var regularExpressions: RegularExpressionsClientCapabilities? - public var markdown: MarkdownClientCapabilities? - - public init(regularExpressions: RegularExpressionsClientCapabilities?, markdown: MarkdownClientCapabilities?) { - self.regularExpressions = regularExpressions - self.markdown = markdown - } + public var regularExpressions: RegularExpressionsClientCapabilities? + public var markdown: MarkdownClientCapabilities? + + public init( + regularExpressions: RegularExpressionsClientCapabilities?, + markdown: MarkdownClientCapabilities? + ) { + self.regularExpressions = regularExpressions + self.markdown = markdown + } } public struct TextDocumentSyncClientCapabilities: Codable, Hashable, Sendable { - public let dynamicRegistration: Bool? - public let willSave: Bool? - public let willSaveWaitUntil: Bool? - public let didSave: Bool? - - public init(dynamicRegistration: Bool, willSave: Bool, willSaveWaitUntil: Bool, didSave: Bool) { - self.dynamicRegistration = dynamicRegistration - self.willSave = willSave - self.willSaveWaitUntil = willSaveWaitUntil - self.didSave = didSave - } + public let dynamicRegistration: Bool? + public let willSave: Bool? + public let willSaveWaitUntil: Bool? + public let didSave: Bool? + + public init(dynamicRegistration: Bool, willSave: Bool, willSaveWaitUntil: Bool, didSave: Bool) { + self.dynamicRegistration = dynamicRegistration + self.willSave = willSave + self.willSaveWaitUntil = willSaveWaitUntil + self.didSave = didSave + } } public struct TextDocumentClientCapabilities: Codable, Hashable, Sendable { - public var synchronization: TextDocumentSyncClientCapabilities? - public var completion: CompletionClientCapabilities? - public var hover: HoverClientCapabilities? - public var signatureHelp: SignatureHelpClientCapabilities? - public var declaration: DeclarationClientCapabilities? - public var definition: DefinitionClientCapabilities? - public var typeDefinition: TypeDefinitionClientCapabilities? - public var implementation: ImplementationClientCapabilities? - public var references: ReferenceClientCapabilities? - public var documentHighlight: DocumentHighlightClientCapabilities? - public var documentSymbol: DocumentSymbolClientCapabilities? - public var codeAction: CodeActionClientCapabilities? - public var codeLens: CodeLensClientCapabilities? - public var documentLink: DocumentLinkClientCapabilities? - public var colorProvider: DocumentColorClientCapabilities? - public var formatting: DocumentFormattingClientCapabilities? - public var rangeFormatting: DocumentRangeFormattingClientCapabilities? - public var onTypeFormatting: DocumentOnTypeFormattingClientCapabilities? - public var rename: RenameClientCapabilities? - public var publishDiagnostics: PublishDiagnosticsClientCapabilities? - public var foldingRange: FoldingRangeClientCapabilities? - public var selectionRange: SelectionRangeClientCapabilities? - public var linkedEditingRange: LinkedEditingRangeClientCapabilities? - public var callHierarchy: CallHierarchyClientCapabilities? - public var semanticTokens: SemanticTokensClientCapabilities? - public var moniker: MonikerClientCapabilities? + public var synchronization: TextDocumentSyncClientCapabilities? + public var completion: CompletionClientCapabilities? + public var hover: HoverClientCapabilities? + public var signatureHelp: SignatureHelpClientCapabilities? + public var declaration: DeclarationClientCapabilities? + public var definition: DefinitionClientCapabilities? + public var typeDefinition: TypeDefinitionClientCapabilities? + public var implementation: ImplementationClientCapabilities? + public var references: ReferenceClientCapabilities? + public var documentHighlight: DocumentHighlightClientCapabilities? + public var documentSymbol: DocumentSymbolClientCapabilities? + public var codeAction: CodeActionClientCapabilities? + public var codeLens: CodeLensClientCapabilities? + public var documentLink: DocumentLinkClientCapabilities? + public var colorProvider: DocumentColorClientCapabilities? + public var formatting: DocumentFormattingClientCapabilities? + public var rangeFormatting: DocumentRangeFormattingClientCapabilities? + public var onTypeFormatting: DocumentOnTypeFormattingClientCapabilities? + public var rename: RenameClientCapabilities? + public var publishDiagnostics: PublishDiagnosticsClientCapabilities? + public var foldingRange: FoldingRangeClientCapabilities? + public var selectionRange: SelectionRangeClientCapabilities? + public var linkedEditingRange: LinkedEditingRangeClientCapabilities? + public var callHierarchy: CallHierarchyClientCapabilities? + public var semanticTokens: SemanticTokensClientCapabilities? + public var moniker: MonikerClientCapabilities? public var inlayHint: InlayHintClientCapabilities? public var diagnostic: DiagnosticClientCapabilities? - public init(synchronization: TextDocumentSyncClientCapabilities? = nil, - completion: CompletionClientCapabilities? = nil, - hover: HoverClientCapabilities? = nil, - signatureHelp: SignatureHelpClientCapabilities? = nil, - declaration: DeclarationClientCapabilities? = nil, - definition: DefinitionClientCapabilities? = nil, - typeDefinition: TypeDefinitionClientCapabilities? = nil, - implementation: ImplementationClientCapabilities? = nil, - references: ReferenceClientCapabilities? = nil, - documentHighlight: DocumentHighlightClientCapabilities? = nil, - documentSymbol: DocumentSymbolClientCapabilities? = nil, - codeAction: CodeActionClientCapabilities? = nil, - codeLens: CodeLensClientCapabilities? = nil, - documentLink: DocumentLinkClientCapabilities? = nil, - colorProvider: DocumentColorClientCapabilities? = nil, - formatting: DocumentFormattingClientCapabilities? = nil, - rangeFormatting: DocumentRangeFormattingClientCapabilities? = nil, - onTypeFormatting: DocumentOnTypeFormattingClientCapabilities? = nil, - rename: RenameClientCapabilities? = nil, - publishDiagnostics: PublishDiagnosticsClientCapabilities? = nil, - foldingRange: FoldingRangeClientCapabilities? = nil, - selectionRange: SelectionRangeClientCapabilities? = nil, - linkedEditingRange: LinkedEditingRangeClientCapabilities? = nil, - callHierarchy: CallHierarchyClientCapabilities? = nil, - semanticTokens: SemanticTokensClientCapabilities? = nil, - moniker: MonikerClientCapabilities? = nil, - inlayHint: InlayHintClientCapabilities? = nil, - diagnostic: DiagnosticClientCapabilities? = nil) { - self.synchronization = synchronization - self.completion = completion - self.hover = hover - self.signatureHelp = signatureHelp - self.declaration = declaration - self.definition = definition - self.typeDefinition = typeDefinition - self.implementation = implementation - self.references = references - self.documentHighlight = documentHighlight - self.documentSymbol = documentSymbol - self.codeAction = codeAction - self.codeLens = codeLens - self.documentLink = documentLink - self.colorProvider = colorProvider - self.formatting = formatting - self.rangeFormatting = rangeFormatting - self.onTypeFormatting = onTypeFormatting - self.rename = rename - self.publishDiagnostics = publishDiagnostics - self.foldingRange = foldingRange - self.selectionRange = selectionRange - self.linkedEditingRange = linkedEditingRange - self.callHierarchy = callHierarchy - self.semanticTokens = semanticTokens - self.moniker = moniker + public init( + synchronization: TextDocumentSyncClientCapabilities? = nil, + completion: CompletionClientCapabilities? = nil, + hover: HoverClientCapabilities? = nil, + signatureHelp: SignatureHelpClientCapabilities? = nil, + declaration: DeclarationClientCapabilities? = nil, + definition: DefinitionClientCapabilities? = nil, + typeDefinition: TypeDefinitionClientCapabilities? = nil, + implementation: ImplementationClientCapabilities? = nil, + references: ReferenceClientCapabilities? = nil, + documentHighlight: DocumentHighlightClientCapabilities? = nil, + documentSymbol: DocumentSymbolClientCapabilities? = nil, + codeAction: CodeActionClientCapabilities? = nil, + codeLens: CodeLensClientCapabilities? = nil, + documentLink: DocumentLinkClientCapabilities? = nil, + colorProvider: DocumentColorClientCapabilities? = nil, + formatting: DocumentFormattingClientCapabilities? = nil, + rangeFormatting: DocumentRangeFormattingClientCapabilities? = nil, + onTypeFormatting: DocumentOnTypeFormattingClientCapabilities? = nil, + rename: RenameClientCapabilities? = nil, + publishDiagnostics: PublishDiagnosticsClientCapabilities? = nil, + foldingRange: FoldingRangeClientCapabilities? = nil, + selectionRange: SelectionRangeClientCapabilities? = nil, + linkedEditingRange: LinkedEditingRangeClientCapabilities? = nil, + callHierarchy: CallHierarchyClientCapabilities? = nil, + semanticTokens: SemanticTokensClientCapabilities? = nil, + moniker: MonikerClientCapabilities? = nil, + inlayHint: InlayHintClientCapabilities? = nil, + diagnostic: DiagnosticClientCapabilities? = nil + ) { + self.synchronization = synchronization + self.completion = completion + self.hover = hover + self.signatureHelp = signatureHelp + self.declaration = declaration + self.definition = definition + self.typeDefinition = typeDefinition + self.implementation = implementation + self.references = references + self.documentHighlight = documentHighlight + self.documentSymbol = documentSymbol + self.codeAction = codeAction + self.codeLens = codeLens + self.documentLink = documentLink + self.colorProvider = colorProvider + self.formatting = formatting + self.rangeFormatting = rangeFormatting + self.onTypeFormatting = onTypeFormatting + self.rename = rename + self.publishDiagnostics = publishDiagnostics + self.foldingRange = foldingRange + self.selectionRange = selectionRange + self.linkedEditingRange = linkedEditingRange + self.callHierarchy = callHierarchy + self.semanticTokens = semanticTokens + self.moniker = moniker self.diagnostic = diagnostic - } + } } public struct ClientCapabilities: Codable, Hashable, Sendable { - public struct Workspace: Codable, Hashable, Sendable { - public struct FileOperations: Codable, Hashable, Sendable { - public var dynamicRegistration: Bool? - public var didCreate: Bool? - public var willCreate: Bool? - public var didRename: Bool? - public var willRename: Bool? - public var didDelete: Bool? - public var willDelete: Bool? - - public init(dynamicRegistration: Bool? = nil, - didCreate: Bool? = nil, - willCreate: Bool? = nil, - didRename: Bool? = nil, - willRename: Bool? = nil, - didDelete: Bool? = nil, - willDelete: Bool? = nil) { - self.dynamicRegistration = dynamicRegistration - self.didCreate = didCreate - self.willCreate = willCreate - self.didRename = didRename - self.willRename = willRename - self.didDelete = didDelete - self.willDelete = willDelete - } - } - - public let applyEdit: Bool? - public let workspaceEdit: WorkspaceClientCapabilityEdit? - public let didChangeConfiguration: DidChangeConfigurationClientCapabilities? - public let didChangeWatchedFiles: GenericDynamicRegistration? - public let symbol: WorkspaceSymbolClientCapabilities? - public let executeCommand: GenericDynamicRegistration? - public let workspaceFolders: Bool? - public let configuration: Bool? - public let semanticTokens: SemanticTokensWorkspaceClientCapabilities? - public let codeLens: CodeLensWorkspaceClientCapabilities? - public let fileOperations: FileOperations? - - public init(applyEdit: Bool, - workspaceEdit: WorkspaceClientCapabilityEdit?, - didChangeConfiguration: DidChangeConfigurationClientCapabilities?, - didChangeWatchedFiles: GenericDynamicRegistration?, - symbol: WorkspaceSymbolClientCapabilities?, - executeCommand: GenericDynamicRegistration?, - workspaceFolders: Bool?, - configuration: Bool?, - semanticTokens: SemanticTokensWorkspaceClientCapabilities?, - codeLens: CodeLensWorkspaceClientCapabilities? = nil, - fileOperations: FileOperations? = nil) { - self.applyEdit = applyEdit - self.workspaceEdit = workspaceEdit - self.didChangeConfiguration = didChangeConfiguration - self.didChangeWatchedFiles = didChangeWatchedFiles - self.symbol = symbol - self.executeCommand = executeCommand - self.workspaceFolders = workspaceFolders - self.configuration = configuration - self.semanticTokens = semanticTokens - self.codeLens = codeLens - self.fileOperations = fileOperations - } - } - - - public let workspace: Workspace? - public let textDocument: TextDocumentClientCapabilities? - public var window: WindowClientCapabilities? - public var general: GeneralClientCapabilities? - public let experimental: LSPAny? - - public init(workspace: Workspace?, textDocument: TextDocumentClientCapabilities?, window: WindowClientCapabilities?, general: GeneralClientCapabilities?, experimental: LSPAny?) { - self.workspace = workspace - self.textDocument = textDocument - self.window = window - self.general = general - self.experimental = experimental - } + public struct Workspace: Codable, Hashable, Sendable { + public struct FileOperations: Codable, Hashable, Sendable { + public var dynamicRegistration: Bool? + public var didCreate: Bool? + public var willCreate: Bool? + public var didRename: Bool? + public var willRename: Bool? + public var didDelete: Bool? + public var willDelete: Bool? + + public init( + dynamicRegistration: Bool? = nil, + didCreate: Bool? = nil, + willCreate: Bool? = nil, + didRename: Bool? = nil, + willRename: Bool? = nil, + didDelete: Bool? = nil, + willDelete: Bool? = nil + ) { + self.dynamicRegistration = dynamicRegistration + self.didCreate = didCreate + self.willCreate = willCreate + self.didRename = didRename + self.willRename = willRename + self.didDelete = didDelete + self.willDelete = willDelete + } + } + + public let applyEdit: Bool? + public let workspaceEdit: WorkspaceClientCapabilityEdit? + public let didChangeConfiguration: DidChangeConfigurationClientCapabilities? + public let didChangeWatchedFiles: GenericDynamicRegistration? + public let symbol: WorkspaceSymbolClientCapabilities? + public let executeCommand: GenericDynamicRegistration? + public let workspaceFolders: Bool? + public let configuration: Bool? + public let semanticTokens: SemanticTokensWorkspaceClientCapabilities? + public let codeLens: CodeLensWorkspaceClientCapabilities? + public let fileOperations: FileOperations? + + public init( + applyEdit: Bool, + workspaceEdit: WorkspaceClientCapabilityEdit?, + didChangeConfiguration: DidChangeConfigurationClientCapabilities?, + didChangeWatchedFiles: GenericDynamicRegistration?, + symbol: WorkspaceSymbolClientCapabilities?, + executeCommand: GenericDynamicRegistration?, + workspaceFolders: Bool?, + configuration: Bool?, + semanticTokens: SemanticTokensWorkspaceClientCapabilities?, + codeLens: CodeLensWorkspaceClientCapabilities? = nil, + fileOperations: FileOperations? = nil + ) { + self.applyEdit = applyEdit + self.workspaceEdit = workspaceEdit + self.didChangeConfiguration = didChangeConfiguration + self.didChangeWatchedFiles = didChangeWatchedFiles + self.symbol = symbol + self.executeCommand = executeCommand + self.workspaceFolders = workspaceFolders + self.configuration = configuration + self.semanticTokens = semanticTokens + self.codeLens = codeLens + self.fileOperations = fileOperations + } + } + + public let workspace: Workspace? + public let textDocument: TextDocumentClientCapabilities? + public var window: WindowClientCapabilities? + public var general: GeneralClientCapabilities? + public let experimental: LSPAny? + + public init( + workspace: Workspace?, textDocument: TextDocumentClientCapabilities?, + window: WindowClientCapabilities?, general: GeneralClientCapabilities?, + experimental: LSPAny? + ) { + self.workspace = workspace + self.textDocument = textDocument + self.window = window + self.general = general + self.experimental = experimental + } } diff --git a/Sources/LanguageServerProtocol/Framing/AsyncByteSequence.swift b/Sources/LanguageServerProtocol/Framing/AsyncByteSequence.swift index b4c2fb6..4ed176b 100644 --- a/Sources/LanguageServerProtocol/Framing/AsyncByteSequence.swift +++ b/Sources/LanguageServerProtocol/Framing/AsyncByteSequence.swift @@ -1,10 +1,10 @@ import Foundation /// Converts a sequence of Data objects into a sequence of bytes. -struct AsyncByteSequence : AsyncSequence where Base : AsyncSequence, Base.Element == Data { +struct AsyncByteSequence: AsyncSequence where Base: AsyncSequence, Base.Element == Data { public typealias Element = UInt8 - public struct AsyncIterator : AsyncIteratorProtocol { + public struct AsyncIterator: AsyncIteratorProtocol { private enum State { case idle case enumerating(Data, Data.Index) diff --git a/Sources/LanguageServerProtocol/Framing/AsyncMessageFramingSequence.swift b/Sources/LanguageServerProtocol/Framing/AsyncMessageFramingSequence.swift index d4ed177..a0726a7 100644 --- a/Sources/LanguageServerProtocol/Framing/AsyncMessageFramingSequence.swift +++ b/Sources/LanguageServerProtocol/Framing/AsyncMessageFramingSequence.swift @@ -1,17 +1,18 @@ import Foundation /// Sequence that reads data framed by the LSP base protocol specification. -struct AsyncMessageFramingSequence : AsyncSequence where Base : AsyncSequence, Base.Element == UInt8 { +struct AsyncMessageFramingSequence: AsyncSequence +where Base: AsyncSequence, Base.Element == UInt8 { public typealias Element = Data - public struct AsyncIterator : AsyncIteratorProtocol { + public struct AsyncIterator: AsyncIteratorProtocol { private enum State { case buffering case expectingCR } private let linefeed: UInt8 = Character("\r").asciiValue! - private let newline: UInt8 = Character("\n").asciiValue! + private let newline: UInt8 = Character("\n").asciiValue! private var iterator: Base.AsyncIterator diff --git a/Sources/LanguageServerProtocol/Framing/DataChannel+MessageFraming.swift b/Sources/LanguageServerProtocol/Framing/DataChannel+MessageFraming.swift index d0b899e..8ec6452 100644 --- a/Sources/LanguageServerProtocol/Framing/DataChannel+MessageFraming.swift +++ b/Sources/LanguageServerProtocol/Framing/DataChannel+MessageFraming.swift @@ -23,7 +23,8 @@ extension DataChannel { continuation.finish() } - return DataChannel(writeHandler: writeHandler, - dataSequence: stream) + return DataChannel( + writeHandler: writeHandler, + dataSequence: stream) } } diff --git a/Sources/LanguageServerProtocol/General.swift b/Sources/LanguageServerProtocol/General.swift index b975414..11d0e05 100644 --- a/Sources/LanguageServerProtocol/General.swift +++ b/Sources/LanguageServerProtocol/General.swift @@ -1,9 +1,9 @@ import Foundation public enum Tracing: String, Codable, Hashable, Sendable { - case off - case messages - case verbose + case off + case messages + case verbose } public struct InitializeParams: Codable, Hashable, Sendable { @@ -17,38 +17,40 @@ public struct InitializeParams: Codable, Hashable, Sendable { } } - public let processId: Int? + public let processId: Int? public let clientInfo: ClientInfo? public let locale: String? - public let rootPath: String? - public let rootUri: DocumentUri? - public let initializationOptions: LSPAny? - public let capabilities: ClientCapabilities - public let trace: Tracing? - public let workspaceFolders: [WorkspaceFolder]? + public let rootPath: String? + public let rootUri: DocumentUri? + public let initializationOptions: LSPAny? + public let capabilities: ClientCapabilities + public let trace: Tracing? + public let workspaceFolders: [WorkspaceFolder]? - public init(processId: Int, - clientInfo: ClientInfo? = nil, - locale: String?, - rootPath: String?, - rootUri: DocumentUri?, - initializationOptions: LSPAny?, - capabilities: ClientCapabilities, - trace: Tracing?, - workspaceFolders: [WorkspaceFolder]?) { - self.processId = processId + public init( + processId: Int, + clientInfo: ClientInfo? = nil, + locale: String?, + rootPath: String?, + rootUri: DocumentUri?, + initializationOptions: LSPAny?, + capabilities: ClientCapabilities, + trace: Tracing?, + workspaceFolders: [WorkspaceFolder]? + ) { + self.processId = processId self.clientInfo = clientInfo self.locale = locale - self.rootPath = rootPath - self.rootUri = rootUri - self.initializationOptions = initializationOptions - self.capabilities = capabilities - self.trace = trace - self.workspaceFolders = workspaceFolders - } + self.rootPath = rootPath + self.rootUri = rootUri + self.initializationOptions = initializationOptions + self.capabilities = capabilities + self.trace = trace + self.workspaceFolders = workspaceFolders + } } -public struct ServerInfo : Codable, Hashable, Sendable { +public struct ServerInfo: Codable, Hashable, Sendable { /** * The name of the server as defined by the server. */ @@ -65,8 +67,8 @@ public struct ServerInfo : Codable, Hashable, Sendable { } } -public struct InitializationResponse : Codable, Hashable, Sendable { - public let capabilities: ServerCapabilities +public struct InitializationResponse: Codable, Hashable, Sendable { + public let capabilities: ServerCapabilities public let serverInfo: ServerInfo? public init(capabilities: ServerCapabilities, serverInfo: ServerInfo?) { @@ -75,8 +77,7 @@ public struct InitializationResponse : Codable, Hashable, Sendable { } } - public struct InitializedParams: Codable, Hashable, Sendable { - public init() { - } + public init() { + } } diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/CallHeirarchy.swift b/Sources/LanguageServerProtocol/LanguageFeatures/CallHeirarchy.swift index 48fa4c3..3de3ad1 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/CallHeirarchy.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/CallHeirarchy.swift @@ -4,14 +4,18 @@ public typealias CallHierarchyClientCapabilities = DynamicRegistrationClientCapa public typealias CallHierarchyOptions = WorkDoneProgressOptions -public typealias CallHierarchyRegistrationOptions = StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions +public typealias CallHierarchyRegistrationOptions = + StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions public struct CallHierarchyPrepareParams: Codable, Hashable, Sendable { public let textDocument: TextDocumentIdentifier public let position: Position public let workDoneToken: ProgressToken? - public init(textDocument: TextDocumentIdentifier, position: Position, workDoneToken: ProgressToken? = nil) { + public init( + textDocument: TextDocumentIdentifier, position: Position, + workDoneToken: ProgressToken? = nil + ) { self.textDocument = textDocument self.position = position self.workDoneToken = workDoneToken @@ -28,14 +32,16 @@ public struct CallHierarchyItem: Codable, Hashable, Sendable { public let selectionRange: LSPRange public let data: LSPAny? - public init(name: String, - kind: SymbolKind, - tag: [SymbolTag]? = nil, - detail: String? = nil, - uri: DocumentUri, - range: LSPRange, - selectionRange: LSPRange, - data: LSPAny? = nil) { + public init( + name: String, + kind: SymbolKind, + tag: [SymbolTag]? = nil, + detail: String? = nil, + uri: DocumentUri, + range: LSPRange, + selectionRange: LSPRange, + data: LSPAny? = nil + ) { self.name = name self.kind = kind self.tag = tag @@ -55,7 +61,10 @@ public struct CallHierarchyIncomingCallsParams: Codable, Hashable, Sendable { public let item: CallHierarchyItem - public init(item: CallHierarchyItem, workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil) { + public init( + item: CallHierarchyItem, workDoneToken: ProgressToken? = nil, + partialResultToken: ProgressToken? = nil + ) { self.workDoneToken = workDoneToken self.partialResultToken = partialResultToken self.item = item diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/CodeAction.swift b/Sources/LanguageServerProtocol/LanguageFeatures/CodeAction.swift index 838fa02..9391832 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/CodeAction.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/CodeAction.swift @@ -3,57 +3,59 @@ import Foundation public typealias CodeActionKind = String extension CodeActionKind { - public static let Empty: CodeActionKind = "" - public static let Quickfix: CodeActionKind = "quickfix" - public static let Refactor: CodeActionKind = "refactor" - public static let RefactorExtract: CodeActionKind = "refactor.extract" - public static let RefactorInline: CodeActionKind = "refactor.inline" - public static let RefactorRewrite: CodeActionKind = "refactor.rewrite" - public static let Source: CodeActionKind = "source" - public static let SourceOrganizeImports: CodeActionKind = "source.organizeImports" + public static let Empty: CodeActionKind = "" + public static let Quickfix: CodeActionKind = "quickfix" + public static let Refactor: CodeActionKind = "refactor" + public static let RefactorExtract: CodeActionKind = "refactor.extract" + public static let RefactorInline: CodeActionKind = "refactor.inline" + public static let RefactorRewrite: CodeActionKind = "refactor.rewrite" + public static let Source: CodeActionKind = "source" + public static let SourceOrganizeImports: CodeActionKind = "source.organizeImports" public static let SourceFixAll: CodeActionKind = "source.fixAll" } public struct CodeActionClientCapabilities: Codable, Hashable, Sendable { - public struct CodeActionLiteralSupport: Codable, Hashable, Sendable { - public var codeActionKind: ValueSet - - public init(codeActionKind: ValueSet) { - self.codeActionKind = codeActionKind - } - } - - public struct ResolveSupport: Codable, Hashable, Sendable { - public var properties: [String] - - public init(properties: [String]) { - self.properties = properties - } - } - - public var dynamicRegistration: Bool? - public var codeActionLiteralSupport:CodeActionLiteralSupport? - public var isPreferredSupport: Bool? - public var disabledSupport: Bool? - public var dataSupport: Bool? - public var resolveSupport: ResolveSupport? - public var honorsChangeAnnotations: Bool? - - public init(dynamicRegistration: Bool?, - codeActionLiteralSupport: CodeActionClientCapabilities.CodeActionLiteralSupport? = nil, - isPreferredSupport: Bool? = nil, - disabledSupport: Bool? = nil, - dataSupport: Bool? = nil, - resolveSupport: ResolveSupport? = nil, - honorsChangeAnnotations: Bool? = nil) { - self.dynamicRegistration = dynamicRegistration - self.codeActionLiteralSupport = codeActionLiteralSupport - self.isPreferredSupport = isPreferredSupport - self.disabledSupport = disabledSupport - self.dataSupport = dataSupport - self.resolveSupport = resolveSupport - self.honorsChangeAnnotations = honorsChangeAnnotations - } + public struct CodeActionLiteralSupport: Codable, Hashable, Sendable { + public var codeActionKind: ValueSet + + public init(codeActionKind: ValueSet) { + self.codeActionKind = codeActionKind + } + } + + public struct ResolveSupport: Codable, Hashable, Sendable { + public var properties: [String] + + public init(properties: [String]) { + self.properties = properties + } + } + + public var dynamicRegistration: Bool? + public var codeActionLiteralSupport: CodeActionLiteralSupport? + public var isPreferredSupport: Bool? + public var disabledSupport: Bool? + public var dataSupport: Bool? + public var resolveSupport: ResolveSupport? + public var honorsChangeAnnotations: Bool? + + public init( + dynamicRegistration: Bool?, + codeActionLiteralSupport: CodeActionClientCapabilities.CodeActionLiteralSupport? = nil, + isPreferredSupport: Bool? = nil, + disabledSupport: Bool? = nil, + dataSupport: Bool? = nil, + resolveSupport: ResolveSupport? = nil, + honorsChangeAnnotations: Bool? = nil + ) { + self.dynamicRegistration = dynamicRegistration + self.codeActionLiteralSupport = codeActionLiteralSupport + self.isPreferredSupport = isPreferredSupport + self.disabledSupport = disabledSupport + self.dataSupport = dataSupport + self.resolveSupport = resolveSupport + self.honorsChangeAnnotations = honorsChangeAnnotations + } } public struct CodeActionOptions: Codable, Hashable, Sendable { @@ -61,7 +63,8 @@ public struct CodeActionOptions: Codable, Hashable, Sendable { public var codeActionKinds: [CodeActionKind]? public var resolveProvider: Bool? - public init(workDoneProgress: Bool?, codeActionKinds: [CodeActionKind]?, resolveProvider: Bool) { + public init(workDoneProgress: Bool?, codeActionKinds: [CodeActionKind]?, resolveProvider: Bool) + { self.workDoneProgress = workDoneProgress self.codeActionKinds = codeActionKinds self.resolveProvider = resolveProvider @@ -74,53 +77,60 @@ public enum CodeActionTriggerKind: Int, Codable, Hashable, Sendable { } public struct CodeActionContext: Codable, Hashable, Sendable { - public let diagnostics: [Diagnostic] - public let only: [CodeActionKind]? + public let diagnostics: [Diagnostic] + public let only: [CodeActionKind]? public let triggerKind: CodeActionTriggerKind? - public init(diagnostics: [Diagnostic], only: [CodeActionKind]?, triggerKind: CodeActionTriggerKind? = nil) { - self.diagnostics = diagnostics - self.only = only + public init( + diagnostics: [Diagnostic], only: [CodeActionKind]?, + triggerKind: CodeActionTriggerKind? = nil + ) { + self.diagnostics = diagnostics + self.only = only self.triggerKind = triggerKind - } + } } public struct CodeActionParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier - public let range: LSPRange - public let context: CodeActionContext - - public init(textDocument: TextDocumentIdentifier, range: LSPRange, context: CodeActionContext) { - self.textDocument = textDocument - self.range = range - self.context = context - } + public let textDocument: TextDocumentIdentifier + public let range: LSPRange + public let context: CodeActionContext + + public init(textDocument: TextDocumentIdentifier, range: LSPRange, context: CodeActionContext) { + self.textDocument = textDocument + self.range = range + self.context = context + } } public struct CodeAction: Codable, Hashable, Sendable { - public struct Disabled: Codable, Hashable, Sendable { - public var disabled: Bool - } - - public var title: String - public var kind: CodeActionKind? - public var diagnostics: [Diagnostic]? - public var isPreferred: Bool? - public var disabled: Disabled? - public var edit: WorkspaceEdit? - public var command: Command? - public var data: LSPAny? - - public init(title: String, kind: CodeActionKind? = nil, diagnostics: [Diagnostic]? = nil, isPreferred: Bool? = nil, disabled: CodeAction.Disabled? = nil, edit: WorkspaceEdit? = nil, command: Command? = nil, data: LSPAny? = nil) { - self.title = title - self.kind = kind - self.diagnostics = diagnostics - self.isPreferred = isPreferred - self.disabled = disabled - self.edit = edit - self.command = command - self.data = data - } + public struct Disabled: Codable, Hashable, Sendable { + public var disabled: Bool + } + + public var title: String + public var kind: CodeActionKind? + public var diagnostics: [Diagnostic]? + public var isPreferred: Bool? + public var disabled: Disabled? + public var edit: WorkspaceEdit? + public var command: Command? + public var data: LSPAny? + + public init( + title: String, kind: CodeActionKind? = nil, diagnostics: [Diagnostic]? = nil, + isPreferred: Bool? = nil, disabled: CodeAction.Disabled? = nil, edit: WorkspaceEdit? = nil, + command: Command? = nil, data: LSPAny? = nil + ) { + self.title = title + self.kind = kind + self.diagnostics = diagnostics + self.isPreferred = isPreferred + self.disabled = disabled + self.edit = edit + self.command = command + self.data = data + } } public typealias CodeActionResponse = [TwoTypeOption]? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/CodeLens.swift b/Sources/LanguageServerProtocol/LanguageFeatures/CodeLens.swift index 7a5d9f2..0338720 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/CodeLens.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/CodeLens.swift @@ -3,40 +3,43 @@ import Foundation public typealias CodeLensClientCapabilities = DynamicRegistrationClientCapabilities public struct CodeLensWorkspaceClientCapabilities: Codable, Hashable, Sendable { - public var refreshSupport: Bool? + public var refreshSupport: Bool? - public init(refreshSupport: Bool? = nil) { - self.refreshSupport = refreshSupport - } + public init(refreshSupport: Bool? = nil) { + self.refreshSupport = refreshSupport + } } public struct CodeLensOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var resolveProvider: Bool? + public var workDoneProgress: Bool? + public var resolveProvider: Bool? } public struct CodeLensRegistrationOptions: Codable, Hashable, Sendable { - public var documentSelector: DocumentSelector? - public var workDoneProgress: Bool? - public var resolveProvider: Bool? + public var documentSelector: DocumentSelector? + public var workDoneProgress: Bool? + public var resolveProvider: Bool? } public struct CodeLensParams: Codable, Hashable, Sendable { - public var textDocument: TextDocumentIdentifier - public var workDoneToken: ProgressToken? - public var partialResultToken: ProgressToken? - - public init(textDocument: TextDocumentIdentifier, workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil) { - self.textDocument = textDocument - self.workDoneToken = workDoneToken - self.partialResultToken = partialResultToken - } + public var textDocument: TextDocumentIdentifier + public var workDoneToken: ProgressToken? + public var partialResultToken: ProgressToken? + + public init( + textDocument: TextDocumentIdentifier, workDoneToken: ProgressToken? = nil, + partialResultToken: ProgressToken? = nil + ) { + self.textDocument = textDocument + self.workDoneToken = workDoneToken + self.partialResultToken = partialResultToken + } } public struct CodeLens: Codable, Hashable, Sendable { - public var range: LSPRange - public var command: Command? - public var data: LSPAny? + public var range: LSPRange + public var command: Command? + public var data: LSPAny? } public typealias CodeLensResponse = [CodeLens]? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/ColorPresentation.swift b/Sources/LanguageServerProtocol/LanguageFeatures/ColorPresentation.swift index ff76b3d..18e8d48 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/ColorPresentation.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/ColorPresentation.swift @@ -1,25 +1,28 @@ import Foundation public struct ColorPresentationParams: Codable, Hashable, Sendable { - public let workDoneToken: ProgressToken? - public let partialResultToken: ProgressToken? - public let textDocument: TextDocumentIdentifier - public let color: Color - public let range: LSPRange + public let workDoneToken: ProgressToken? + public let partialResultToken: ProgressToken? + public let textDocument: TextDocumentIdentifier + public let color: Color + public let range: LSPRange - public init(workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil, textDocument: TextDocumentIdentifier, color: Color, range: LSPRange) { - self.workDoneToken = workDoneToken - self.partialResultToken = partialResultToken - self.textDocument = textDocument - self.color = color - self.range = range - } + public init( + workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil, + textDocument: TextDocumentIdentifier, color: Color, range: LSPRange + ) { + self.workDoneToken = workDoneToken + self.partialResultToken = partialResultToken + self.textDocument = textDocument + self.color = color + self.range = range + } } public struct ColorPresentation: Codable, Hashable, Sendable { - public let label: String - public let textEdit: TextEdit? - public let additionalTextEdits: [TextEdit]? + public let label: String + public let textEdit: TextEdit? + public let additionalTextEdits: [TextEdit]? } public typealias ColorPresentationResponse = [ColorPresentation] diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift b/Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift index 6fcddcc..d07d475 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/Completion.swift @@ -2,231 +2,242 @@ import Foundation import JSONRPC public struct CompletionClientCapabilities: Codable, Hashable, Sendable { - public struct CompletionItem: Codable, Hashable, Sendable { - public struct ResolveSupport: Codable, Hashable, Sendable { - public var properties: [String] - - public init(properties: [String]) { - self.properties = properties - } - } - - public let snippetSupport: Bool? - public let commitCharactersSupport: Bool? - public let documentationFormat: [MarkupKind]? - public let deprecatedSupport: Bool? - public let preselectSupport: Bool? - public var tagSupport: ValueSet? - public var insertReplaceSupport: Bool? - public var resolveSupport: ResolveSupport? - public var insertTextModeSupport: ValueSet? - public var labelDetailsSupport: Bool? - - public init(snippetSupport: Bool? = nil, - commitCharactersSupport: Bool? = nil, - documentationFormat: [MarkupKind]? = nil, - deprecatedSupport: Bool? = nil, - preselectSupport: Bool? = nil, - tagSupport: ValueSet? = nil, - insertReplaceSupport: Bool? = nil, - resolveSupport: CompletionItem.ResolveSupport? = nil, - insertTextModeSupport: ValueSet? = nil, - labelDetailsSupport: Bool? = nil) { - self.snippetSupport = snippetSupport - self.commitCharactersSupport = commitCharactersSupport - self.documentationFormat = documentationFormat - self.deprecatedSupport = deprecatedSupport - self.preselectSupport = preselectSupport - self.tagSupport = tagSupport - self.insertReplaceSupport = insertReplaceSupport - self.resolveSupport = resolveSupport - self.insertTextModeSupport = insertTextModeSupport - self.labelDetailsSupport = labelDetailsSupport - } - } - - public struct CompletionList: Codable, Hashable, Sendable { - public var itemDefaults: [String]? - - public init(itemDefaults: [String]? = nil) { - self.itemDefaults = itemDefaults - } - } - - public var dynamicRegistration: Bool? - public var completionItem: CompletionItem? - public var completionItemKind: ValueSet? - public var contextSupport: Bool? - public var insertTextMode: InsertTextMode? - public var completionList: CompletionList? - - public init(dynamicRegistration: Bool? = nil, - completionItem: CompletionItem? = nil, - completionItemKind: ValueSet? = nil, - contextSupport: Bool? = nil, - insertTextMode: InsertTextMode? = nil, - completionList: CompletionClientCapabilities.CompletionList? = nil) { - self.dynamicRegistration = dynamicRegistration - self.completionItem = completionItem - self.completionItemKind = completionItemKind - self.contextSupport = contextSupport - self.insertTextMode = insertTextMode - self.completionList = completionList - } + public struct CompletionItem: Codable, Hashable, Sendable { + public struct ResolveSupport: Codable, Hashable, Sendable { + public var properties: [String] + + public init(properties: [String]) { + self.properties = properties + } + } + + public let snippetSupport: Bool? + public let commitCharactersSupport: Bool? + public let documentationFormat: [MarkupKind]? + public let deprecatedSupport: Bool? + public let preselectSupport: Bool? + public var tagSupport: ValueSet? + public var insertReplaceSupport: Bool? + public var resolveSupport: ResolveSupport? + public var insertTextModeSupport: ValueSet? + public var labelDetailsSupport: Bool? + + public init( + snippetSupport: Bool? = nil, + commitCharactersSupport: Bool? = nil, + documentationFormat: [MarkupKind]? = nil, + deprecatedSupport: Bool? = nil, + preselectSupport: Bool? = nil, + tagSupport: ValueSet? = nil, + insertReplaceSupport: Bool? = nil, + resolveSupport: CompletionItem.ResolveSupport? = nil, + insertTextModeSupport: ValueSet? = nil, + labelDetailsSupport: Bool? = nil + ) { + self.snippetSupport = snippetSupport + self.commitCharactersSupport = commitCharactersSupport + self.documentationFormat = documentationFormat + self.deprecatedSupport = deprecatedSupport + self.preselectSupport = preselectSupport + self.tagSupport = tagSupport + self.insertReplaceSupport = insertReplaceSupport + self.resolveSupport = resolveSupport + self.insertTextModeSupport = insertTextModeSupport + self.labelDetailsSupport = labelDetailsSupport + } + } + + public struct CompletionList: Codable, Hashable, Sendable { + public var itemDefaults: [String]? + + public init(itemDefaults: [String]? = nil) { + self.itemDefaults = itemDefaults + } + } + + public var dynamicRegistration: Bool? + public var completionItem: CompletionItem? + public var completionItemKind: ValueSet? + public var contextSupport: Bool? + public var insertTextMode: InsertTextMode? + public var completionList: CompletionList? + + public init( + dynamicRegistration: Bool? = nil, + completionItem: CompletionItem? = nil, + completionItemKind: ValueSet? = nil, + contextSupport: Bool? = nil, + insertTextMode: InsertTextMode? = nil, + completionList: CompletionClientCapabilities.CompletionList? = nil + ) { + self.dynamicRegistration = dynamicRegistration + self.completionItem = completionItem + self.completionItemKind = completionItemKind + self.contextSupport = contextSupport + self.insertTextMode = insertTextMode + self.completionList = completionList + } } public enum CompletionTriggerKind: Int, Codable, Hashable, Sendable { - case invoked = 1 - case triggerCharacter = 2 - case triggerForIncompleteCompletions = 3 + case invoked = 1 + case triggerCharacter = 2 + case triggerForIncompleteCompletions = 3 } public enum CompletionItemKind: Int, CaseIterable, Codable, Hashable, Sendable { - case text = 1 - case method = 2 - case function = 3 - case constructor = 4 - case field = 5 - case variable = 6 - case `class` = 7 - case interface = 8 - case module = 9 - case property = 10 - case unit = 11 - case value = 12 - case `enum` = 13 - case keyword = 14 - case snippet = 15 - case color = 16 - case file = 17 - case reference = 18 - case folder = 19 - case enumMember = 20 - case constant = 21 - case `struct` = 22 - case event = 23 - case `operator` = 24 - case typeParameter = 25 + case text = 1 + case method = 2 + case function = 3 + case constructor = 4 + case field = 5 + case variable = 6 + case `class` = 7 + case interface = 8 + case module = 9 + case property = 10 + case unit = 11 + case value = 12 + case `enum` = 13 + case keyword = 14 + case snippet = 15 + case color = 16 + case file = 17 + case reference = 18 + case folder = 19 + case enumMember = 20 + case constant = 21 + case `struct` = 22 + case event = 23 + case `operator` = 24 + case typeParameter = 25 } public enum CompletionItemTag: Int, CaseIterable, Codable, Hashable, Sendable { - case deprecated = 1 + case deprecated = 1 } public struct CompletionContext: Codable, Hashable, Sendable { - public let triggerKind: CompletionTriggerKind - public let triggerCharacter: String? + public let triggerKind: CompletionTriggerKind + public let triggerCharacter: String? - public init(triggerKind: CompletionTriggerKind, triggerCharacter: String?) { - self.triggerKind = triggerKind - self.triggerCharacter = triggerCharacter - } + public init(triggerKind: CompletionTriggerKind, triggerCharacter: String?) { + self.triggerKind = triggerKind + self.triggerCharacter = triggerCharacter + } } public struct CompletionParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier - public let position: Position - public let context: CompletionContext? - - public init(textDocument: TextDocumentIdentifier, position: Position, context: CompletionContext?) { - self.textDocument = textDocument - self.position = position - self.context = context - } - - public init(uri: DocumentUri, position: Position, triggerKind: CompletionTriggerKind, triggerCharacter: String?) { - let td = TextDocumentIdentifier(uri: uri) - let ctx = CompletionContext(triggerKind: triggerKind, triggerCharacter: triggerCharacter) - - self.init(textDocument: td, position: position, context: ctx) - } + public let textDocument: TextDocumentIdentifier + public let position: Position + public let context: CompletionContext? + + public init( + textDocument: TextDocumentIdentifier, position: Position, context: CompletionContext? + ) { + self.textDocument = textDocument + self.position = position + self.context = context + } + + public init( + uri: DocumentUri, position: Position, triggerKind: CompletionTriggerKind, + triggerCharacter: String? + ) { + let td = TextDocumentIdentifier(uri: uri) + let ctx = CompletionContext(triggerKind: triggerKind, triggerCharacter: triggerCharacter) + + self.init(textDocument: td, position: position, context: ctx) + } } public enum InsertTextFormat: Int, Codable, Hashable, Sendable { - case plaintext = 1 - case snippet = 2 + case plaintext = 1 + case snippet = 2 } public struct CompletionItem: Codable, Hashable, Sendable { - public let label: String - public let kind: CompletionItemKind? - public let detail: String? - public let documentation: TwoTypeOption? - public let deprecated: Bool? - public let preselect: Bool? - public let sortText: String? - public let filterText: String? - public let insertText: String? - public let insertTextFormat: InsertTextFormat? - public let textEdit: TextEdit? - public let additionalTextEdits: [TextEdit]? - public let commitCharacters: [String]? - public let command: Command? - public let data: LSPAny? - - public init(label: String, - kind: CompletionItemKind? = nil, - detail: String? = nil, - documentation: TwoTypeOption? = nil, - deprecated: Bool? = nil, - preselect: Bool? = nil, - sortText: String? = nil, - filterText: String? = nil, - insertText: String? = nil, - insertTextFormat: InsertTextFormat? = nil, - textEdit: TextEdit? = nil, - additionalTextEdits: [TextEdit]? = nil, - commitCharacters: [String]? = nil, - command: Command? = nil, - data: LSPAny? = nil) { - self.label = label - self.kind = kind - self.detail = detail - self.documentation = documentation - self.deprecated = deprecated - self.preselect = preselect - self.sortText = sortText - self.filterText = filterText - self.insertText = insertText - self.insertTextFormat = insertTextFormat - self.textEdit = textEdit - self.additionalTextEdits = additionalTextEdits - self.commitCharacters = commitCharacters - self.command = command - self.data = data - } + public let label: String + public let kind: CompletionItemKind? + public let detail: String? + public let documentation: TwoTypeOption? + public let deprecated: Bool? + public let preselect: Bool? + public let sortText: String? + public let filterText: String? + public let insertText: String? + public let insertTextFormat: InsertTextFormat? + public let textEdit: TextEdit? + public let additionalTextEdits: [TextEdit]? + public let commitCharacters: [String]? + public let command: Command? + public let data: LSPAny? + + public init( + label: String, + kind: CompletionItemKind? = nil, + detail: String? = nil, + documentation: TwoTypeOption? = nil, + deprecated: Bool? = nil, + preselect: Bool? = nil, + sortText: String? = nil, + filterText: String? = nil, + insertText: String? = nil, + insertTextFormat: InsertTextFormat? = nil, + textEdit: TextEdit? = nil, + additionalTextEdits: [TextEdit]? = nil, + commitCharacters: [String]? = nil, + command: Command? = nil, + data: LSPAny? = nil + ) { + self.label = label + self.kind = kind + self.detail = detail + self.documentation = documentation + self.deprecated = deprecated + self.preselect = preselect + self.sortText = sortText + self.filterText = filterText + self.insertText = insertText + self.insertTextFormat = insertTextFormat + self.textEdit = textEdit + self.additionalTextEdits = additionalTextEdits + self.commitCharacters = commitCharacters + self.command = command + self.data = data + } } public struct CompletionList: Codable, Hashable, Sendable { - public let isIncomplete: Bool - public let items: [CompletionItem] + public let isIncomplete: Bool + public let items: [CompletionItem] - public init(isIncomplete: Bool, items: [CompletionItem]) { - self.isIncomplete = isIncomplete - self.items = items - } + public init(isIncomplete: Bool, items: [CompletionItem]) { + self.isIncomplete = isIncomplete + self.items = items + } } public typealias CompletionResponse = TwoTypeOption<[CompletionItem], CompletionList>? -public extension TwoTypeOption where T == [CompletionItem], U == CompletionList { - var items: [CompletionItem] { - switch self { - case .optionA(let v): - return v - case .optionB(let list): - return list.items - } - } - - var isIncomplete: Bool { - switch self { - case .optionA: - return false - case .optionB(let value): - return value.isIncomplete - } - } +extension TwoTypeOption where T == [CompletionItem], U == CompletionList { + public var items: [CompletionItem] { + switch self { + case .optionA(let v): + return v + case .optionB(let list): + return list.items + } + } + + public var isIncomplete: Bool { + switch self { + case .optionA: + return false + case .optionB(let value): + return value.isIncomplete + } + } } public struct CompletionRegistrationOptions: Codable { @@ -236,7 +247,6 @@ public struct CompletionRegistrationOptions: Codable { } public enum InsertTextMode: Int, CaseIterable, Codable, Hashable, Sendable { - case asIs = 1 - case adjustIndentation = 2 + case asIs = 1 + case adjustIndentation = 2 } - diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/Declaration.swift b/Sources/LanguageServerProtocol/LanguageFeatures/Declaration.swift index e14027a..f0bcd1f 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/Declaration.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/Declaration.swift @@ -1,6 +1,6 @@ // // File.swift -// +// // // Created by Matthew Massicotte on 2022-02-17. // diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/Diagnostics.swift b/Sources/LanguageServerProtocol/LanguageFeatures/Diagnostics.swift index 94b4b7d..7605383 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/Diagnostics.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/Diagnostics.swift @@ -6,7 +6,10 @@ public struct DiagnosticOptions: Codable, Hashable, Sendable { public let interFileDependencies: Bool public let workspaceDiagnostics: Bool - public init(workDoneProgress: Bool? = nil, identifier: String? = nil, interFileDependencies: Bool, workspaceDiagnostics: Bool) { + public init( + workDoneProgress: Bool? = nil, identifier: String? = nil, interFileDependencies: Bool, + workspaceDiagnostics: Bool + ) { self.workDoneProgress = workDoneProgress self.identifier = identifier self.interFileDependencies = interFileDependencies @@ -22,7 +25,11 @@ public struct DiagnosticRegistrationOptions: Codable, Hashable, Sendable { public let workspaceDiagnostics: Bool public let id: String? - public init(documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil, identifier: String? = nil, interFileDependencies: Bool, workspaceDiagnostics: Bool, id: String? = nil) { + public init( + documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil, + identifier: String? = nil, interFileDependencies: Bool, workspaceDiagnostics: Bool, + id: String? = nil + ) { self.documentSelector = documentSelector self.workDoneProgress = workDoneProgress self.identifier = identifier @@ -33,19 +40,22 @@ public struct DiagnosticRegistrationOptions: Codable, Hashable, Sendable { } public struct PublishDiagnosticsClientCapabilities: Codable, Hashable, Sendable { - public var relatedInformation: Bool? - public var tagSupport: ValueSet? - public var versionSupport: Bool? - public var codeDescriptionSupport: Bool? - public var dataSupport: Bool? - - public init(relatedInformation: Bool? = nil, tagSupport: ValueSet? = nil, versionSupport: Bool? = nil, codeDescriptionSupport: Bool? = nil, dataSupport: Bool? = nil) { - self.relatedInformation = relatedInformation - self.tagSupport = tagSupport - self.versionSupport = versionSupport - self.codeDescriptionSupport = codeDescriptionSupport - self.dataSupport = dataSupport - } + public var relatedInformation: Bool? + public var tagSupport: ValueSet? + public var versionSupport: Bool? + public var codeDescriptionSupport: Bool? + public var dataSupport: Bool? + + public init( + relatedInformation: Bool? = nil, tagSupport: ValueSet? = nil, + versionSupport: Bool? = nil, codeDescriptionSupport: Bool? = nil, dataSupport: Bool? = nil + ) { + self.relatedInformation = relatedInformation + self.tagSupport = tagSupport + self.versionSupport = versionSupport + self.codeDescriptionSupport = codeDescriptionSupport + self.dataSupport = dataSupport + } } public struct DiagnosticClientCapabilities: Codable, Hashable, Sendable { @@ -59,8 +69,8 @@ public struct DiagnosticClientCapabilities: Codable, Hashable, Sendable { } public struct DiagnosticRelatedInformation: Codable, Hashable, Sendable { - public let location: Location - public let message: String + public let location: Location + public let message: String public init(location: Location, message: String) { self.location = location @@ -71,15 +81,15 @@ public struct DiagnosticRelatedInformation: Codable, Hashable, Sendable { public typealias DiagnosticCode = TwoTypeOption public enum DiagnosticSeverity: Int, CaseIterable, Codable, Hashable, Sendable { - case error = 1 - case warning = 2 - case information = 3 - case hint = 4 + case error = 1 + case warning = 2 + case information = 3 + case hint = 4 } public enum DiagnosticTag: Int, CaseIterable, Codable, Hashable, Sendable { - case unnecessary = 1 - case deprecated = 2 + case unnecessary = 1 + case deprecated = 2 } public struct CodeDescription: Codable, Hashable, Sendable { @@ -91,31 +101,35 @@ public struct CodeDescription: Codable, Hashable, Sendable { } public struct Diagnostic: Codable, Hashable, Sendable { - public let range: LSPRange - public let severity: DiagnosticSeverity? - public let code: DiagnosticCode? + public let range: LSPRange + public let severity: DiagnosticSeverity? + public let code: DiagnosticCode? public let codeDescription: CodeDescription? - public let source: String? - public let message: String - public let tags: [DiagnosticTag]? - public let relatedInformation: [DiagnosticRelatedInformation]? - - public init(range: LSPRange, severity: DiagnosticSeverity? = nil, code: DiagnosticCode? = nil, codeDescription: CodeDescription? = nil, source: String? = nil, message: String, tags: [DiagnosticTag]? = nil, relatedInformation: [DiagnosticRelatedInformation]? = nil) { - self.range = range - self.severity = severity - self.code = code - self.codeDescription = codeDescription - self.source = source - self.message = message - self.tags = tags - self.relatedInformation = relatedInformation - } + public let source: String? + public let message: String + public let tags: [DiagnosticTag]? + public let relatedInformation: [DiagnosticRelatedInformation]? + + public init( + range: LSPRange, severity: DiagnosticSeverity? = nil, code: DiagnosticCode? = nil, + codeDescription: CodeDescription? = nil, source: String? = nil, message: String, + tags: [DiagnosticTag]? = nil, relatedInformation: [DiagnosticRelatedInformation]? = nil + ) { + self.range = range + self.severity = severity + self.code = code + self.codeDescription = codeDescription + self.source = source + self.message = message + self.tags = tags + self.relatedInformation = relatedInformation + } } public struct PublishDiagnosticsParams: Codable, Hashable, Sendable { - public let uri: DocumentUri - public let version: Int? - public let diagnostics: [Diagnostic] + public let uri: DocumentUri + public let version: Int? + public let diagnostics: [Diagnostic] public init(uri: DocumentUri, version: Int? = nil, diagnostics: [Diagnostic]) { self.uri = uri @@ -156,7 +170,9 @@ public struct BaseDocumentDiagnosticReport: Codable, Hashable, Sendable { public let resultId: String? public let items: [Diagnostic]? - public init(kind: DocumentDiagnosticReportKind, resultId: String? = nil, items: [Diagnostic]? = nil) { + public init( + kind: DocumentDiagnosticReportKind, resultId: String? = nil, items: [Diagnostic]? = nil + ) { self.kind = kind self.resultId = resultId self.items = items @@ -169,7 +185,10 @@ public struct RelatedDocumentDiagnosticReport: Codable, Hashable, Sendable { public let items: [Diagnostic]? public let relatedDocuments: [DocumentUri: DocumentDiagnosticReport]? - public init(kind: DocumentDiagnosticReportKind, resultId: String? = nil, items: [Diagnostic]? = nil, relatedDocuments: [DocumentUri : DocumentDiagnosticReport]? = nil) { + public init( + kind: DocumentDiagnosticReportKind, resultId: String? = nil, items: [Diagnostic]? = nil, + relatedDocuments: [DocumentUri: DocumentDiagnosticReport]? = nil + ) { self.kind = kind self.resultId = resultId self.items = items diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/DocumentColor.swift b/Sources/LanguageServerProtocol/LanguageFeatures/DocumentColor.swift index 623c850..347bc9d 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/DocumentColor.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/DocumentColor.swift @@ -3,27 +3,30 @@ import Foundation public typealias DocumentColorClientCapabilities = DynamicRegistrationClientCapabilities public struct DocumentColorParams: Codable, Hashable, Sendable { - public let workDoneToken: ProgressToken? - public let partialResultToken: ProgressToken? - public let textDocument: TextDocumentIdentifier + public let workDoneToken: ProgressToken? + public let partialResultToken: ProgressToken? + public let textDocument: TextDocumentIdentifier - public init(textDocument: TextDocumentIdentifier, workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil) { - self.workDoneToken = workDoneToken - self.partialResultToken = partialResultToken - self.textDocument = textDocument - } + public init( + textDocument: TextDocumentIdentifier, workDoneToken: ProgressToken? = nil, + partialResultToken: ProgressToken? = nil + ) { + self.workDoneToken = workDoneToken + self.partialResultToken = partialResultToken + self.textDocument = textDocument + } } public struct Color: Codable, Hashable, Sendable { - public let red: Float - public let green: Float - public let blue: Float - public let alpha: Float + public let red: Float + public let green: Float + public let blue: Float + public let alpha: Float } public struct ColorInformation: Codable, Hashable, Sendable { - public let range: LSPRange - public let color: Color + public let range: LSPRange + public let color: Color } public typealias DocumentColorResponse = [ColorInformation] diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/DocumentHighlight.swift b/Sources/LanguageServerProtocol/LanguageFeatures/DocumentHighlight.swift index d02dc83..0ad90f4 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/DocumentHighlight.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/DocumentHighlight.swift @@ -5,33 +5,36 @@ public typealias DocumentHighlightClientCapabilities = DynamicRegistrationClient public typealias DocumentHighlightOptions = WorkDoneProgressOptions public struct DocumentHighlightRegistrationOptions: Codable, Hashable, Sendable { - public var documentSelector: DocumentSelector? - public var workDoneProgress: Bool? + public var documentSelector: DocumentSelector? + public var workDoneProgress: Bool? } public struct DocumentHighlightParams: Codable, Hashable, Sendable { - public var textDocument: TextDocumentIdentifier - public var position: Position - public var workDoneToken: ProgressToken? - public var partialResultToken: ProgressToken? - - public init(textDocument: TextDocumentIdentifier, position: Position, workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil) { - self.textDocument = textDocument - self.position = position - self.workDoneToken = workDoneToken - self.partialResultToken = partialResultToken - } + public var textDocument: TextDocumentIdentifier + public var position: Position + public var workDoneToken: ProgressToken? + public var partialResultToken: ProgressToken? + + public init( + textDocument: TextDocumentIdentifier, position: Position, + workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil + ) { + self.textDocument = textDocument + self.position = position + self.workDoneToken = workDoneToken + self.partialResultToken = partialResultToken + } } public enum DocumentHighlightKind: Int, CaseIterable, Codable, Hashable, Sendable { - case Text = 1 - case Read = 2 - case Write = 3 + case Text = 1 + case Read = 2 + case Write = 3 } public struct DocumentHighlight: Codable, Hashable, Sendable { - public var range: LSPRange - public var kind: DocumentHighlightKind? + public var range: LSPRange + public var kind: DocumentHighlightKind? } public typealias DocumentHighlightResponse = [DocumentHighlight]? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/DocumentLink.swift b/Sources/LanguageServerProtocol/LanguageFeatures/DocumentLink.swift index 092ad50..a6fd733 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/DocumentLink.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/DocumentLink.swift @@ -1,6 +1,6 @@ // // File.swift -// +// // // Created by Matthew Massicotte on 2022-02-18. // @@ -8,42 +8,45 @@ import Foundation public struct DocumentLinkClientCapabilities: Codable, Hashable, Sendable { - public var dynamicRegistration: Bool? - public var tooltipSupport: Bool? + public var dynamicRegistration: Bool? + public var tooltipSupport: Bool? - public init(dynamicRegistration: Bool, tooltipSupport: Bool? = nil) { - self.dynamicRegistration = dynamicRegistration - self.tooltipSupport = tooltipSupport - } + public init(dynamicRegistration: Bool, tooltipSupport: Bool? = nil) { + self.dynamicRegistration = dynamicRegistration + self.tooltipSupport = tooltipSupport + } } public struct DocumentLinkOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var resolveProvider: Bool? + public var workDoneProgress: Bool? + public var resolveProvider: Bool? } public struct DocumentLinkRegistrationOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var documentSelector: DocumentSelector? - public var resolveProvider: Bool? - - public init(workDoneProgress: Bool? = nil, documentSelector: DocumentSelector? = nil, resolveProvider: Bool? = nil) { - self.workDoneProgress = workDoneProgress - self.documentSelector = documentSelector - self.resolveProvider = resolveProvider - } + public var workDoneProgress: Bool? + public var documentSelector: DocumentSelector? + public var resolveProvider: Bool? + + public init( + workDoneProgress: Bool? = nil, documentSelector: DocumentSelector? = nil, + resolveProvider: Bool? = nil + ) { + self.workDoneProgress = workDoneProgress + self.documentSelector = documentSelector + self.resolveProvider = resolveProvider + } } public struct DocumentLinkParams: Codable, Hashable, Sendable { - public var workDoneToken: ProgressToken? - public var partialResultToken: ProgressToken? + public var workDoneToken: ProgressToken? + public var partialResultToken: ProgressToken? } public struct DocumentLink: Codable, Hashable, Sendable { - public var range: LSPRange - public var target: DocumentUri? - public var tooltip: String? - public var data: LSPAny? + public var range: LSPRange + public var target: DocumentUri? + public var tooltip: String? + public var data: LSPAny? public init(range: LSPRange, target: DocumentUri?, tooltip: String?, data: LSPAny?) { self.range = range diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/DocumentSymbol.swift b/Sources/LanguageServerProtocol/LanguageFeatures/DocumentSymbol.swift index 631d6db..72a42d0 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/DocumentSymbol.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/DocumentSymbol.swift @@ -1,31 +1,38 @@ import Foundation public struct DocumentSymbolClientCapabilities: Codable, Hashable, Sendable { - public var dynamicRegistration: Bool? - public var symbolKind: ValueSet? - public var hierarchicalDocumentSymbolSupport: Bool? - public var tagSupport: ValueSet? - public var labelSupport: Bool? - - public init(dynamicRegistration: Bool, symbolKind: ValueSet? = nil, hierarchicalDocumentSymbolSupport: Bool? = nil, tagSupport: ValueSet? = nil, labelSupport: Bool? = nil) { - self.dynamicRegistration = dynamicRegistration - self.symbolKind = symbolKind - self.hierarchicalDocumentSymbolSupport = hierarchicalDocumentSymbolSupport - self.tagSupport = tagSupport - self.labelSupport = labelSupport - } + public var dynamicRegistration: Bool? + public var symbolKind: ValueSet? + public var hierarchicalDocumentSymbolSupport: Bool? + public var tagSupport: ValueSet? + public var labelSupport: Bool? + + public init( + dynamicRegistration: Bool, symbolKind: ValueSet? = nil, + hierarchicalDocumentSymbolSupport: Bool? = nil, tagSupport: ValueSet? = nil, + labelSupport: Bool? = nil + ) { + self.dynamicRegistration = dynamicRegistration + self.symbolKind = symbolKind + self.hierarchicalDocumentSymbolSupport = hierarchicalDocumentSymbolSupport + self.tagSupport = tagSupport + self.labelSupport = labelSupport + } } public struct DocumentSymbolParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier + public let textDocument: TextDocumentIdentifier - public init(textDocument: TextDocumentIdentifier) { - self.textDocument = textDocument - } + public init(textDocument: TextDocumentIdentifier) { + self.textDocument = textDocument + } } public struct DocumentSymbol: Codable, Hashable, Sendable { - public init(name: String, detail: String? = nil, kind: SymbolKind, deprecated: Bool? = nil, range: LSPRange, selectionRange: LSPRange, children: [DocumentSymbol]? = nil) { + public init( + name: String, detail: String? = nil, kind: SymbolKind, deprecated: Bool? = nil, + range: LSPRange, selectionRange: LSPRange, children: [DocumentSymbol]? = nil + ) { self.name = name self.detail = detail self.kind = kind @@ -35,14 +42,13 @@ public struct DocumentSymbol: Codable, Hashable, Sendable { self.children = children } - public let name: String - public let detail: String? - public let kind: SymbolKind - public let deprecated: Bool? - public let range: LSPRange - public let selectionRange: LSPRange - public let children: [DocumentSymbol]? + public let name: String + public let detail: String? + public let kind: SymbolKind + public let deprecated: Bool? + public let range: LSPRange + public let selectionRange: LSPRange + public let children: [DocumentSymbol]? } - public typealias DocumentSymbolResponse = TwoTypeOption<[DocumentSymbol], [SymbolInformation]>? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/FoldingRange.swift b/Sources/LanguageServerProtocol/LanguageFeatures/FoldingRange.swift index ffdabe0..c103110 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/FoldingRange.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/FoldingRange.swift @@ -1,37 +1,39 @@ import Foundation public struct FoldingRangeClientCapabilities: Codable, Hashable, Sendable { - public var dynamicRegistration: Bool? - public var rangeLimit: Int? - public var lineFoldingOnly: Bool? + public var dynamicRegistration: Bool? + public var rangeLimit: Int? + public var lineFoldingOnly: Bool? - public init(dynamicRegistration: Bool? = nil, rangeLimit: Int? = nil, lineFoldingOnly: Bool? = nil) { - self.dynamicRegistration = dynamicRegistration - self.rangeLimit = rangeLimit - self.lineFoldingOnly = lineFoldingOnly - } + public init( + dynamicRegistration: Bool? = nil, rangeLimit: Int? = nil, lineFoldingOnly: Bool? = nil + ) { + self.dynamicRegistration = dynamicRegistration + self.rangeLimit = rangeLimit + self.lineFoldingOnly = lineFoldingOnly + } } public struct FoldingRangeParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier + public let textDocument: TextDocumentIdentifier - public init(textDocument: TextDocumentIdentifier) { - self.textDocument = textDocument - } + public init(textDocument: TextDocumentIdentifier) { + self.textDocument = textDocument + } } public enum FoldingRangeKind: String, CaseIterable, Codable, Hashable, Sendable { - case comment - case imports - case region + case comment + case imports + case region } public struct FoldingRange: Codable, Hashable, Sendable { - public let startLine: Int - public let startCharacter: Int? - public let endLine: Int - public let endCharacter: Int? - public let kind: FoldingRangeKind? + public let startLine: Int + public let startCharacter: Int? + public let endLine: Int + public let endCharacter: Int? + public let kind: FoldingRangeKind? } public typealias FoldingRangeResponse = [FoldingRange]? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/Formatting.swift b/Sources/LanguageServerProtocol/LanguageFeatures/Formatting.swift index 0ba4a55..d8d4662 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/Formatting.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/Formatting.swift @@ -4,49 +4,52 @@ public typealias DocumentFormattingClientCapabilities = DynamicRegistrationClien public typealias DocumentRangeFormattingClientCapabilities = DynamicRegistrationClientCapabilities public struct FormattingOptions: Codable, Hashable, Sendable { - public let tabSize: Int - public let insertSpaces: Bool + public let tabSize: Int + public let insertSpaces: Bool - public init(tabSize: Int, insertSpaces: Bool) { - self.tabSize = tabSize - self.insertSpaces = insertSpaces - } + public init(tabSize: Int, insertSpaces: Bool) { + self.tabSize = tabSize + self.insertSpaces = insertSpaces + } } public struct DocumentFormattingParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier - public let options: FormattingOptions + public let textDocument: TextDocumentIdentifier + public let options: FormattingOptions - public init(textDocument: TextDocumentIdentifier, options: FormattingOptions) { - self.textDocument = textDocument - self.options = options - } + public init(textDocument: TextDocumentIdentifier, options: FormattingOptions) { + self.textDocument = textDocument + self.options = options + } } public struct DocumentRangeFormattingParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier - public let range: LSPRange - public let options: FormattingOptions - - public init(textDocument: TextDocumentIdentifier, range: LSPRange, options: FormattingOptions) { - self.textDocument = textDocument - self.range = range - self.options = options - } + public let textDocument: TextDocumentIdentifier + public let range: LSPRange + public let options: FormattingOptions + + public init(textDocument: TextDocumentIdentifier, range: LSPRange, options: FormattingOptions) { + self.textDocument = textDocument + self.range = range + self.options = options + } } public struct DocumentOnTypeFormattingParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier - public let position: Position - public let ch: String - public let options: FormattingOptions - - public init(textDocument: TextDocumentIdentifier, position: Position, ch: String, options: FormattingOptions) { - self.textDocument = textDocument - self.position = position - self.ch = ch - self.options = options - } + public let textDocument: TextDocumentIdentifier + public let position: Position + public let ch: String + public let options: FormattingOptions + + public init( + textDocument: TextDocumentIdentifier, position: Position, ch: String, + options: FormattingOptions + ) { + self.textDocument = textDocument + self.position = position + self.ch = ch + self.options = options + } } public typealias FormattingResult = [TextEdit]? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/Hover.swift b/Sources/LanguageServerProtocol/LanguageFeatures/Hover.swift index 7454a33..5d40a90 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/Hover.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/Hover.swift @@ -1,20 +1,22 @@ import Foundation public struct HoverClientCapabilities: Codable, Hashable, Sendable { - public var dynamicRegistration: Bool? - public var contentFormat: [MarkupKind]? + public var dynamicRegistration: Bool? + public var contentFormat: [MarkupKind]? - public init(dynamicRegistration: Bool?, contentFormat: [MarkupKind]?) { - self.dynamicRegistration = dynamicRegistration - self.contentFormat = contentFormat - } + public init(dynamicRegistration: Bool?, contentFormat: [MarkupKind]?) { + self.dynamicRegistration = dynamicRegistration + self.contentFormat = contentFormat + } } public struct Hover: Codable, Hashable, Sendable { - public let contents: ThreeTypeOption - public let range: LSPRange? + public let contents: ThreeTypeOption + public let range: LSPRange? - public init(contents: ThreeTypeOption, range: LSPRange?) { + public init( + contents: ThreeTypeOption, range: LSPRange? + ) { self.contents = contents self.range = range } diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/InlayHint.swift b/Sources/LanguageServerProtocol/LanguageFeatures/InlayHint.swift index 061b550..0b8b92c 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/InlayHint.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/InlayHint.swift @@ -24,7 +24,9 @@ public struct InlayHintRegistrationOptions: Codable, Hashable, Sendable { public var workDoneProgress: Bool? public var id: String? - public init(documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil, id: String? = nil) { + public init( + documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil, id: String? = nil + ) { self.documentSelector = documentSelector self.workDoneProgress = workDoneProgress self.id = id @@ -44,7 +46,9 @@ public struct InlayHintParams: Codable, Hashable, Sendable { public var textDocument: TextDocumentIdentifier public var range: LSPRange - public init(workDoneToken: ProgressToken? = nil, textDocument: TextDocumentIdentifier, range: LSPRange) { + public init( + workDoneToken: ProgressToken? = nil, textDocument: TextDocumentIdentifier, range: LSPRange + ) { self.workDoneToken = workDoneToken self.textDocument = textDocument self.range = range @@ -57,7 +61,10 @@ public struct InlayHintLabelPart: Codable, Hashable, Sendable { public var location: Location? public var command: Command? - public init(value: String, tooltop: TwoTypeOption? = nil, location: Location? = nil, command: Command? = nil) { + public init( + value: String, tooltop: TwoTypeOption? = nil, + location: Location? = nil, command: Command? = nil + ) { self.value = value self.tooltop = tooltop self.location = location diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/LinkedEditingRange.swift b/Sources/LanguageServerProtocol/LanguageFeatures/LinkedEditingRange.swift index e111f0c..94f7f81 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/LinkedEditingRange.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/LinkedEditingRange.swift @@ -4,20 +4,23 @@ public typealias LinkedEditingRangeClientCapabilities = DynamicRegistrationClien public struct LinkedEditingRangeParams: Codable, Hashable, Sendable { public let workDoneToken: ProgressToken? - public let partialResultToken: ProgressToken? + public let partialResultToken: ProgressToken? public let textDocument: TextDocumentIdentifier public let position: Position - public init(workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil, textDocument: TextDocumentIdentifier, position: Position) { + public init( + workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil, + textDocument: TextDocumentIdentifier, position: Position + ) { self.workDoneToken = workDoneToken - self.partialResultToken = partialResultToken - self.textDocument = textDocument - self.position = position - } + self.partialResultToken = partialResultToken + self.textDocument = textDocument + self.position = position + } } -public struct LinkedEditingRanges : Codable, Sendable { +public struct LinkedEditingRanges: Codable, Sendable { public let ranges: [LSPRange] public let wordPattern: String? @@ -27,5 +30,4 @@ public struct LinkedEditingRanges : Codable, Sendable { } } - public typealias LinkedEditingRangeResponse = LinkedEditingRanges? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/Moniker.swift b/Sources/LanguageServerProtocol/LanguageFeatures/Moniker.swift index f23d0c1..f813379 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/Moniker.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/Moniker.swift @@ -4,17 +4,20 @@ public typealias MonikerClientCapabilities = DynamicRegistrationClientCapabiliti public struct MonikerParams: Codable, Hashable, Sendable { public let workDoneToken: ProgressToken? - public let partialResultToken: ProgressToken? + public let partialResultToken: ProgressToken? public let textDocument: TextDocumentIdentifier public let position: Position - public init(workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil, textDocument: TextDocumentIdentifier, position: Position) { + public init( + workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil, + textDocument: TextDocumentIdentifier, position: Position + ) { self.workDoneToken = workDoneToken - self.partialResultToken = partialResultToken - self.textDocument = textDocument - self.position = position - } + self.partialResultToken = partialResultToken + self.textDocument = textDocument + self.position = position + } } public enum UniquenessLevel: Codable, Sendable { @@ -25,18 +28,17 @@ public enum UniquenessLevel: Codable, Sendable { case global } -public enum MonikerKind : Codable, Sendable{ +public enum MonikerKind: Codable, Sendable { case _import case export case local } -public struct Moniker : Codable, Sendable { +public struct Moniker: Codable, Sendable { public let scheme: String public let identifier: String public let unique: UniquenessLevel public let kind: MonikerKind? } - public typealias MonikerResponse = [Moniker]? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/References.swift b/Sources/LanguageServerProtocol/LanguageFeatures/References.swift index 0aaa02d..f2305dd 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/References.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/References.swift @@ -3,30 +3,34 @@ import Foundation public typealias ReferenceClientCapabilities = DynamicRegistrationClientCapabilities public struct ReferenceContext: Codable, Hashable, Sendable { - public let includeDeclaration: Bool + public let includeDeclaration: Bool - public init(includeDeclaration: Bool) { - self.includeDeclaration = includeDeclaration - } + public init(includeDeclaration: Bool) { + self.includeDeclaration = includeDeclaration + } } public struct ReferenceParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier - public let position: Position - public let context: ReferenceContext - - public init(textDocument: TextDocumentIdentifier, position: Position, - context: ReferenceContext) { - self.textDocument = textDocument - self.position = position - self.context = context - } - - public init(textDocument: TextDocumentIdentifier, position: Position, includeDeclaration: Bool = false) { - let ctx = ReferenceContext(includeDeclaration: includeDeclaration) - - self.init(textDocument: textDocument, position: position, context: ctx) - } + public let textDocument: TextDocumentIdentifier + public let position: Position + public let context: ReferenceContext + + public init( + textDocument: TextDocumentIdentifier, position: Position, + context: ReferenceContext + ) { + self.textDocument = textDocument + self.position = position + self.context = context + } + + public init( + textDocument: TextDocumentIdentifier, position: Position, includeDeclaration: Bool = false + ) { + let ctx = ReferenceContext(includeDeclaration: includeDeclaration) + + self.init(textDocument: textDocument, position: position, context: ctx) + } } public typealias ReferenceResponse = [Location]? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/Rename.swift b/Sources/LanguageServerProtocol/LanguageFeatures/Rename.swift index ab68a90..b8d100a 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/Rename.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/Rename.swift @@ -1,52 +1,57 @@ import Foundation public enum PrepareSupportDefaultBehavior: Int, CaseIterable, Codable, Hashable, Sendable { - case Identifier = 1 + case Identifier = 1 } public struct RenameClientCapabilities: Codable, Hashable, Sendable { - public let dynamicRegistration: Bool? - public let prepareSupport: Bool? - public let prepareSupportDefaultBehavior: PrepareSupportDefaultBehavior? - public let honorsChangeAnnotations: Bool? - - public init(dynamicRegistration: Bool?, prepareSupport: Bool?, prepareSupportDefaultBehavior: PrepareSupportDefaultBehavior?, honorsChangeAnnotations: Bool?) { - self.dynamicRegistration = dynamicRegistration - self.prepareSupport = prepareSupport - self.prepareSupportDefaultBehavior = prepareSupportDefaultBehavior - self.honorsChangeAnnotations = honorsChangeAnnotations - } + public let dynamicRegistration: Bool? + public let prepareSupport: Bool? + public let prepareSupportDefaultBehavior: PrepareSupportDefaultBehavior? + public let honorsChangeAnnotations: Bool? + + public init( + dynamicRegistration: Bool?, prepareSupport: Bool?, + prepareSupportDefaultBehavior: PrepareSupportDefaultBehavior?, + honorsChangeAnnotations: Bool? + ) { + self.dynamicRegistration = dynamicRegistration + self.prepareSupport = prepareSupport + self.prepareSupportDefaultBehavior = prepareSupportDefaultBehavior + self.honorsChangeAnnotations = honorsChangeAnnotations + } } - public struct RenameOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var prepareProvider: Bool? + public var workDoneProgress: Bool? + public var prepareProvider: Bool? } public typealias PrepareRenameParams = TextDocumentPositionParams public struct RenameParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier - public let position: Position - public let newName: String - - public init(textDocument: TextDocumentIdentifier, position: Position, newName: String) { - self.textDocument = textDocument - self.position = position - self.newName = newName - } + public let textDocument: TextDocumentIdentifier + public let position: Position + public let newName: String + + public init(textDocument: TextDocumentIdentifier, position: Position, newName: String) { + self.textDocument = textDocument + self.position = position + self.newName = newName + } } public struct RangeWithPlaceholder: Codable, Hashable, Sendable { - public let range: LSPRange - public let placeholder: String + public let range: LSPRange + public let placeholder: String } public struct PrepareRenameDefaultBehavior: Codable, Hashable, Sendable { - public let defaultBehavior: Bool + public let defaultBehavior: Bool } -public typealias PrepareRenameResponse = ThreeTypeOption? +public typealias PrepareRenameResponse = ThreeTypeOption< + LSPRange, RangeWithPlaceholder, PrepareRenameDefaultBehavior +>? public typealias RenameResponse = WorkspaceEdit? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/SelectionRange.swift b/Sources/LanguageServerProtocol/LanguageFeatures/SelectionRange.swift index 7e66395..b684ae2 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/SelectionRange.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/SelectionRange.swift @@ -4,31 +4,35 @@ public typealias SelectionRangeClientCapabilities = DynamicRegistrationClientCap public typealias SelectionRangeOptions = WorkDoneProgressOptions -public typealias SelectionRangeRegistrationOptions = StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions +public typealias SelectionRangeRegistrationOptions = + StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions public struct SelectionRangeParams: Codable, Hashable, Sendable { - public let workDoneToken: ProgressToken? - public let partialResultToken: ProgressToken? - public let textDocument: TextDocumentIdentifier - public let positions: [Position] - - public init(workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil, textDocument: TextDocumentIdentifier, positions: [Position]) { - self.workDoneToken = workDoneToken - self.partialResultToken = partialResultToken - self.textDocument = textDocument - self.positions = positions - } + public let workDoneToken: ProgressToken? + public let partialResultToken: ProgressToken? + public let textDocument: TextDocumentIdentifier + public let positions: [Position] + + public init( + workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil, + textDocument: TextDocumentIdentifier, positions: [Position] + ) { + self.workDoneToken = workDoneToken + self.partialResultToken = partialResultToken + self.textDocument = textDocument + self.positions = positions + } } public final class SelectionRange: Codable, Sendable { - public let range: LSPRange - public let parent: SelectionRange? + public let range: LSPRange + public let parent: SelectionRange? } extension SelectionRange: Equatable { - public static func == (lhs: SelectionRange, rhs: SelectionRange) -> Bool { - return lhs.range == rhs.range && lhs.parent == rhs.parent - } + public static func == (lhs: SelectionRange, rhs: SelectionRange) -> Bool { + return lhs.range == rhs.range && lhs.parent == rhs.parent + } } public typealias SelectionRangeResponse = [SelectionRange]? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/SemanticTokens.swift b/Sources/LanguageServerProtocol/LanguageFeatures/SemanticTokens.swift index 46a99cb..3f9a121 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/SemanticTokens.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/SemanticTokens.swift @@ -1,78 +1,80 @@ import Foundation public struct SemanticTokensWorkspaceClientCapabilities: Codable, Hashable, Sendable { - public var refreshSupport: Bool? + public var refreshSupport: Bool? - public init(refreshSupport: Bool) { - self.refreshSupport = refreshSupport - } + public init(refreshSupport: Bool) { + self.refreshSupport = refreshSupport + } } public enum TokenFormat: String, Codable, Hashable, Sendable { - case relative = "relative" + case relative = "relative" - public static let Relative = TokenFormat.relative + public static let Relative = TokenFormat.relative } public struct SemanticTokensClientCapabilities: Codable, Hashable, Sendable { - public struct Requests: Codable, Hashable, Sendable { - public struct Range: Codable, Hashable, Sendable { - } - - public struct Full: Codable, Hashable, Sendable { - public var delta: Bool? - - public init(delta: Bool = true) { - self.delta = delta - } - } - - public typealias RangeOption = TwoTypeOption - public typealias FullOption = TwoTypeOption - - public var range: RangeOption - public var full: FullOption - - public init(range: Bool = true, delta: Bool = true) { - self.range = .optionA(range) - self.full = .optionB(Full(delta: true)) - } - } - - public var dynamicRegistration: Bool? - public var requests: Requests - public var tokenTypes: [String] - public var tokenModifiers: [String] - public var formats: [TokenFormat] - public var overlappingTokenSupport: Bool? - public var multilineTokenSupport: Bool? - public var serverCancelSupport: Bool? - public var augmentsSyntaxTokens: Bool? - - public init(dynamicRegistration: Bool = false, - requests: SemanticTokensClientCapabilities.Requests = .init(range: true, delta: true), - tokenTypes: [String] = SemanticTokenTypes.allStrings, - tokenModifiers: [String] = SemanticTokenModifiers.allStrings, - formats: [TokenFormat] = [TokenFormat.relative], - overlappingTokenSupport: Bool = true, - multilineTokenSupport: Bool = true, - serverCancelSupport: Bool = false, - augmentsSyntaxTokens: Bool = true) { - self.dynamicRegistration = dynamicRegistration - self.requests = requests - self.tokenTypes = tokenTypes - self.tokenModifiers = tokenModifiers - self.formats = formats - self.overlappingTokenSupport = overlappingTokenSupport - self.multilineTokenSupport = multilineTokenSupport - self.serverCancelSupport = serverCancelSupport - self.augmentsSyntaxTokens = augmentsSyntaxTokens - } + public struct Requests: Codable, Hashable, Sendable { + public struct Range: Codable, Hashable, Sendable { + } + + public struct Full: Codable, Hashable, Sendable { + public var delta: Bool? + + public init(delta: Bool = true) { + self.delta = delta + } + } + + public typealias RangeOption = TwoTypeOption + public typealias FullOption = TwoTypeOption + + public var range: RangeOption + public var full: FullOption + + public init(range: Bool = true, delta: Bool = true) { + self.range = .optionA(range) + self.full = .optionB(Full(delta: true)) + } + } + + public var dynamicRegistration: Bool? + public var requests: Requests + public var tokenTypes: [String] + public var tokenModifiers: [String] + public var formats: [TokenFormat] + public var overlappingTokenSupport: Bool? + public var multilineTokenSupport: Bool? + public var serverCancelSupport: Bool? + public var augmentsSyntaxTokens: Bool? + + public init( + dynamicRegistration: Bool = false, + requests: SemanticTokensClientCapabilities.Requests = .init(range: true, delta: true), + tokenTypes: [String] = SemanticTokenTypes.allStrings, + tokenModifiers: [String] = SemanticTokenModifiers.allStrings, + formats: [TokenFormat] = [TokenFormat.relative], + overlappingTokenSupport: Bool = true, + multilineTokenSupport: Bool = true, + serverCancelSupport: Bool = false, + augmentsSyntaxTokens: Bool = true + ) { + self.dynamicRegistration = dynamicRegistration + self.requests = requests + self.tokenTypes = tokenTypes + self.tokenModifiers = tokenModifiers + self.formats = formats + self.overlappingTokenSupport = overlappingTokenSupport + self.multilineTokenSupport = multilineTokenSupport + self.serverCancelSupport = serverCancelSupport + self.augmentsSyntaxTokens = augmentsSyntaxTokens + } } public struct SemanticTokensLegend: Codable, Hashable, Sendable { - public var tokenTypes: [String] - public var tokenModifiers: [String] + public var tokenTypes: [String] + public var tokenModifiers: [String] public init(tokenTypes: [String], tokenModifiers: [String]) { self.tokenTypes = tokenTypes @@ -81,59 +83,59 @@ public struct SemanticTokensLegend: Codable, Hashable, Sendable { } public enum SemanticTokenTypes: String, Codable, Hashable, CaseIterable, Sendable { - case namespace = "namespace" - case type = "type" - case `class` = "class" - case `enum` = "enum" - case interface = "interface" - case `struct` = "struct" - case typeParameter = "typeParameter" - case parameter = "parameter" - case variable = "variable" - case property = "property" - case enumMember = "enumMember" - case event = "event" - case function = "function" - case method = "method" - case macro = "macro" - case keyword = "keyword" - case modifier = "modifier" - case comment = "comment" - case string = "string" - case number = "number" - case regexp = "regexp" - case `operator` = "operator" - - public static var allStrings: [String] { - return allCases.map({ $0.rawValue }) - } + case namespace = "namespace" + case type = "type" + case `class` = "class" + case `enum` = "enum" + case interface = "interface" + case `struct` = "struct" + case typeParameter = "typeParameter" + case parameter = "parameter" + case variable = "variable" + case property = "property" + case enumMember = "enumMember" + case event = "event" + case function = "function" + case method = "method" + case macro = "macro" + case keyword = "keyword" + case modifier = "modifier" + case comment = "comment" + case string = "string" + case number = "number" + case regexp = "regexp" + case `operator` = "operator" + + public static var allStrings: [String] { + return allCases.map({ $0.rawValue }) + } } public enum SemanticTokenModifiers: String, Codable, Hashable, CaseIterable, Sendable { - case declaration = "declaration" - case definition = "definition" - case readonly = "readonly" - case `static` = "static" - case deprecated = "deprecated" - case abstract = "abstract" - case async = "async" - case modification = "modification" - case documentation = "documentation" - case defaultLibrary = "defaultLibrary" - - public static var allStrings: [String] { - return allCases.map({ $0.rawValue }) - } + case declaration = "declaration" + case definition = "definition" + case readonly = "readonly" + case `static` = "static" + case deprecated = "deprecated" + case abstract = "abstract" + case async = "async" + case modification = "modification" + case documentation = "documentation" + case defaultLibrary = "defaultLibrary" + + public static var allStrings: [String] { + return allCases.map({ $0.rawValue }) + } } public struct SemanticTokensParams: Codable, Hashable, Sendable { - public var workDoneToken: ProgressToken? - public var partialResultToken: ProgressToken? - public var textDocument: TextDocumentIdentifier + public var workDoneToken: ProgressToken? + public var partialResultToken: ProgressToken? + public var textDocument: TextDocumentIdentifier - public init(textDocument: TextDocumentIdentifier) { - self.textDocument = textDocument - } + public init(textDocument: TextDocumentIdentifier) { + self.textDocument = textDocument + } } // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#documentSelector @@ -167,11 +169,10 @@ public struct SemanticTokens: Codable, Hashable, Sendable { * A server can then instead of computing all semantic tokens again simply * send a delta. */ - public var resultId: String? + public var resultId: String? /// Encoded token data - public var data: [UInt32] - + public var data: [UInt32] public init(resultId: String? = nil, data: [UInt32]) { self.resultId = resultId @@ -203,11 +204,11 @@ public struct SemanticTokens: Codable, Hashable, Sendable { let d0 = (tokens.startIndex + i) * SemanticToken.numFields let t = sortedTokens[i] - self.data[d0+0] = t.line - prevLine - self.data[d0+1] = t.char - prevCol - self.data[d0+2] = t.length - self.data[d0+3] = t.type - self.data[d0+4] = t.modifiers + self.data[d0 + 0] = t.line - prevLine + self.data[d0 + 1] = t.char - prevCol + self.data[d0 + 2] = t.length + self.data[d0 + 3] = t.type + self.data[d0 + 4] = t.modifiers prevLine = t.line prevCol = t.char @@ -226,7 +227,7 @@ public struct SemanticTokens: Codable, Hashable, Sendable { self.data = Array(repeating: 0, count: tokens.count * SemanticToken.numFields) var tail = tokens[...] - var lines: Array = [] + var lines: [Line] = [] while !tail.isEmpty { let line = getLineTokens(tail) lines.append(line) @@ -250,7 +251,7 @@ public struct SemanticTokens: Codable, Hashable, Sendable { var currentRow: UInt32 = 0 var currentCol: UInt32 = 0 - let numTokens = data.count/5 + let numTokens = data.count / 5 tokens.reserveCapacity(numTokens) for n in 0..? public struct SemanticTokensRangeParams: Codable, Hashable, Sendable { - public var workDoneToken: ProgressToken? - public var partialResultToken: ProgressToken? - public var textDocument: TextDocumentIdentifier - public var range: LSPRange - - public init(textDocument: TextDocumentIdentifier, range: LSPRange) { - self.textDocument = textDocument - self.range = range - } + public var workDoneToken: ProgressToken? + public var partialResultToken: ProgressToken? + public var textDocument: TextDocumentIdentifier + public var range: LSPRange + + public init(textDocument: TextDocumentIdentifier, range: LSPRange) { + self.textDocument = textDocument + self.range = range + } } -public extension TwoTypeOption where T == SemanticTokens, U == SemanticTokensDelta { - var resultId: String? { +extension TwoTypeOption where T == SemanticTokens, U == SemanticTokensDelta { + public var resultId: String? { switch self { case .optionA(let token): return token.resultId diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/SignatureHelp.swift b/Sources/LanguageServerProtocol/LanguageFeatures/SignatureHelp.swift index b4912b7..d6b9615 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/SignatureHelp.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/SignatureHelp.swift @@ -1,64 +1,75 @@ import Foundation public struct SignatureHelpClientCapabilities: Codable, Hashable, Sendable { - public struct SignatureInformation: Codable, Hashable, Sendable { - public struct ParameterInformation: Codable, Hashable, Sendable { - public var labelOffsetSupport: Bool? + public struct SignatureInformation: Codable, Hashable, Sendable { + public struct ParameterInformation: Codable, Hashable, Sendable { + public var labelOffsetSupport: Bool? - public init(labelOffsetSupport: Bool? = nil) { - self.labelOffsetSupport = labelOffsetSupport - } - } + public init(labelOffsetSupport: Bool? = nil) { + self.labelOffsetSupport = labelOffsetSupport + } + } - public var documentationFormat: [MarkupKind]? - public var parameterInformation: ParameterInformation? - public var activeParameterSupport: Bool? + public var documentationFormat: [MarkupKind]? + public var parameterInformation: ParameterInformation? + public var activeParameterSupport: Bool? - public init(documentationFormat: [MarkupKind]? = nil, parameterInformation: ParameterInformation? = nil, activeParameterSupport: Bool? = nil) { - self.documentationFormat = documentationFormat - self.parameterInformation = parameterInformation - self.activeParameterSupport = activeParameterSupport - } + public init( + documentationFormat: [MarkupKind]? = nil, + parameterInformation: ParameterInformation? = nil, activeParameterSupport: Bool? = nil + ) { + self.documentationFormat = documentationFormat + self.parameterInformation = parameterInformation + self.activeParameterSupport = activeParameterSupport + } - public init(documentationFormat: [MarkupKind]? = nil, labelOffsetSupport: Bool? = nil, activeParameterSupport: Bool? = nil) { - self.init(documentationFormat: documentationFormat, - parameterInformation: ParameterInformation(labelOffsetSupport: labelOffsetSupport), - activeParameterSupport: activeParameterSupport) - } - } + public init( + documentationFormat: [MarkupKind]? = nil, labelOffsetSupport: Bool? = nil, + activeParameterSupport: Bool? = nil + ) { + self.init( + documentationFormat: documentationFormat, + parameterInformation: ParameterInformation(labelOffsetSupport: labelOffsetSupport), + activeParameterSupport: activeParameterSupport) + } + } - public var dynamicRegistration: Bool? - public var signatureInformation: SignatureInformation? - public var contextSupport: Bool? + public var dynamicRegistration: Bool? + public var signatureInformation: SignatureInformation? + public var contextSupport: Bool? - public init(dynamicRegistration: Bool?, signatureInformation: SignatureHelpClientCapabilities.SignatureInformation?, contextSupport: Bool?) { - self.dynamicRegistration = dynamicRegistration - self.signatureInformation = signatureInformation - self.contextSupport = contextSupport - } + public init( + dynamicRegistration: Bool?, + signatureInformation: SignatureHelpClientCapabilities.SignatureInformation?, + contextSupport: Bool? + ) { + self.dynamicRegistration = dynamicRegistration + self.signatureInformation = signatureInformation + self.contextSupport = contextSupport + } } public struct ParameterInformation: Codable, Hashable, Sendable { - public var label: TwoTypeOption - public var documentation: TwoTypeOption? + public var label: TwoTypeOption + public var documentation: TwoTypeOption? } public struct SignatureInformation: Codable, Hashable, Sendable { - public var label: String - public var documentation: TwoTypeOption? - public var parameters: [ParameterInformation]? - public var activeParameter: UInt? + public var label: String + public var documentation: TwoTypeOption? + public var parameters: [ParameterInformation]? + public var activeParameter: UInt? } public struct SignatureHelp: Codable, Hashable, Sendable { - public let signatures: [SignatureInformation] - public let activeSignature: Int? - public let activeParameter: Int? + public let signatures: [SignatureInformation] + public let activeSignature: Int? + public let activeParameter: Int? } public struct SignatureHelpRegistrationOptions: Codable, Hashable, Sendable { - public let documentSelector: DocumentSelector? - public let triggerCharacters: [String]? + public let documentSelector: DocumentSelector? + public let triggerCharacters: [String]? } public typealias SignatureHelpResponse = SignatureHelp? diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/TypeHeirarchy.swift b/Sources/LanguageServerProtocol/LanguageFeatures/TypeHeirarchy.swift index 9419dcc..900c205 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/TypeHeirarchy.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/TypeHeirarchy.swift @@ -5,7 +5,10 @@ public struct TypeHierarchyPrepareParams: Codable, Hashable, Sendable { public let position: Position public let workDoneToken: ProgressToken? - public init(textDocument: TextDocumentIdentifier, position: Position, workDoneToken: ProgressToken? = nil) { + public init( + textDocument: TextDocumentIdentifier, position: Position, + workDoneToken: ProgressToken? = nil + ) { self.textDocument = textDocument self.position = position self.workDoneToken = workDoneToken diff --git a/Sources/LanguageServerProtocol/LanguageServerProtocol.swift b/Sources/LanguageServerProtocol/LanguageServerProtocol.swift index 37c34d2..ce56a37 100644 --- a/Sources/LanguageServerProtocol/LanguageServerProtocol.swift +++ b/Sources/LanguageServerProtocol/LanguageServerProtocol.swift @@ -14,7 +14,6 @@ public enum ProtocolError: Error { public typealias ServerError = ProtocolError public typealias ClientError = ProtocolError - public enum ClientEvent: Sendable { public typealias RequestResult = Result public typealias RequestHandler = @Sendable (RequestResult) async -> Void @@ -25,7 +24,6 @@ public enum ClientEvent: Sendable { // case error(ClientError) } - public enum ServerEvent: Sendable { public typealias RequestResult = Result public typealias RequestHandler = @Sendable (RequestResult) async -> Void @@ -36,84 +34,85 @@ public enum ServerEvent: Sendable { // case error(ServerError) } - public enum ClientNotification: Sendable, Hashable { - public enum Method: String, Hashable, Sendable { - case initialized - case exit + public enum Method: String, Hashable, Sendable { + case initialized + case exit case windowWorkDoneProgressCancel = "window/workDoneProgress/cancel" - case workspaceDidChangeWatchedFiles = "workspace/didChangeWatchedFiles" - case workspaceDidChangeConfiguration = "workspace/didChangeConfiguration" - case workspaceDidChangeWorkspaceFolders = "workspace/didChangeWorkspaceFolders" - case workspaceDidCreateFiles = "workspace/didCreateFiles" - case workspaceDidRenameFiles = "workspace/didRenameFiles" - case workspaceDidDeleteFiles = "workspace/didDeleteFiles" - case textDocumentDidOpen = "textDocument/didOpen" - case textDocumentDidChange = "textDocument/didChange" - case textDocumentDidClose = "textDocument/didClose" - case textDocumentWillSave = "textDocument/willSave" - case textDocumentDidSave = "textDocument/didSave" - case protocolCancelRequest = "$/cancelRequest" - case protocolSetTrace = "$/setTrace" - } + case workspaceDidChangeWatchedFiles = "workspace/didChangeWatchedFiles" + case workspaceDidChangeConfiguration = "workspace/didChangeConfiguration" + case workspaceDidChangeWorkspaceFolders = "workspace/didChangeWorkspaceFolders" + case workspaceDidCreateFiles = "workspace/didCreateFiles" + case workspaceDidRenameFiles = "workspace/didRenameFiles" + case workspaceDidDeleteFiles = "workspace/didDeleteFiles" + case textDocumentDidOpen = "textDocument/didOpen" + case textDocumentDidChange = "textDocument/didChange" + case textDocumentDidClose = "textDocument/didClose" + case textDocumentWillSave = "textDocument/willSave" + case textDocumentDidSave = "textDocument/didSave" + case protocolCancelRequest = "$/cancelRequest" + case protocolSetTrace = "$/setTrace" + } - case initialized(InitializedParams) - case exit - case textDocumentDidOpen(DidOpenTextDocumentParams) - case textDocumentDidChange(DidChangeTextDocumentParams) - case textDocumentDidClose(DidCloseTextDocumentParams) - case textDocumentWillSave(WillSaveTextDocumentParams) - case textDocumentDidSave(DidSaveTextDocumentParams) - case protocolCancelRequest(CancelParams) - case protocolSetTrace(SetTraceParams) - case workspaceDidChangeWatchedFiles(DidChangeWatchedFilesParams) + case initialized(InitializedParams) + case exit + case textDocumentDidOpen(DidOpenTextDocumentParams) + case textDocumentDidChange(DidChangeTextDocumentParams) + case textDocumentDidClose(DidCloseTextDocumentParams) + case textDocumentWillSave(WillSaveTextDocumentParams) + case textDocumentDidSave(DidSaveTextDocumentParams) + case protocolCancelRequest(CancelParams) + case protocolSetTrace(SetTraceParams) + case workspaceDidChangeWatchedFiles(DidChangeWatchedFilesParams) case windowWorkDoneProgressCancel(WorkDoneProgressCancelParams) - case workspaceDidChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams) - case workspaceDidChangeConfiguration(DidChangeConfigurationParams) - case workspaceDidCreateFiles(CreateFilesParams) - case workspaceDidRenameFiles(RenameFilesParams) - case workspaceDidDeleteFiles(DeleteFilesParams) + case workspaceDidChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams) + case workspaceDidChangeConfiguration(DidChangeConfigurationParams) + case workspaceDidCreateFiles(CreateFilesParams) + case workspaceDidRenameFiles(RenameFilesParams) + case workspaceDidDeleteFiles(DeleteFilesParams) - public var method: Method { - switch self { - case .initialized: - return .initialized - case .exit: - return .exit - case .textDocumentDidChange: - return .textDocumentDidChange - case .textDocumentDidOpen: - return .textDocumentDidOpen - case .textDocumentDidClose: - return .textDocumentDidClose - case .textDocumentWillSave: - return .textDocumentWillSave - case .textDocumentDidSave: - return .textDocumentDidSave - case .workspaceDidChangeWatchedFiles: - return .workspaceDidChangeWatchedFiles - case .protocolCancelRequest: - return .protocolCancelRequest - case .protocolSetTrace: - return .protocolSetTrace + public var method: Method { + switch self { + case .initialized: + return .initialized + case .exit: + return .exit + case .textDocumentDidChange: + return .textDocumentDidChange + case .textDocumentDidOpen: + return .textDocumentDidOpen + case .textDocumentDidClose: + return .textDocumentDidClose + case .textDocumentWillSave: + return .textDocumentWillSave + case .textDocumentDidSave: + return .textDocumentDidSave + case .workspaceDidChangeWatchedFiles: + return .workspaceDidChangeWatchedFiles + case .protocolCancelRequest: + return .protocolCancelRequest + case .protocolSetTrace: + return .protocolSetTrace case .windowWorkDoneProgressCancel: return .windowWorkDoneProgressCancel - case .workspaceDidChangeWorkspaceFolders: - return .workspaceDidChangeWorkspaceFolders - case .workspaceDidChangeConfiguration: - return .workspaceDidChangeConfiguration - case .workspaceDidCreateFiles: - return .workspaceDidCreateFiles - case .workspaceDidRenameFiles: - return .workspaceDidRenameFiles - case .workspaceDidDeleteFiles: - return .workspaceDidDeleteFiles - } - } + case .workspaceDidChangeWorkspaceFolders: + return .workspaceDidChangeWorkspaceFolders + case .workspaceDidChangeConfiguration: + return .workspaceDidChangeConfiguration + case .workspaceDidCreateFiles: + return .workspaceDidCreateFiles + case .workspaceDidRenameFiles: + return .workspaceDidRenameFiles + case .workspaceDidDeleteFiles: + return .workspaceDidDeleteFiles + } + } } public enum ClientRequest: Sendable { - public typealias Handler = @Sendable (Result) async -> Void + public typealias Handler = @Sendable ( + Result + ) async -> Void public typealias ErrorOnlyHandler = @Sendable (AnyJSONRPCResponseError?) async -> Void // NOTE: The same `ClientRequest` type is used on the client side and the server side, only the server use the handler to send back the response, on the client side we use the `NullHandler`, which will never be called @@ -122,59 +121,58 @@ public enum ClientRequest: Sendable { // throw NullHandlerError.notImplemented(result) } - public enum Method: String, Hashable, Sendable { - case initialize - case shutdown - case workspaceExecuteCommand = "workspace/executeCommand" + case initialize + case shutdown + case workspaceExecuteCommand = "workspace/executeCommand" case workspaceInlayHintRefresh = "workspace/inlayHint/refresh" - case workspaceWillCreateFiles = "workspace/willCreateFiles" - case workspaceWillRenameFiles = "workspace/willRenameFiles" - case workspaceWillDeleteFiles = "workspace/willDeleteFiles" - case workspaceSymbol = "workspace/symbol" - case workspaceSymbolResolve = "workspaceSymbol/resolve" - case textDocumentWillSaveWaitUntil = "textDocument/willSaveWaitUntil" - case textDocumentCompletion = "textDocument/completion" - case completionItemResolve = "completionItem/resolve" - case textDocumentHover = "textDocument/hover" - case textDocumentSignatureHelp = "textDocument/signatureHelp" - case textDocumentDeclaration = "textDocument/declaration" - case textDocumentDefinition = "textDocument/definition" + case workspaceWillCreateFiles = "workspace/willCreateFiles" + case workspaceWillRenameFiles = "workspace/willRenameFiles" + case workspaceWillDeleteFiles = "workspace/willDeleteFiles" + case workspaceSymbol = "workspace/symbol" + case workspaceSymbolResolve = "workspaceSymbol/resolve" + case textDocumentWillSaveWaitUntil = "textDocument/willSaveWaitUntil" + case textDocumentCompletion = "textDocument/completion" + case completionItemResolve = "completionItem/resolve" + case textDocumentHover = "textDocument/hover" + case textDocumentSignatureHelp = "textDocument/signatureHelp" + case textDocumentDeclaration = "textDocument/declaration" + case textDocumentDefinition = "textDocument/definition" case textDocumentPrepareTypeHierarchy = "textDocument/prepareTypeHierarchy" - case textDocumentTypeDefinition = "textDocument/typeDefinition" - case textDocumentImplementation = "textDocument/implementation" - case textDocumentReferences = "textDocument/references" - case textDocumentDocumentHighlight = "textDocument/documentHighlight" - case textDocumentDocumentSymbol = "textDocument/documentSymbol" - case textDocumentCodeAction = "textDocument/codeAction" + case textDocumentTypeDefinition = "textDocument/typeDefinition" + case textDocumentImplementation = "textDocument/implementation" + case textDocumentReferences = "textDocument/references" + case textDocumentDocumentHighlight = "textDocument/documentHighlight" + case textDocumentDocumentSymbol = "textDocument/documentSymbol" + case textDocumentCodeAction = "textDocument/codeAction" case codeActionResolve = "codeAction/resolve" - case codeLensResolve = "codeLens/resolve" - case textDocumentCodeLens = "textDocument/codeLens" + case codeLensResolve = "codeLens/resolve" + case textDocumentCodeLens = "textDocument/codeLens" case textDocumentDiagnostic = "textDocument/diagnostic" - case textDocumentDocumentLink = "textDocument/documentLink" - case documentLinkResolve = "documentLink/resolve" - case textDocumentDocumentColor = "textDocument/documentColor" - case textDocumentColorPresentation = "textDocument/colorPresentation" - case textDocumentFormatting = "textDocument/formatting" - case textDocumentRangeFormatting = "textDocument/rangeFormatting" - case textDocumentOnTypeFormatting = "textDocument/onTypeFormatting" - case textDocumentRename = "textDocument/rename" + case textDocumentDocumentLink = "textDocument/documentLink" + case documentLinkResolve = "documentLink/resolve" + case textDocumentDocumentColor = "textDocument/documentColor" + case textDocumentColorPresentation = "textDocument/colorPresentation" + case textDocumentFormatting = "textDocument/formatting" + case textDocumentRangeFormatting = "textDocument/rangeFormatting" + case textDocumentOnTypeFormatting = "textDocument/onTypeFormatting" + case textDocumentRename = "textDocument/rename" case textDocumentInlayHint = "textDocument/inlayHint" case inlayHintResolve = "inlayHint/resolve" - case textDocumentPrepareRename = "textDocument/prepareRename" + case textDocumentPrepareRename = "textDocument/prepareRename" case textDocumentPrepareCallHierarchy = "textDocument/prepareCallHierarchy" - case textDocumentFoldingRange = "textDocument/foldingRange" - case textDocumentSelectionRange = "textDocument/selectionRange" - case textDocumentLinkedEditingRange = "textDocument/linkedEditingRange" - case textDocumentSemanticTokens = "textDocument/semanticTokens" - case textDocumentSemanticTokensRange = "textDocument/semanticTokens/range" - case textDocumentSemanticTokensFull = "textDocument/semanticTokens/full" - case textDocumentSemanticTokensFullDelta = "textDocument/semanticTokens/full/delta" - case textDocumentMoniker = "textDocument/moniker" + case textDocumentFoldingRange = "textDocument/foldingRange" + case textDocumentSelectionRange = "textDocument/selectionRange" + case textDocumentLinkedEditingRange = "textDocument/linkedEditingRange" + case textDocumentSemanticTokens = "textDocument/semanticTokens" + case textDocumentSemanticTokensRange = "textDocument/semanticTokens/range" + case textDocumentSemanticTokensFull = "textDocument/semanticTokens/full" + case textDocumentSemanticTokensFullDelta = "textDocument/semanticTokens/full/delta" + case textDocumentMoniker = "textDocument/moniker" case callHierarchyIncomingCalls = "callHierarchy/incomingCalls" case callHierarchyOutgoingCalls = "callHierarchy/outgoingCalls" - case custom - } + case custom + } case initialize(InitializeParams, Handler) case shutdown(Handler) @@ -222,112 +220,114 @@ public enum ClientRequest: Sendable { case semanticTokensFull(SemanticTokensParams, Handler) case semanticTokensFullDelta(SemanticTokensDeltaParams, Handler) case semanticTokensRange(SemanticTokensRangeParams, Handler) - case callHierarchyIncomingCalls(CallHierarchyIncomingCallsParams, Handler) - case callHierarchyOutgoingCalls(CallHierarchyOutgoingCallsParams, Handler) + case callHierarchyIncomingCalls( + CallHierarchyIncomingCallsParams, Handler) + case callHierarchyOutgoingCalls( + CallHierarchyOutgoingCallsParams, Handler) case custom(String, LSPAny, Handler) - public var method: Method { - switch self { - case .initialize: - return .initialize - case .shutdown: - return .shutdown - case .workspaceExecuteCommand: - return .workspaceExecuteCommand + public var method: Method { + switch self { + case .initialize: + return .initialize + case .shutdown: + return .shutdown + case .workspaceExecuteCommand: + return .workspaceExecuteCommand case .workspaceInlayHintRefresh: return .workspaceInlayHintRefresh - case .workspaceWillCreateFiles: - return .workspaceWillCreateFiles - case .workspaceWillRenameFiles: - return .workspaceWillRenameFiles - case .workspaceWillDeleteFiles: - return .workspaceWillDeleteFiles - case .workspaceSymbol: - return .workspaceSymbol - case .workspaceSymbolResolve: - return .workspaceSymbolResolve - case .textDocumentWillSaveWaitUntil: - return .textDocumentWillSaveWaitUntil - case .completion: - return .textDocumentCompletion - case .completionItemResolve: - return .completionItemResolve - case .hover: - return .textDocumentHover - case .signatureHelp: - return .textDocumentSignatureHelp - case .declaration: - return .textDocumentDeclaration - case .definition: - return .textDocumentDefinition - case .typeDefinition: - return .textDocumentTypeDefinition - case .implementation: - return .textDocumentImplementation - case .documentHighlight: - return .textDocumentDocumentHighlight - case .documentSymbol: - return .textDocumentDocumentSymbol - case .codeAction: - return .textDocumentCodeAction + case .workspaceWillCreateFiles: + return .workspaceWillCreateFiles + case .workspaceWillRenameFiles: + return .workspaceWillRenameFiles + case .workspaceWillDeleteFiles: + return .workspaceWillDeleteFiles + case .workspaceSymbol: + return .workspaceSymbol + case .workspaceSymbolResolve: + return .workspaceSymbolResolve + case .textDocumentWillSaveWaitUntil: + return .textDocumentWillSaveWaitUntil + case .completion: + return .textDocumentCompletion + case .completionItemResolve: + return .completionItemResolve + case .hover: + return .textDocumentHover + case .signatureHelp: + return .textDocumentSignatureHelp + case .declaration: + return .textDocumentDeclaration + case .definition: + return .textDocumentDefinition + case .typeDefinition: + return .textDocumentTypeDefinition + case .implementation: + return .textDocumentImplementation + case .documentHighlight: + return .textDocumentDocumentHighlight + case .documentSymbol: + return .textDocumentDocumentSymbol + case .codeAction: + return .textDocumentCodeAction case .codeActionResolve: return .codeActionResolve - case .codeLens: - return .textDocumentCodeLens - case .codeLensResolve: - return .codeLensResolve - case .selectionRange: - return .textDocumentSelectionRange + case .codeLens: + return .textDocumentCodeLens + case .codeLensResolve: + return .codeLensResolve + case .selectionRange: + return .textDocumentSelectionRange case .linkedEditingRange: return .textDocumentLinkedEditingRange case .prepareCallHierarchy: return .textDocumentPrepareCallHierarchy - case .prepareRename: - return .textDocumentPrepareRename + case .prepareRename: + return .textDocumentPrepareRename case .prepareTypeHierarchy: return .textDocumentPrepareTypeHierarchy - case .rename: - return .textDocumentRename + case .rename: + return .textDocumentRename case .inlayHint: return .textDocumentInlayHint case .inlayHintResolve: return .inlayHintResolve - case .documentLink: - return .textDocumentDocumentLink - case .documentLinkResolve: - return .documentLinkResolve - case .documentColor: - return .textDocumentDocumentColor + case .documentLink: + return .textDocumentDocumentLink + case .documentLinkResolve: + return .documentLinkResolve + case .documentColor: + return .textDocumentDocumentColor case .diagnostics: return .textDocumentDiagnostic - case .colorPresentation: - return .textDocumentColorPresentation - case .formatting: - return .textDocumentFormatting - case .rangeFormatting: - return .textDocumentRangeFormatting - case .onTypeFormatting: - return .textDocumentOnTypeFormatting - case .references: - return .textDocumentReferences - case .foldingRange: - return .textDocumentFoldingRange + case .colorPresentation: + return .textDocumentColorPresentation + case .formatting: + return .textDocumentFormatting + case .rangeFormatting: + return .textDocumentRangeFormatting + case .onTypeFormatting: + return .textDocumentOnTypeFormatting + case .references: + return .textDocumentReferences + case .foldingRange: + return .textDocumentFoldingRange case .moniker: - return .textDocumentMoniker - case .semanticTokensFull: - return .textDocumentSemanticTokensFull - case .semanticTokensFullDelta: - return .textDocumentSemanticTokensFullDelta - case .semanticTokensRange: - return .textDocumentSemanticTokensRange + return .textDocumentMoniker + case .semanticTokensFull: + return .textDocumentSemanticTokensFull + case .semanticTokensFullDelta: + return .textDocumentSemanticTokensFullDelta + case .semanticTokensRange: + return .textDocumentSemanticTokensRange case .callHierarchyIncomingCalls: return .callHierarchyIncomingCalls case .callHierarchyOutgoingCalls: return .callHierarchyOutgoingCalls - case .custom: - return .custom - } - } + case .custom: + return .custom + } + } } extension ClientRequest: Equatable { @@ -336,9 +336,13 @@ extension ClientRequest: Equatable { /// This really stinks. But, the handler parameter was a big win for server-side development, and this is a one-time cost. Still, error-prone. Please take care when adding/modifying. public static func == (lhs: ClientRequest, rhs: ClientRequest) -> Bool { switch (lhs, rhs) { - case let (.callHierarchyIncomingCalls(lhsParam, _), .callHierarchyIncomingCalls(rhsParam, _)): + case let ( + .callHierarchyIncomingCalls(lhsParam, _), .callHierarchyIncomingCalls(rhsParam, _) + ): return lhsParam == rhsParam - case let (.callHierarchyOutgoingCalls(lhsParam, _), .callHierarchyOutgoingCalls(rhsParam, _)): + case let ( + .callHierarchyOutgoingCalls(lhsParam, _), .callHierarchyOutgoingCalls(rhsParam, _) + ): return lhsParam == rhsParam case let (.codeAction(lhsParam, _), .codeAction(rhsParam, _)): return lhsParam == rhsParam @@ -416,7 +420,9 @@ extension ClientRequest: Equatable { return true case let (.signatureHelp(lhsParam, _), .signatureHelp(rhsParam, _)): return lhsParam == rhsParam - case let (.textDocumentWillSaveWaitUntil(lhsParam, _), .textDocumentWillSaveWaitUntil(rhsParam, _)): + case let ( + .textDocumentWillSaveWaitUntil(lhsParam, _), .textDocumentWillSaveWaitUntil(rhsParam, _) + ): return lhsParam == rhsParam case let (.typeDefinition(lhsParam, _), .typeDefinition(rhsParam, _)): return lhsParam == rhsParam @@ -441,100 +447,103 @@ extension ClientRequest: Equatable { } public enum ServerNotification: Sendable, Hashable { - public enum Method: String, Hashable, Sendable { - case windowLogMessage = "window/logMessage" - case windowShowMessage = "window/showMessage" - case textDocumentPublishDiagnostics = "textDocument/publishDiagnostics" - case telemetryEvent = "telemetry/event" - case protocolCancelRequest = "$/cancelRequest" - case protocolProgress = "$/progress" - case protocolLogTrace = "$/logTrace" - } + public enum Method: String, Hashable, Sendable { + case windowLogMessage = "window/logMessage" + case windowShowMessage = "window/showMessage" + case textDocumentPublishDiagnostics = "textDocument/publishDiagnostics" + case telemetryEvent = "telemetry/event" + case protocolCancelRequest = "$/cancelRequest" + case protocolProgress = "$/progress" + case protocolLogTrace = "$/logTrace" + } - case windowLogMessage(LogMessageParams) - case windowShowMessage(ShowMessageParams) - case textDocumentPublishDiagnostics(PublishDiagnosticsParams) - case telemetryEvent(LSPAny) - case protocolCancelRequest(CancelParams) - case protocolProgress(ProgressParams) - case protocolLogTrace(LogTraceParams) + case windowLogMessage(LogMessageParams) + case windowShowMessage(ShowMessageParams) + case textDocumentPublishDiagnostics(PublishDiagnosticsParams) + case telemetryEvent(LSPAny) + case protocolCancelRequest(CancelParams) + case protocolProgress(ProgressParams) + case protocolLogTrace(LogTraceParams) - public var method: Method { - switch self { - case .windowLogMessage: - return .windowLogMessage - case .windowShowMessage: - return .windowShowMessage - case .textDocumentPublishDiagnostics: - return .textDocumentPublishDiagnostics - case .telemetryEvent: - return .telemetryEvent - case .protocolCancelRequest: - return .protocolCancelRequest - case .protocolProgress: - return .protocolProgress - case .protocolLogTrace: - return .protocolLogTrace - } - } + public var method: Method { + switch self { + case .windowLogMessage: + return .windowLogMessage + case .windowShowMessage: + return .windowShowMessage + case .textDocumentPublishDiagnostics: + return .textDocumentPublishDiagnostics + case .telemetryEvent: + return .telemetryEvent + case .protocolCancelRequest: + return .protocolCancelRequest + case .protocolProgress: + return .protocolProgress + case .protocolLogTrace: + return .protocolLogTrace + } + } } public enum ServerRequest: Sendable { - public typealias Handler = @Sendable (Result) async -> Void + public typealias Handler = @Sendable ( + Result + ) async -> Void public typealias VoidHandler = @Sendable () async -> Void public typealias ErrorOnlyHandler = @Sendable (AnyJSONRPCResponseError?) async -> Void - public enum Method: String { - case workspaceConfiguration = "workspace/configuration" - case workspaceFolders = "workspace/workspaceFolders" - case workspaceApplyEdit = "workspace/applyEdit" - case clientRegisterCapability = "client/registerCapability" - case clientUnregisterCapability = "client/unregisterCapability" - case workspaceCodeLensRefresh = "workspace/codeLens/refresh" - case workspaceSemanticTokenRefresh = "workspace/semanticTokens/refresh" - case windowShowMessageRequest = "window/showMessageRequest" - case windowShowDocument = "window/showDocument" - case windowWorkDoneProgressCreate = "window/workDoneProgress/create" - } + public enum Method: String { + case workspaceConfiguration = "workspace/configuration" + case workspaceFolders = "workspace/workspaceFolders" + case workspaceApplyEdit = "workspace/applyEdit" + case clientRegisterCapability = "client/registerCapability" + case clientUnregisterCapability = "client/unregisterCapability" + case workspaceCodeLensRefresh = "workspace/codeLens/refresh" + case workspaceSemanticTokenRefresh = "workspace/semanticTokens/refresh" + case windowShowMessageRequest = "window/showMessageRequest" + case windowShowDocument = "window/showDocument" + case windowWorkDoneProgressCreate = "window/workDoneProgress/create" + } - case workspaceConfiguration(ConfigurationParams, Handler<[LSPAny]>) - case workspaceFolders(Handler) - case workspaceApplyEdit(ApplyWorkspaceEditParams, Handler) - case clientRegisterCapability(RegistrationParams, ErrorOnlyHandler) - case clientUnregisterCapability(UnregistrationParams, ErrorOnlyHandler) - case workspaceCodeLensRefresh(ErrorOnlyHandler) - case workspaceSemanticTokenRefresh(ErrorOnlyHandler) - case windowShowMessageRequest(ShowMessageRequestParams, Handler) - case windowShowDocument(ShowDocumentParams, Handler) + case workspaceConfiguration(ConfigurationParams, Handler<[LSPAny]>) + case workspaceFolders(Handler) + case workspaceApplyEdit(ApplyWorkspaceEditParams, Handler) + case clientRegisterCapability(RegistrationParams, ErrorOnlyHandler) + case clientUnregisterCapability(UnregistrationParams, ErrorOnlyHandler) + case workspaceCodeLensRefresh(ErrorOnlyHandler) + case workspaceSemanticTokenRefresh(ErrorOnlyHandler) + case windowShowMessageRequest(ShowMessageRequestParams, Handler) + case windowShowDocument(ShowDocumentParams, Handler) case windowWorkDoneProgressCreate(WorkDoneProgressCreateParams, ErrorOnlyHandler) - public var method: Method { - switch self { - case .workspaceConfiguration: - return .workspaceConfiguration - case .workspaceFolders: - return .workspaceFolders - case .workspaceApplyEdit: - return .workspaceApplyEdit - case .clientRegisterCapability: - return .clientRegisterCapability - case .clientUnregisterCapability: - return .clientUnregisterCapability - case .workspaceCodeLensRefresh: - return .workspaceCodeLensRefresh - case .workspaceSemanticTokenRefresh: - return .workspaceSemanticTokenRefresh - case .windowShowMessageRequest: - return .windowShowMessageRequest - case .windowShowDocument: - return .windowShowDocument - case .windowWorkDoneProgressCreate: - return .windowWorkDoneProgressCreate - } - } + public var method: Method { + switch self { + case .workspaceConfiguration: + return .workspaceConfiguration + case .workspaceFolders: + return .workspaceFolders + case .workspaceApplyEdit: + return .workspaceApplyEdit + case .clientRegisterCapability: + return .clientRegisterCapability + case .clientUnregisterCapability: + return .clientUnregisterCapability + case .workspaceCodeLensRefresh: + return .workspaceCodeLensRefresh + case .workspaceSemanticTokenRefresh: + return .workspaceSemanticTokenRefresh + case .windowShowMessageRequest: + return .windowShowMessageRequest + case .windowShowDocument: + return .windowShowDocument + case .windowWorkDoneProgressCreate: + return .windowWorkDoneProgressCreate + } + } public func relyWithError(_ error: Error) async { - let protocolError = AnyJSONRPCResponseError(code: JSONRPCErrors.internalError, message: "unsupported", data: nil) + let protocolError = AnyJSONRPCResponseError( + code: JSONRPCErrors.internalError, message: "unsupported", data: nil) switch self { case let .workspaceConfiguration(_, handler): @@ -562,29 +571,29 @@ public enum ServerRequest: Sendable { } public enum ServerRegistration { - public enum Method: String { - case workspaceDidChangeWatchedFiles = "workspace/didChangeWatchedFiles" - case workspaceDidChangeConfiguration = "workspace/didChangeConfiguration" - case workspaceDidChangeWorkspaceFolders = "workspace/didChangeWorkspaceFolders" + public enum Method: String { + case workspaceDidChangeWatchedFiles = "workspace/didChangeWatchedFiles" + case workspaceDidChangeConfiguration = "workspace/didChangeConfiguration" + case workspaceDidChangeWorkspaceFolders = "workspace/didChangeWorkspaceFolders" - case textDocumentSemanticTokens = "textDocument/semanticTokens" - } + case textDocumentSemanticTokens = "textDocument/semanticTokens" + } - case workspaceDidChangeWatchedFiles(DidChangeWatchedFilesRegistrationOptions) - case textDocumentSemanticTokens(SemanticTokensRegistrationOptions) - case workspaceDidChangeConfiguration - case workspaceDidChangeWorkspaceFolders + case workspaceDidChangeWatchedFiles(DidChangeWatchedFilesRegistrationOptions) + case textDocumentSemanticTokens(SemanticTokensRegistrationOptions) + case workspaceDidChangeConfiguration + case workspaceDidChangeWorkspaceFolders - public var method: Method { - switch self { - case .workspaceDidChangeWatchedFiles: - return .workspaceDidChangeWatchedFiles - case .textDocumentSemanticTokens: - return .textDocumentSemanticTokens - case .workspaceDidChangeConfiguration: - return .workspaceDidChangeConfiguration - case .workspaceDidChangeWorkspaceFolders: - return .workspaceDidChangeWorkspaceFolders - } - } + public var method: Method { + switch self { + case .workspaceDidChangeWatchedFiles: + return .workspaceDidChangeWatchedFiles + case .textDocumentSemanticTokens: + return .textDocumentSemanticTokens + case .workspaceDidChangeConfiguration: + return .workspaceDidChangeConfiguration + case .workspaceDidChangeWorkspaceFolders: + return .workspaceDidChangeWorkspaceFolders + } + } } diff --git a/Sources/LanguageServerProtocol/ServerCapabilities.swift b/Sources/LanguageServerProtocol/ServerCapabilities.swift index c9d3044..56c3dce 100644 --- a/Sources/LanguageServerProtocol/ServerCapabilities.swift +++ b/Sources/LanguageServerProtocol/ServerCapabilities.swift @@ -1,60 +1,67 @@ import Foundation -public struct StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var textDocument: TextDocumentIdentifier - public var position: Position - public var documentSelector: DocumentSelector? - public var id: String? +public struct StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions: Codable, Hashable, + Sendable +{ + public var workDoneProgress: Bool? + public var textDocument: TextDocumentIdentifier + public var position: Position + public var documentSelector: DocumentSelector? + public var id: String? } -public struct PartialResultsWorkDoneProgressTextDocumentRegistrationOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var textDocument: TextDocumentIdentifier - public var position: Position - public var documentSelector: DocumentSelector? - public var partialResultToken: ProgressToken? +public struct PartialResultsWorkDoneProgressTextDocumentRegistrationOptions: Codable, Hashable, + Sendable +{ + public var workDoneProgress: Bool? + public var textDocument: TextDocumentIdentifier + public var position: Position + public var documentSelector: DocumentSelector? + public var partialResultToken: ProgressToken? } public struct WorkDoneProgressOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? + public var workDoneProgress: Bool? } public struct SaveOptions: Codable, Hashable, Sendable { - public let includeText: Bool? + public let includeText: Bool? } public enum TextDocumentSyncKind: Int, Codable, Hashable, Sendable { - case none = 0 - case full = 1 - case incremental = 2 + case none = 0 + case full = 1 + case incremental = 2 } public struct TextDocumentSyncOptions: Codable, Hashable, Sendable { - public var openClose: Bool? - public var change: TextDocumentSyncKind? - public var willSave: Bool? - public var willSaveWaitUntil: Bool? - public var save: TwoTypeOption? - - public var effectiveSave: SaveOptions? { - switch save { - case nil: - return nil - case .optionA(let value): - return value ? SaveOptions(includeText: false) : nil - case .optionB(let options): - return options - } - } - - public init(openClose: Bool? = nil, change: TextDocumentSyncKind? = nil, willSave: Bool? = nil, willSaveWaitUntil: Bool? = nil, save: TwoTypeOption? = nil) { - self.openClose = openClose - self.change = change - self.willSave = willSave - self.willSaveWaitUntil = willSaveWaitUntil - self.save = save - } + public var openClose: Bool? + public var change: TextDocumentSyncKind? + public var willSave: Bool? + public var willSaveWaitUntil: Bool? + public var save: TwoTypeOption? + + public var effectiveSave: SaveOptions? { + switch save { + case nil: + return nil + case .optionA(let value): + return value ? SaveOptions(includeText: false) : nil + case .optionB(let options): + return options + } + } + + public init( + openClose: Bool? = nil, change: TextDocumentSyncKind? = nil, willSave: Bool? = nil, + willSaveWaitUntil: Bool? = nil, save: TwoTypeOption? = nil + ) { + self.openClose = openClose + self.change = change + self.willSave = willSave + self.willSaveWaitUntil = willSaveWaitUntil + self.save = save + } } @@ -91,60 +98,70 @@ public struct CompletionOptions: Codable, Hashable, Sendable { public typealias HoverOptions = WorkDoneProgressOptions public struct SignatureHelpOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var triggerCharacters: [String]? - public var retriggerCharacters: [String]? + public var workDoneProgress: Bool? + public var triggerCharacters: [String]? + public var retriggerCharacters: [String]? } public typealias DeclarationOptions = WorkDoneProgressOptions -public typealias DeclarationRegistrationOptions = StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions +public typealias DeclarationRegistrationOptions = + StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions public typealias DefinitionOptions = WorkDoneProgressOptions public typealias TypeDefinitionOptions = WorkDoneProgressOptions -public typealias TypeDefinitionRegistrationOptions = PartialResultsWorkDoneProgressTextDocumentRegistrationOptions +public typealias TypeDefinitionRegistrationOptions = + PartialResultsWorkDoneProgressTextDocumentRegistrationOptions public typealias ImplementationOptions = WorkDoneProgressOptions -public typealias ImplementationRegistrationOptions = StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions +public typealias ImplementationRegistrationOptions = + StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions public typealias ReferenceOptions = WorkDoneProgressOptions public struct DocumentSymbolOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var label: String? + public var workDoneProgress: Bool? + public var label: String? } public typealias DocumentColorOptions = WorkDoneProgressOptions -public typealias DocumentColorRegistrationOptions = StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions +public typealias DocumentColorRegistrationOptions = + StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions public typealias DocumentFormattingOptions = WorkDoneProgressOptions public typealias DocumentRangeFormattingOptions = WorkDoneProgressOptions public struct DocumentOnTypeFormattingOptions: Codable, Hashable, Sendable { - public var firstTriggerCharacter: String - public var moreTriggerCharacter: [String]? + public var firstTriggerCharacter: String + public var moreTriggerCharacter: [String]? } public typealias FoldingRangeOptions = WorkDoneProgressOptions -public typealias FoldingRangeRegistrationOptions = StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions +public typealias FoldingRangeRegistrationOptions = + StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions public typealias LinkedEditingRangeOptions = WorkDoneProgressOptions -public typealias LinkedEditingRangeRegistrationOptions = StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions +public typealias LinkedEditingRangeRegistrationOptions = + StaticRegistrationWorkDoneProgressTextDocumentRegistrationOptions public struct SemanticTokensOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var legend: SemanticTokensLegend - public var range: SemanticTokensClientCapabilities.Requests.RangeOption? - public var full: SemanticTokensClientCapabilities.Requests.FullOption? + public var workDoneProgress: Bool? + public var legend: SemanticTokensLegend + public var range: SemanticTokensClientCapabilities.Requests.RangeOption? + public var full: SemanticTokensClientCapabilities.Requests.FullOption? - public init(workDoneProgress: Bool? = nil, legend: SemanticTokensLegend, range: SemanticTokensClientCapabilities.Requests.RangeOption? = nil, full: SemanticTokensClientCapabilities.Requests.FullOption? = nil) { + public init( + workDoneProgress: Bool? = nil, legend: SemanticTokensLegend, + range: SemanticTokensClientCapabilities.Requests.RangeOption? = nil, + full: SemanticTokensClientCapabilities.Requests.FullOption? = nil + ) { self.workDoneProgress = workDoneProgress self.legend = legend self.range = range @@ -154,14 +171,19 @@ public struct SemanticTokensOptions: Codable, Hashable, Sendable { } public struct SemanticTokensRegistrationOptions: Codable, Hashable, Sendable { - public var documentSelector: DocumentSelector? - public var workDoneProgress: Bool? - public var legend: SemanticTokensLegend - public var range: SemanticTokensClientCapabilities.Requests.RangeOption? - public var full: SemanticTokensClientCapabilities.Requests.FullOption? - public var id: String? - - public init(documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil, legend: SemanticTokensLegend, range: SemanticTokensClientCapabilities.Requests.RangeOption? = nil, full: SemanticTokensClientCapabilities.Requests.FullOption? = nil, id: String? = nil) { + public var documentSelector: DocumentSelector? + public var workDoneProgress: Bool? + public var legend: SemanticTokensLegend + public var range: SemanticTokensClientCapabilities.Requests.RangeOption? + public var full: SemanticTokensClientCapabilities.Requests.FullOption? + public var id: String? + + public init( + documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil, + legend: SemanticTokensLegend, + range: SemanticTokensClientCapabilities.Requests.RangeOption? = nil, + full: SemanticTokensClientCapabilities.Requests.FullOption? = nil, id: String? = nil + ) { self.documentSelector = documentSelector self.workDoneProgress = workDoneProgress self.legend = legend @@ -173,29 +195,32 @@ public struct SemanticTokensRegistrationOptions: Codable, Hashable, Sendable { public typealias MonikerOptions = WorkDoneProgressOptions -public typealias MonikerRegistrationOptions = PartialResultsWorkDoneProgressTextDocumentRegistrationOptions +public typealias MonikerRegistrationOptions = + PartialResultsWorkDoneProgressTextDocumentRegistrationOptions public struct WorkspaceFoldersServerCapabilities: Codable, Hashable, Sendable { - public var supported: Bool? - public var changeNotifications: TwoTypeOption? + public var supported: Bool? + public var changeNotifications: TwoTypeOption? } public struct ServerCapabilities: Codable, Hashable, Sendable { - public struct Workspace: Codable, Hashable, Sendable { - public struct FileOperations: Codable, Hashable, Sendable { - public var didCreate: FileOperationRegistrationOptions? - public var willCreate: FileOperationRegistrationOptions? - public var didRename: FileOperationRegistrationOptions? - public var willRename: FileOperationRegistrationOptions? - public var didDelete: FileOperationRegistrationOptions? - public var willDelete: FileOperationRegistrationOptions? - - public init(didCreate: FileOperationRegistrationOptions? = nil, - willCreate: FileOperationRegistrationOptions? = nil, - didRename: FileOperationRegistrationOptions? = nil, - willRename: FileOperationRegistrationOptions? = nil, - didDelete: FileOperationRegistrationOptions? = nil, - willDelete: FileOperationRegistrationOptions? = nil) { + public struct Workspace: Codable, Hashable, Sendable { + public struct FileOperations: Codable, Hashable, Sendable { + public var didCreate: FileOperationRegistrationOptions? + public var willCreate: FileOperationRegistrationOptions? + public var didRename: FileOperationRegistrationOptions? + public var willRename: FileOperationRegistrationOptions? + public var didDelete: FileOperationRegistrationOptions? + public var willDelete: FileOperationRegistrationOptions? + + public init( + didCreate: FileOperationRegistrationOptions? = nil, + willCreate: FileOperationRegistrationOptions? = nil, + didRename: FileOperationRegistrationOptions? = nil, + willRename: FileOperationRegistrationOptions? = nil, + didDelete: FileOperationRegistrationOptions? = nil, + willDelete: FileOperationRegistrationOptions? = nil + ) { self.didCreate = didCreate self.willCreate = willCreate self.didRename = didRename @@ -203,49 +228,61 @@ public struct ServerCapabilities: Codable, Hashable, Sendable { self.didDelete = didDelete self.willDelete = willDelete } - } + } - public var workspaceFolders: WorkspaceFoldersServerCapabilities? - public var fileOperations: FileOperations? + public var workspaceFolders: WorkspaceFoldersServerCapabilities? + public var fileOperations: FileOperations? - public init(workspaceFolders: WorkspaceFoldersServerCapabilities? = nil, - fileOperations: FileOperations? = nil) { + public init( + workspaceFolders: WorkspaceFoldersServerCapabilities? = nil, + fileOperations: FileOperations? = nil + ) { self.workspaceFolders = workspaceFolders self.fileOperations = fileOperations } - } - - public var textDocumentSync: TwoTypeOption? - public var completionProvider: CompletionOptions? - public var hoverProvider: TwoTypeOption? - public var signatureHelpProvider: SignatureHelpOptions? - public var declarationProvider: ThreeTypeOption? - public var definitionProvider: TwoTypeOption? - public var typeDefinitionProvider: ThreeTypeOption? - public var implementationProvider: ThreeTypeOption? - public var referencesProvider: TwoTypeOption? - public var documentHighlightProvider: TwoTypeOption? - public var documentSymbolProvider: TwoTypeOption? - public var codeActionProvider: TwoTypeOption? - public var codeLensProvider: CodeLensOptions? - public var documentLinkProvider: DocumentLinkOptions? - public var colorProvider: ThreeTypeOption? - public var documentFormattingProvider: TwoTypeOption? - public var documentRangeFormattingProvider: TwoTypeOption? - public var documentOnTypeFormattingProvider: DocumentOnTypeFormattingOptions? - public var renameProvider: TwoTypeOption? - public var foldingRangeProvider: ThreeTypeOption? - public var executeCommandProvider: ExecuteCommandOptions? - public var selectionRangeProvider: ThreeTypeOption? - public var linkedEditingRangeProvider: ThreeTypeOption? - public var callHierarchyProvider: ThreeTypeOption? - public var semanticTokensProvider: TwoTypeOption? - public var monikerProvider: ThreeTypeOption? - public var inlayHintProvider: ThreeTypeOption? + } + + public var textDocumentSync: TwoTypeOption? + public var completionProvider: CompletionOptions? + public var hoverProvider: TwoTypeOption? + public var signatureHelpProvider: SignatureHelpOptions? + public var declarationProvider: + ThreeTypeOption? + public var definitionProvider: TwoTypeOption? + public var typeDefinitionProvider: + ThreeTypeOption? + public var implementationProvider: + ThreeTypeOption? + public var referencesProvider: TwoTypeOption? + public var documentHighlightProvider: TwoTypeOption? + public var documentSymbolProvider: TwoTypeOption? + public var codeActionProvider: TwoTypeOption? + public var codeLensProvider: CodeLensOptions? + public var documentLinkProvider: DocumentLinkOptions? + public var colorProvider: + ThreeTypeOption? + public var documentFormattingProvider: TwoTypeOption? + public var documentRangeFormattingProvider: TwoTypeOption? + public var documentOnTypeFormattingProvider: DocumentOnTypeFormattingOptions? + public var renameProvider: TwoTypeOption? + public var foldingRangeProvider: + ThreeTypeOption? + public var executeCommandProvider: ExecuteCommandOptions? + public var selectionRangeProvider: + ThreeTypeOption? + public var linkedEditingRangeProvider: + ThreeTypeOption? + public var callHierarchyProvider: + ThreeTypeOption? + public var semanticTokensProvider: + TwoTypeOption? + public var monikerProvider: ThreeTypeOption? + public var inlayHintProvider: + ThreeTypeOption? public var diagnosticProvider: TwoTypeOption? - public var workspaceSymbolProvider: TwoTypeOption? - public var workspace: Workspace? - public var experimental: LSPAny? + public var workspaceSymbolProvider: TwoTypeOption? + public var workspace: Workspace? + public var experimental: LSPAny? public init() { } diff --git a/Sources/LanguageServerProtocol/TextSynchronization.swift b/Sources/LanguageServerProtocol/TextSynchronization.swift index 829c0ad..d4100c6 100644 --- a/Sources/LanguageServerProtocol/TextSynchronization.swift +++ b/Sources/LanguageServerProtocol/TextSynchronization.swift @@ -1,162 +1,166 @@ import Foundation public struct DidOpenTextDocumentParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentItem + public let textDocument: TextDocumentItem - public init(textDocument: TextDocumentItem) { - self.textDocument = textDocument - } + public init(textDocument: TextDocumentItem) { + self.textDocument = textDocument + } } public struct TextDocumentContentChangeEvent: Codable, Hashable, Sendable { - public let range: LSPRange? - public let rangeLength: Int? - public let text: String - - public init(range: LSPRange?, rangeLength: Int?, text: String) { - self.range = range - self.rangeLength = rangeLength - self.text = text - } + public let range: LSPRange? + public let rangeLength: Int? + public let text: String + + public init(range: LSPRange?, rangeLength: Int?, text: String) { + self.range = range + self.rangeLength = rangeLength + self.text = text + } } public struct DidChangeTextDocumentParams: Codable, Hashable, Sendable { - public let textDocument: VersionedTextDocumentIdentifier - public let contentChanges: [TextDocumentContentChangeEvent] - - public init(textDocument: VersionedTextDocumentIdentifier, contentChanges: [TextDocumentContentChangeEvent]) { - self.textDocument = textDocument - self.contentChanges = contentChanges - } - - public init(uri: DocumentUri, version: Int, contentChanges: [TextDocumentContentChangeEvent]) { - self.textDocument = VersionedTextDocumentIdentifier(uri: uri, version: version) - self.contentChanges = contentChanges - } - - public init(uri: DocumentUri, version: Int, contentChange: TextDocumentContentChangeEvent) { - self.textDocument = VersionedTextDocumentIdentifier(uri: uri, version: version) - self.contentChanges = [contentChange] - } + public let textDocument: VersionedTextDocumentIdentifier + public let contentChanges: [TextDocumentContentChangeEvent] + + public init( + textDocument: VersionedTextDocumentIdentifier, + contentChanges: [TextDocumentContentChangeEvent] + ) { + self.textDocument = textDocument + self.contentChanges = contentChanges + } + + public init(uri: DocumentUri, version: Int, contentChanges: [TextDocumentContentChangeEvent]) { + self.textDocument = VersionedTextDocumentIdentifier(uri: uri, version: version) + self.contentChanges = contentChanges + } + + public init(uri: DocumentUri, version: Int, contentChange: TextDocumentContentChangeEvent) { + self.textDocument = VersionedTextDocumentIdentifier(uri: uri, version: version) + self.contentChanges = [contentChange] + } } public struct TextDocumentChangeRegistrationOptions: Codable, Hashable, Sendable { - public let documentSelector: DocumentSelector? - public let syncKind: TextDocumentSyncKind + public let documentSelector: DocumentSelector? + public let syncKind: TextDocumentSyncKind } public struct DidSaveTextDocumentParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier - public let text: String? + public let textDocument: TextDocumentIdentifier + public let text: String? - public init(textDocument: TextDocumentIdentifier, text: String? = nil) { - self.textDocument = textDocument - self.text = text - } + public init(textDocument: TextDocumentIdentifier, text: String? = nil) { + self.textDocument = textDocument + self.text = text + } - public init(uri: DocumentUri, text: String? = nil) { - let docId = TextDocumentIdentifier(uri: uri) + public init(uri: DocumentUri, text: String? = nil) { + let docId = TextDocumentIdentifier(uri: uri) - self.textDocument = docId - self.text = text - } + self.textDocument = docId + self.text = text + } } public struct TextDocumentSaveRegistrationOptions: Codable, Hashable, Sendable { - public let documentSelector: DocumentSelector? - public let includeText: Bool? + public let documentSelector: DocumentSelector? + public let includeText: Bool? } public struct DidCloseTextDocumentParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier + public let textDocument: TextDocumentIdentifier - public init(textDocument: TextDocumentIdentifier) { - self.textDocument = textDocument - } + public init(textDocument: TextDocumentIdentifier) { + self.textDocument = textDocument + } - public init(uri: DocumentUri) { - let docId = TextDocumentIdentifier(uri: uri) + public init(uri: DocumentUri) { + let docId = TextDocumentIdentifier(uri: uri) - self.init(textDocument: docId) - } + self.init(textDocument: docId) + } } public enum TextDocumentSaveReason: Int, Codable, Hashable, Sendable { - case manual = 1 - case afterDelay = 2 - case focusOut = 3 + case manual = 1 + case afterDelay = 2 + case focusOut = 3 } public struct WillSaveTextDocumentParams: Codable, Hashable, Sendable { - public let textDocument: TextDocumentIdentifier - public let reason: TextDocumentSaveReason + public let textDocument: TextDocumentIdentifier + public let reason: TextDocumentSaveReason - public init(textDocument: TextDocumentIdentifier, reason: TextDocumentSaveReason) { - self.textDocument = textDocument - self.reason = reason - } + public init(textDocument: TextDocumentIdentifier, reason: TextDocumentSaveReason) { + self.textDocument = textDocument + self.reason = reason + } } public typealias WillSaveWaitUntilResponse = [TextEdit]? public struct TextEdit: Codable, Hashable, Sendable { - public let range: LSPRange - public let newText: String - - public init(range: LSPRange, newText: String) { - self.range = range - self.newText = newText - } - - public var isNoOp: Bool { - return range.isEmpty && newText.isEmpty - } - - public var isInsert: Bool { - return range.isEmpty && (newText.isEmpty == false) - } - - /// Adjusts the input array so that it can be applied, in order - /// to produce the desired final state - /// - /// This function *requires* the input edits to meet the LSP spec. In - /// particular: - /// - overlaps are not allowed - /// - inserts with the same starting location must be applied in the order - /// they appear in the array. - public static func makeApplicable(_ edits: [TextEdit]) -> [TextEdit] { - var finalEdits = [TextEdit]() - - for edit in edits { - if edit.isNoOp { - continue - } - - guard let last = finalEdits.last else { - finalEdits.append(edit) - continue - } - - guard edit.isInsert && last.isInsert && edit.range == last.range else { - finalEdits.append(edit) - continue - } - - let combinedEdit = TextEdit(range: edit.range, - newText: last.newText + edit.newText) - - finalEdits.removeLast() - finalEdits.append(combinedEdit) - } - - return finalEdits.sorted(by: { - return $1.range.start < $0.range.start - }) - } + public let range: LSPRange + public let newText: String + + public init(range: LSPRange, newText: String) { + self.range = range + self.newText = newText + } + + public var isNoOp: Bool { + return range.isEmpty && newText.isEmpty + } + + public var isInsert: Bool { + return range.isEmpty && (newText.isEmpty == false) + } + + /// Adjusts the input array so that it can be applied, in order + /// to produce the desired final state + /// + /// This function *requires* the input edits to meet the LSP spec. In + /// particular: + /// - overlaps are not allowed + /// - inserts with the same starting location must be applied in the order + /// they appear in the array. + public static func makeApplicable(_ edits: [TextEdit]) -> [TextEdit] { + var finalEdits = [TextEdit]() + + for edit in edits { + if edit.isNoOp { + continue + } + + guard let last = finalEdits.last else { + finalEdits.append(edit) + continue + } + + guard edit.isInsert && last.isInsert && edit.range == last.range else { + finalEdits.append(edit) + continue + } + + let combinedEdit = TextEdit( + range: edit.range, + newText: last.newText + edit.newText) + + finalEdits.removeLast() + finalEdits.append(combinedEdit) + } + + return finalEdits.sorted(by: { + return $1.range.start < $0.range.start + }) + } } extension TextEdit: CustomStringConvertible { - public var description: String { - return "\(range): \"\(newText)\"" - } + public var description: String { + return "\(range): \"\(newText)\"" + } } diff --git a/Sources/LanguageServerProtocol/ThreeTypeOption.swift b/Sources/LanguageServerProtocol/ThreeTypeOption.swift index f12ba55..ac4f811 100644 --- a/Sources/LanguageServerProtocol/ThreeTypeOption.swift +++ b/Sources/LanguageServerProtocol/ThreeTypeOption.swift @@ -1,41 +1,41 @@ import Foundation public enum ThreeTypeOption { - case optionA(T) - case optionB(U) - case optionC(V) + case optionA(T) + case optionB(U) + case optionC(V) } extension ThreeTypeOption: Codable where T: Codable, U: Codable, V: Codable { - public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() - do { - let value = try container.decode(T.self) - self = .optionA(value) - } catch is DecodingError { - do { - let value = try container.decode(U.self) - self = .optionB(value) - } catch is DecodingError { - let value = try container.decode(V.self) - self = .optionC(value) - } - } - } + do { + let value = try container.decode(T.self) + self = .optionA(value) + } catch is DecodingError { + do { + let value = try container.decode(U.self) + self = .optionB(value) + } catch is DecodingError { + let value = try container.decode(V.self) + self = .optionC(value) + } + } + } - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() - switch self { - case .optionA(let value): - try container.encode(value) - case .optionB(let value): - try container.encode(value) - case .optionC(let value): - try container.encode(value) - } - } + switch self { + case .optionA(let value): + try container.encode(value) + case .optionB(let value): + try container.encode(value) + case .optionC(let value): + try container.encode(value) + } + } } extension ThreeTypeOption: Equatable where T: Equatable, U: Equatable, V: Equatable {} diff --git a/Sources/LanguageServerProtocol/TwoTypeOption.swift b/Sources/LanguageServerProtocol/TwoTypeOption.swift index aae2a93..1435765 100644 --- a/Sources/LanguageServerProtocol/TwoTypeOption.swift +++ b/Sources/LanguageServerProtocol/TwoTypeOption.swift @@ -1,33 +1,33 @@ import Foundation public enum TwoTypeOption { - case optionA(T) - case optionB(U) + case optionA(T) + case optionB(U) } extension TwoTypeOption: Codable where T: Codable, U: Codable { - public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - - do { - let value = try container.decode(T.self) - self = .optionA(value) - } catch is DecodingError { - let value = try container.decode(U.self) - self = .optionB(value) - } - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - - switch self { - case .optionA(let value): - try container.encode(value) - case .optionB(let value): - try container.encode(value) - } - } + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + + do { + let value = try container.decode(T.self) + self = .optionA(value) + } catch is DecodingError { + let value = try container.decode(U.self) + self = .optionB(value) + } + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + + switch self { + case .optionA(let value): + try container.encode(value) + case .optionB(let value): + try container.encode(value) + } + } } extension TwoTypeOption: Equatable where T: Equatable, U: Equatable { diff --git a/Sources/LanguageServerProtocol/Utility.swift b/Sources/LanguageServerProtocol/Utility.swift index aa0679e..16c974c 100644 --- a/Sources/LanguageServerProtocol/Utility.swift +++ b/Sources/LanguageServerProtocol/Utility.swift @@ -1,9 +1,9 @@ import Foundation public struct GenericDynamicRegistration: Codable, Hashable, Sendable { - public let dynamicRegistration: Bool? + public let dynamicRegistration: Bool? - public init(dynamicRegistration: Bool) { - self.dynamicRegistration = dynamicRegistration - } + public init(dynamicRegistration: Bool) { + self.dynamicRegistration = dynamicRegistration + } } diff --git a/Sources/LanguageServerProtocol/Window.swift b/Sources/LanguageServerProtocol/Window.swift index 8813d90..503d1c0 100644 --- a/Sources/LanguageServerProtocol/Window.swift +++ b/Sources/LanguageServerProtocol/Window.swift @@ -1,30 +1,30 @@ import Foundation public enum MessageType: Int, Codable, Hashable, Sendable { - case error = 1 - case warning = 2 - case info = 3 - case log = 4 + case error = 1 + case warning = 2 + case info = 3 + case log = 4 } extension MessageType: CustomStringConvertible { - public var description: String { - switch self { - case .error: - return "error" - case .warning: - return "warning" - case .info: - return "info" - case .log: - return "log" - } - } + public var description: String { + switch self { + case .error: + return "error" + case .warning: + return "warning" + case .info: + return "info" + case .log: + return "log" + } + } } public struct LogMessageParams: Codable, Hashable, Sendable { - public let type: MessageType - public let message: String + public let type: MessageType + public let message: String public init(type: MessageType, message: String) { self.type = type @@ -33,33 +33,34 @@ public struct LogMessageParams: Codable, Hashable, Sendable { } extension LogMessageParams: CustomStringConvertible { - public var description: String { - return "\(type): \(message)" - } + public var description: String { + return "\(type): \(message)" + } } public typealias ShowMessageParams = LogMessageParams public struct ShowDocumentParams: Hashable, Codable, Sendable { - public var uri: URI - public var external: Bool? - public var takeFocus: Bool? - public var selection: LSPRange? + public var uri: URI + public var external: Bool? + public var takeFocus: Bool? + public var selection: LSPRange? - public init(uri: URI, external: Bool? = nil, takeFocus: Bool? = nil, selection: LSPRange? = nil) { - self.uri = uri - self.external = external - self.takeFocus = takeFocus - self.selection = selection - } + public init(uri: URI, external: Bool? = nil, takeFocus: Bool? = nil, selection: LSPRange? = nil) + { + self.uri = uri + self.external = external + self.takeFocus = takeFocus + self.selection = selection + } } public struct WorkDoneProgressCreateParams: Hashable, Codable, Sendable { - public var token: ProgressToken + public var token: ProgressToken - public init(token: ProgressToken) { - self.token = token - } + public init(token: ProgressToken) { + self.token = token + } } public typealias WorkDoneProgressCancelParams = WorkDoneProgressCreateParams diff --git a/Sources/LanguageServerProtocol/Window/ShowMessageRequest.swift b/Sources/LanguageServerProtocol/Window/ShowMessageRequest.swift index 57a8985..7eacda8 100644 --- a/Sources/LanguageServerProtocol/Window/ShowMessageRequest.swift +++ b/Sources/LanguageServerProtocol/Window/ShowMessageRequest.swift @@ -1,19 +1,19 @@ import Foundation public struct MessageActionItem: Codable, Hashable, Sendable { - public var title: String + public var title: String } public struct ShowMessageRequestParams: Codable, Hashable, Sendable { - public var type: MessageType - public var message: String - public var actions: [MessageActionItem]? + public var type: MessageType + public var message: String + public var actions: [MessageActionItem]? } extension ShowMessageRequestParams: CustomStringConvertible { - public var description: String { - return "\(type): \(message)" - } + public var description: String { + return "\(type): \(message)" + } } public typealias ShowMessageRequestResponse = MessageActionItem? diff --git a/Sources/LanguageServerProtocol/Workspace.swift b/Sources/LanguageServerProtocol/Workspace.swift index a5e794a..0a05592 100644 --- a/Sources/LanguageServerProtocol/Workspace.swift +++ b/Sources/LanguageServerProtocol/Workspace.swift @@ -1,106 +1,109 @@ import Foundation public struct WatchKind: OptionSet, Codable, Hashable, Sendable { - public let rawValue: Int + public let rawValue: Int - public init(rawValue: Int) { - self.rawValue = rawValue - } + public init(rawValue: Int) { + self.rawValue = rawValue + } - public static let create = WatchKind(rawValue: 1) - public static let change = WatchKind(rawValue: 2) - public static let delete = WatchKind(rawValue: 4) + public static let create = WatchKind(rawValue: 1) + public static let change = WatchKind(rawValue: 2) + public static let delete = WatchKind(rawValue: 4) - public static let all: WatchKind = [.create, .change, .delete] + public static let all: WatchKind = [.create, .change, .delete] } public struct FileSystemWatcher: Codable, Hashable, Sendable { - public var globPattern: String - public var kind: WatchKind? + public var globPattern: String + public var kind: WatchKind? - public init(globPattern: String, kind: WatchKind? = nil) { - self.globPattern = globPattern - self.kind = kind - } + public init(globPattern: String, kind: WatchKind? = nil) { + self.globPattern = globPattern + self.kind = kind + } } public struct DidChangeWatchedFilesRegistrationOptions: Codable, Hashable, Sendable { - public var watchers: [FileSystemWatcher] + public var watchers: [FileSystemWatcher] } public enum FileChangeType: Int, Codable, Hashable, Sendable { - case created = 1 - case changed = 2 - case deleted = 3 + case created = 1 + case changed = 2 + case deleted = 3 } public struct FileEvent: Codable, Hashable, Sendable { - public var uri: DocumentUri - public var type: FileChangeType + public var uri: DocumentUri + public var type: FileChangeType - public init(uri: DocumentUri, type: FileChangeType) { - self.uri = uri - self.type = type - } + public init(uri: DocumentUri, type: FileChangeType) { + self.uri = uri + self.type = type + } } public struct DidChangeWatchedFilesParams: Codable, Hashable, Sendable { - public var changes: [FileEvent] + public var changes: [FileEvent] - public init(changes: [FileEvent]) { - self.changes = changes - } + public init(changes: [FileEvent]) { + self.changes = changes + } } public struct WorkspaceFolder: Codable, Hashable, Sendable { - public let uri: String - public let name: String + public let uri: String + public let name: String - public init(uri: String, name: String) { - self.uri = uri - self.name = name - } + public init(uri: String, name: String) { + self.uri = uri + self.name = name + } } public struct WorkspaceFoldersChangeEvent: Codable, Hashable, Sendable { - public var added: [WorkspaceFolder] - public var removed: [WorkspaceFolder] + public var added: [WorkspaceFolder] + public var removed: [WorkspaceFolder] - public init(added: [WorkspaceFolder], removed: [WorkspaceFolder]) { - self.added = added - self.removed = removed - } + public init(added: [WorkspaceFolder], removed: [WorkspaceFolder]) { + self.added = added + self.removed = removed + } } public struct DidChangeWorkspaceFoldersParams: Codable, Hashable, Sendable { - public var event: WorkspaceFoldersChangeEvent + public var event: WorkspaceFoldersChangeEvent - public init(event: WorkspaceFoldersChangeEvent) { - self.event = event - } + public init(event: WorkspaceFoldersChangeEvent) { + self.event = event + } } public struct DidChangeConfigurationParams: Codable, Hashable, Sendable { - public var settings: LSPAny? + public var settings: LSPAny? - public init(settings: LSPAny) { - self.settings = settings - } + public init(settings: LSPAny) { + self.settings = settings + } } public enum SymbolTag: Int, Codable, Hashable, CaseIterable, Sendable { - case Deprecated = 1 + case Deprecated = 1 } public struct SymbolInformation: Codable, Hashable, Sendable { - public let name: String - public let kind: SymbolKind - public let tags: [SymbolTag]? - public let deprecated: Bool? - public let location: Location - public let containerName: String? - - public init(name: String, kind: SymbolKind, tags: [SymbolTag]? = nil, deprecated: Bool? = nil, location: Location, containerName: String? = nil) { + public let name: String + public let kind: SymbolKind + public let tags: [SymbolTag]? + public let deprecated: Bool? + public let location: Location + public let containerName: String? + + public init( + name: String, kind: SymbolKind, tags: [SymbolTag]? = nil, deprecated: Bool? = nil, + location: Location, containerName: String? = nil + ) { self.name = name self.kind = kind self.tags = tags @@ -111,79 +114,79 @@ public struct SymbolInformation: Codable, Hashable, Sendable { } public struct CreateFileOptions: Codable, Hashable, Sendable { - public let overwrite: Bool? - public let ignoreIfExists: Bool? + public let overwrite: Bool? + public let ignoreIfExists: Bool? } public struct CreateFile: Codable, Hashable, Sendable { - public let kind: String - public let uri: DocumentUri - public let options: CreateFileOptions? + public let kind: String + public let uri: DocumentUri + public let options: CreateFileOptions? } public typealias RenameFileOptions = CreateFileOptions public struct RenameFile: Codable, Hashable, Sendable { - public let kind: String - public let oldUri: DocumentUri - public let newUri: DocumentUri - public let options: RenameFileOptions + public let kind: String + public let oldUri: DocumentUri + public let newUri: DocumentUri + public let options: RenameFileOptions } public struct DeleteFileOptions: Codable, Hashable, Sendable { - public let recursive: Bool? - public let ignoreIfNotExists: Bool? + public let recursive: Bool? + public let ignoreIfNotExists: Bool? } public struct DeleteFile: Codable, Hashable, Sendable { - public let kind: String - public let uri: DocumentUri - public let options: DeleteFileOptions + public let kind: String + public let uri: DocumentUri + public let options: DeleteFileOptions } public struct TextDocumentEdit: Codable, Hashable, Sendable { - public let textDocument: VersionedTextDocumentIdentifier - public let edits: [TextEdit] + public let textDocument: VersionedTextDocumentIdentifier + public let edits: [TextEdit] } public enum WorkspaceEditDocumentChange: Codable, Hashable, Sendable { - case textDocumentEdit(TextDocumentEdit) - case createFile(CreateFile) - case renameFile(RenameFile) - case deleteFile(DeleteFile) - - public init(from decoder: Decoder) throws { - let container = try decoder.singleValueContainer() - - if let value = try? container.decode(TextDocumentEdit.self) { - self = .textDocumentEdit(value) - } else if let value = try? container.decode(CreateFile.self) { - self = .createFile(value) - } else if let value = try? container.decode(RenameFile.self) { - self = .renameFile(value) - } else { - let value = try container.decode(DeleteFile.self) - self = .deleteFile(value) - } - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - - switch self { - case .textDocumentEdit(let value): - try container.encode(value) - case .createFile(let value): - try container.encode(value) - case .renameFile(let value): - try container.encode(value) - case .deleteFile(let value): - try container.encode(value) - } - } + case textDocumentEdit(TextDocumentEdit) + case createFile(CreateFile) + case renameFile(RenameFile) + case deleteFile(DeleteFile) + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + + if let value = try? container.decode(TextDocumentEdit.self) { + self = .textDocumentEdit(value) + } else if let value = try? container.decode(CreateFile.self) { + self = .createFile(value) + } else if let value = try? container.decode(RenameFile.self) { + self = .renameFile(value) + } else { + let value = try container.decode(DeleteFile.self) + self = .deleteFile(value) + } + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + + switch self { + case .textDocumentEdit(let value): + try container.encode(value) + case .createFile(let value): + try container.encode(value) + case .renameFile(let value): + try container.encode(value) + case .deleteFile(let value): + try container.encode(value) + } + } } public struct WorkspaceEdit: Codable, Hashable, Sendable { - public let changes: [DocumentUri : [TextEdit]]? - public let documentChanges: [WorkspaceEditDocumentChange]? + public let changes: [DocumentUri: [TextEdit]]? + public let documentChanges: [WorkspaceEditDocumentChange]? } diff --git a/Sources/LanguageServerProtocol/Workspace/ApplyEdit.swift b/Sources/LanguageServerProtocol/Workspace/ApplyEdit.swift index 194ef9b..0d740e4 100644 --- a/Sources/LanguageServerProtocol/Workspace/ApplyEdit.swift +++ b/Sources/LanguageServerProtocol/Workspace/ApplyEdit.swift @@ -1,23 +1,23 @@ import Foundation public struct ApplyWorkspaceEditParams: Codable, Hashable, Sendable { - public var label: String? - public var edit: WorkspaceEdit + public var label: String? + public var edit: WorkspaceEdit - public init(label: String? = nil, edit: WorkspaceEdit) { - self.label = label - self.edit = edit - } + public init(label: String? = nil, edit: WorkspaceEdit) { + self.label = label + self.edit = edit + } } public struct ApplyWorkspaceEditResult: Codable, Hashable, Sendable { - public var applied: Bool - public var failureReason: String? - public var failedChange: UInt? + public var applied: Bool + public var failureReason: String? + public var failedChange: UInt? - public init(applied: Bool, failureReason: String? = nil, failedChange: UInt? = nil) { - self.applied = applied - self.failureReason = failureReason - self.failedChange = failedChange - } + public init(applied: Bool, failureReason: String? = nil, failedChange: UInt? = nil) { + self.applied = applied + self.failureReason = failureReason + self.failedChange = failedChange + } } diff --git a/Sources/LanguageServerProtocol/Workspace/Configuration.swift b/Sources/LanguageServerProtocol/Workspace/Configuration.swift index d2c91b3..4e1f9e7 100644 --- a/Sources/LanguageServerProtocol/Workspace/Configuration.swift +++ b/Sources/LanguageServerProtocol/Workspace/Configuration.swift @@ -1,19 +1,19 @@ import Foundation public struct ConfigurationItem: Codable, Hashable, Sendable { - public var scopeUri: DocumentUri? - public var section: String? + public var scopeUri: DocumentUri? + public var section: String? - public init(scopeUri: DocumentUri?, section: String?) { - self.scopeUri = scopeUri - self.section = section - } + public init(scopeUri: DocumentUri?, section: String?) { + self.scopeUri = scopeUri + self.section = section + } } public struct ConfigurationParams: Codable, Hashable, Sendable { - public var items: [ConfigurationItem] + public var items: [ConfigurationItem] - public init(items: [ConfigurationItem]) { - self.items = items - } + public init(items: [ConfigurationItem]) { + self.items = items + } } diff --git a/Sources/LanguageServerProtocol/Workspace/ExecuteCommand.swift b/Sources/LanguageServerProtocol/Workspace/ExecuteCommand.swift index fded77b..b1c80f5 100644 --- a/Sources/LanguageServerProtocol/Workspace/ExecuteCommand.swift +++ b/Sources/LanguageServerProtocol/Workspace/ExecuteCommand.swift @@ -3,27 +3,27 @@ import Foundation public typealias ExecuteCommandClientCapabilities = DynamicRegistrationClientCapabilities public struct ExecuteCommandOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var commands: [String] + public var workDoneProgress: Bool? + public var commands: [String] - public init(workDoneProgress: Bool? = nil, commands: [String]) { - self.workDoneProgress = workDoneProgress - self.commands = commands - } + public init(workDoneProgress: Bool? = nil, commands: [String]) { + self.workDoneProgress = workDoneProgress + self.commands = commands + } } public typealias ExecuteCommandRegistrationOptions = ExecuteCommandOptions public struct ExecuteCommandParams: Codable, Hashable, Sendable { - public var workDoneToken: ProgressToken? - public var command: String - public var arguments: [LSPAny]? + public var workDoneToken: ProgressToken? + public var command: String + public var arguments: [LSPAny]? - public init(workDoneToken: ProgressToken? = nil, command: String, arguments: [LSPAny]? = nil) { - self.workDoneToken = workDoneToken - self.command = command - self.arguments = arguments - } + public init(workDoneToken: ProgressToken? = nil, command: String, arguments: [LSPAny]? = nil) { + self.workDoneToken = workDoneToken + self.command = command + self.arguments = arguments + } } public typealias ExecuteCommandResponse = LSPAny diff --git a/Sources/LanguageServerProtocol/Workspace/Symbol.swift b/Sources/LanguageServerProtocol/Workspace/Symbol.swift index 36087d1..06bd9b6 100644 --- a/Sources/LanguageServerProtocol/Workspace/Symbol.swift +++ b/Sources/LanguageServerProtocol/Workspace/Symbol.swift @@ -1,55 +1,64 @@ import Foundation public struct WorkspaceSymbolClientCapabilities: Codable, Hashable, Sendable { - public struct Properties: Codable, Hashable, Sendable { - public var properties: [String] - } - - public var dynamicRegistration: Bool? - public var symbolKind: ValueSet? - public var tagSupport: ValueSet? - public var resolveSupport: Properties? - - public init(dynamicRegistration: Bool?, symbolKind: [SymbolKind]?, tagSupport: [SymbolTag]?, resolveSupport: Properties?) { - self.dynamicRegistration = dynamicRegistration - self.symbolKind = symbolKind.map { ValueSet(valueSet: $0) } - self.tagSupport = tagSupport.map { ValueSet(valueSet: $0) } - self.resolveSupport = resolveSupport - } - - public init(dynamicRegistration: Bool?, symbolKind: [SymbolKind]?, tagSupport: [SymbolTag]?, resolveSupport: [String]?) { - self.init(dynamicRegistration: dynamicRegistration, - symbolKind: symbolKind, - tagSupport: tagSupport, - resolveSupport: resolveSupport.map { Properties(properties: $0) }) - } + public struct Properties: Codable, Hashable, Sendable { + public var properties: [String] + } + + public var dynamicRegistration: Bool? + public var symbolKind: ValueSet? + public var tagSupport: ValueSet? + public var resolveSupport: Properties? + + public init( + dynamicRegistration: Bool?, symbolKind: [SymbolKind]?, tagSupport: [SymbolTag]?, + resolveSupport: Properties? + ) { + self.dynamicRegistration = dynamicRegistration + self.symbolKind = symbolKind.map { ValueSet(valueSet: $0) } + self.tagSupport = tagSupport.map { ValueSet(valueSet: $0) } + self.resolveSupport = resolveSupport + } + + public init( + dynamicRegistration: Bool?, symbolKind: [SymbolKind]?, tagSupport: [SymbolTag]?, + resolveSupport: [String]? + ) { + self.init( + dynamicRegistration: dynamicRegistration, + symbolKind: symbolKind, + tagSupport: tagSupport, + resolveSupport: resolveSupport.map { Properties(properties: $0) }) + } } public struct WorkspaceSymbolOptions: Codable, Hashable, Sendable { - public var workDoneProgress: Bool? - public var resolveProvider: Bool? + public var workDoneProgress: Bool? + public var resolveProvider: Bool? } public typealias WorkspaceSymbolRegistrationOptions = WorkspaceSymbolOptions public struct WorkspaceSymbolParams: Codable, Hashable, Sendable { - public var workDoneToken: ProgressToken? - public var partialResultToken: ProgressToken? - public var query: String - - public init(query: String, workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil) { - self.workDoneToken = workDoneToken - self.partialResultToken = partialResultToken - self.query = query - } + public var workDoneToken: ProgressToken? + public var partialResultToken: ProgressToken? + public var query: String + + public init( + query: String, workDoneToken: ProgressToken? = nil, partialResultToken: ProgressToken? = nil + ) { + self.workDoneToken = workDoneToken + self.partialResultToken = partialResultToken + self.query = query + } } public struct WorkspaceSymbol: Codable, Hashable, Sendable { - public var name: String - public var kind: SymbolKind - public var tags: [SymbolTag]? - public var location: TwoTypeOption? - public var containerName: String? + public var name: String + public var kind: SymbolKind + public var tags: [SymbolTag]? + public var location: TwoTypeOption? + public var containerName: String? } -public typealias WorkspaceSymbolResponse = TwoTypeOption<[SymbolInformation],[WorkspaceSymbol]>? +public typealias WorkspaceSymbolResponse = TwoTypeOption<[SymbolInformation], [WorkspaceSymbol]>? diff --git a/Sources/LanguageServerProtocol/Workspace/WillCreateFiles.swift b/Sources/LanguageServerProtocol/Workspace/WillCreateFiles.swift index 27c437c..b7c8264 100644 --- a/Sources/LanguageServerProtocol/Workspace/WillCreateFiles.swift +++ b/Sources/LanguageServerProtocol/Workspace/WillCreateFiles.swift @@ -1,62 +1,64 @@ import Foundation public enum FileOperationPatternKind: String, Codable, Hashable, Sendable { - case file = "file" - case folder = "folder" + case file = "file" + case folder = "folder" } public struct FileOperationPatternOptions: Codable, Hashable, Sendable { - public var ignoreCase: Bool? + public var ignoreCase: Bool? - public init(ignoreCase: Bool? = nil) { - self.ignoreCase = ignoreCase - } + public init(ignoreCase: Bool? = nil) { + self.ignoreCase = ignoreCase + } } public struct FileOperationPattern: Codable, Hashable, Sendable { - public let glob: String - public let matches: FileOperationPatternKind? - public let options: FileOperationPatternOptions? - - public init(glob: String, matches: FileOperationPatternKind?, options: FileOperationPatternOptions?) { - self.glob = glob - self.matches = matches - self.options = options - } + public let glob: String + public let matches: FileOperationPatternKind? + public let options: FileOperationPatternOptions? + + public init( + glob: String, matches: FileOperationPatternKind?, options: FileOperationPatternOptions? + ) { + self.glob = glob + self.matches = matches + self.options = options + } } public struct FileOperationFilter: Codable, Hashable, Sendable { - public var scheme: String? - public var pattern: FileOperationPattern + public var scheme: String? + public var pattern: FileOperationPattern - public init(scheme: String? = nil, pattern: FileOperationPattern) { - self.scheme = scheme - self.pattern = pattern - } + public init(scheme: String? = nil, pattern: FileOperationPattern) { + self.scheme = scheme + self.pattern = pattern + } } public struct FileOperationRegistrationOptions: Codable, Hashable, Sendable { - public var filters: [FileOperationFilter] + public var filters: [FileOperationFilter] - public init(filters: [FileOperationFilter]) { - self.filters = filters - } + public init(filters: [FileOperationFilter]) { + self.filters = filters + } } public struct CreateFilesParams: Codable, Hashable, Sendable { - public var files: [FileCreate] + public var files: [FileCreate] - public init(files: [FileCreate]) { - self.files = files - } + public init(files: [FileCreate]) { + self.files = files + } } public struct FileCreate: Codable, Hashable, Sendable { - public var uri: String + public var uri: String - public init(uri: String) { - self.uri = uri - } + public init(uri: String) { + self.uri = uri + } } public typealias WorkspaceWillCreateFilesResponse = WorkspaceEdit? diff --git a/Sources/LanguageServerProtocol/Workspace/WillDeleteFiles.swift b/Sources/LanguageServerProtocol/Workspace/WillDeleteFiles.swift index 8400a7a..23ff996 100644 --- a/Sources/LanguageServerProtocol/Workspace/WillDeleteFiles.swift +++ b/Sources/LanguageServerProtocol/Workspace/WillDeleteFiles.swift @@ -1,15 +1,15 @@ import Foundation public struct DeleteFilesParams: Codable, Hashable, Sendable { - public var files: [FileDelete] + public var files: [FileDelete] } public struct FileDelete: Codable, Hashable, Sendable { - public var uri: String + public var uri: String - public init(uri: String) { - self.uri = uri - } + public init(uri: String) { + self.uri = uri + } } public typealias WorkspaceWillDeleteFilesResponse = WorkspaceEdit? diff --git a/Sources/LanguageServerProtocol/Workspace/WillRenameFiles.swift b/Sources/LanguageServerProtocol/Workspace/WillRenameFiles.swift index 9c08da3..f90ab8e 100644 --- a/Sources/LanguageServerProtocol/Workspace/WillRenameFiles.swift +++ b/Sources/LanguageServerProtocol/Workspace/WillRenameFiles.swift @@ -1,21 +1,21 @@ import Foundation public struct RenameFilesParams: Codable, Hashable, Sendable { - public var files: [FileRename] + public var files: [FileRename] - public init(files: [FileRename]) { - self.files = files - } + public init(files: [FileRename]) { + self.files = files + } } public struct FileRename: Codable, Hashable, Sendable { - public var oldUri: String - public var newUri: String + public var oldUri: String + public var newUri: String - public init(oldUri: String, newUri: String) { - self.oldUri = oldUri - self.newUri = newUri - } + public init(oldUri: String, newUri: String) { + self.oldUri = oldUri + self.newUri = newUri + } } public typealias WorkspaceWillRenameFilesResponse = WorkspaceEdit? diff --git a/run-swift-format.sh b/run-swift-format.sh new file mode 100755 index 0000000..e3ba076 --- /dev/null +++ b/run-swift-format.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +swift-format --configuration .swift-format.json -r Sources -i