From e8ba8478904c479214f2aaf3ed7ed0843f0eaba1 Mon Sep 17 00:00:00 2001 From: Abe M Date: Sat, 27 Jan 2024 04:01:52 -0800 Subject: [PATCH] Temporarily remove LanguageClient dependency --- Package.resolved | 53 +--- Package.swift | 3 +- .../LSP/LanguageExtension.swift | 286 +++++++++--------- 3 files changed, 148 insertions(+), 194 deletions(-) diff --git a/Package.resolved b/Package.resolved index 28adb57..fa1972b 100644 --- a/Package.resolved +++ b/Package.resolved @@ -14,53 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/ChimeHQ/ConcurrencyPlus", "state" : { - "revision" : "b5ba8d5ea6bfe9e43ccc44aa63f9b458057fa0f4", - "version" : "0.4.1" - } - }, - { - "identity" : "fseventswrapper", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Frizlab/FSEventsWrapper", - "state" : { - "revision" : "e0c59a2ce2775e5f6642da6d19207445f10112d0", - "version" : "1.0.2" - } - }, - { - "identity" : "glob", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Bouke/Glob", - "state" : { - "revision" : "deda6e163d2ff2a8d7e138e2c3326dbd71157faf", - "version" : "1.0.5" - } - }, - { - "identity" : "jsonrpc", - "kind" : "remoteSourceControl", - "location" : "https://github.com/ChimeHQ/JSONRPC", - "state" : { - "revision" : "afc20d00e38674774f84edc325424a32ae3b9e01", - "version" : "0.7.0" - } - }, - { - "identity" : "languageclient", - "kind" : "remoteSourceControl", - "location" : "https://github.com/ChimeHQ/LanguageClient", - "state" : { - "revision" : "92beeecd0bb783da52227839ba6c55e43fc866ec", - "version" : "0.5.1" - } - }, - { - "identity" : "languageserverprotocol", - "kind" : "remoteSourceControl", - "location" : "https://github.com/ChimeHQ/LanguageServerProtocol", - "state" : { - "revision" : "192bcfdcf7a013da49c6fa1b95de66254ce7c614", - "version" : "0.9.1" + "revision" : "8dc56499412a373d617d50d059116bccf44b9874", + "version" : "0.4.2" } }, { @@ -86,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/lukepistrol/SwiftLintPlugin", "state" : { - "revision" : "d3ec7fb242ebe1d8e23bf17e58a1e27d43125994", - "version" : "0.2.6" + "revision" : "ea6d3ca895b49910f790e98e4b4ca658e0fe490e", + "version" : "0.54.0" } } ], diff --git a/Package.swift b/Package.swift index 6b76ce1..471c635 100644 --- a/Package.swift +++ b/Package.swift @@ -15,7 +15,6 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/ChimeHQ/ConcurrencyPlus", from: "0.4.1"), - .package(url: "https://github.com/ChimeHQ/LanguageClient", from: "0.5.0"), .package(url: "https://github.com/ChimeHQ/ProcessService", from: "0.2.6"), .package( url: "https://github.com/lukepistrol/SwiftLintPlugin", @@ -29,7 +28,7 @@ let package = Package( targets: [ .target( name: "CodeEditKit", - dependencies: ["AnyCodable", "ConcurrencyPlus", "LanguageClient", .product(name: "ProcessServiceClient", package: "ProcessService")], + dependencies: ["AnyCodable", "ConcurrencyPlus", .product(name: "ProcessServiceClient", package: "ProcessService")], plugins: [.plugin(name: "SwiftLint", package: "SwiftLintPlugin")] ), .testTarget( diff --git a/Sources/CodeEditKit/NonUIExtensions/LSP/LanguageExtension.swift b/Sources/CodeEditKit/NonUIExtensions/LSP/LanguageExtension.swift index cc93c22..ee866c2 100644 --- a/Sources/CodeEditKit/NonUIExtensions/LSP/LanguageExtension.swift +++ b/Sources/CodeEditKit/NonUIExtensions/LSP/LanguageExtension.swift @@ -5,146 +5,146 @@ // Created by Wouter Hennen on 27/03/2023. // -import Foundation -import LanguageClient -import Combine -import OSLog -import ProcessServiceClient -import ConcurrencyPlus -import LanguageServerProtocol -import ProcessEnv -import JSONRPC - -protocol LanguageExtension { - var client: RemoteLanguageServer { get } - -} - -final class UnrestrictedProcessTransport { - private var readHandler: ReadHandler = { _ in } - private let process: HostedProcess - private let taskQueue = TaskQueue() - private var subscription: AnyCancellable? - private let logger = Logger(subsystem: "com.chimehq.ChimeKit", category: "UnrestrictedProcessTransport") - - init(process: HostedProcess) { - self.process = process - } - - func beginMonitoringProcess() async throws { - let task = taskQueue.addOperation { - self.subscription = try await self.process.processEventPublisher - .sink(receiveCompletion: { _ in - }, receiveValue: { [weak self] event in - switch event { - case .stdout(let data): - self?.readHandler(data) - case .stderr(let data): - let output = String(data: data, encoding: .utf8) ?? "" - - self?.logger.info("stderr: \(output, privacy: .public)") - default: - break - } - }) - } - - try await task.value - } -} - -extension UnrestrictedProcessTransport: DataTransport { - func write(_ data: Data) { - taskQueue.addOperation { - try await self.process.write(data) - } - } - - func setReaderHandler(_ handler: @escaping ReadHandler) { - self.readHandler = handler - } - - func close() { - subscription?.cancel() - } -} - -/// Provides an interface to a LSP language server hosted by an intermediary process. -public class RemoteLanguageServer { - private let wrappedServer: JSONRPCLanguageServer - private var subscription: AnyCancellable? - private let logger = Logger(subsystem: "com.chimehq.ChimeKit", category: "RemoteLanguageServer") - - private let process: HostedProcess - private let taskQueue = TaskQueue() - public var terminationHandler: (() -> Void)? - - init(named serviceName: String, parameters: Process.ExecutionParameters) throws { - self.process = HostedProcess(named: serviceName, parameters: parameters) - let transport = UnrestrictedProcessTransport(process: process) - self.wrappedServer = JSONRPCLanguageServer(dataTransport: transport) - - taskQueue.addOperation { - self.logger.debug("launching remote server") - - do { - try await self.process.launch() - - self.subscription = try await self.process.processEventPublisher - .sink(receiveCompletion: { _ in - - }, receiveValue: { event in - switch event { - case .terminated: - self.terminationHandler?() - default: - break - } - }) - - try await transport.beginMonitoringProcess() - } catch { - self.logger.error("failed to launch: \(String(describing: error), privacy: .public)") - } - } - } - - private func stopProcess() { - self.taskQueue.addOperation { - do { - try await self.process.terminate() - } catch { - self.logger.error("failed to terminate: \(String(describing: error), privacy: .public)") - } - } - } - - public var logMessages: Bool { - get { return wrappedServer.logMessages } - set { wrappedServer.logMessages = newValue } - } -} - -extension RemoteLanguageServer: LanguageServerProtocol.Server { - public func setHandlers(_ handlers: ServerHandlers, completionHandler: @escaping (ServerError?) -> Void) { - wrappedServer.setHandlers(handlers, completionHandler: completionHandler) - } - - public func sendNotification(_ notif: ClientNotification, completionHandler: @escaping (ServerError?) -> Void) { - taskQueue.addOperation { - self.wrappedServer.sendNotification(notif, completionHandler: completionHandler) - } - } - - public func sendRequest(_ request: ClientRequest, completionHandler: @escaping (ServerResult) -> Void) { - taskQueue.addOperation { - self.wrappedServer.sendRequest(request, completionHandler: { (result: ServerResult) in - if case .success = result, case .shutdown = request { - self.stopProcess() - } - - completionHandler(result) - }) - } - } -} +//import Foundation +//import LanguageClient +//import Combine +//import OSLog +//import ProcessServiceClient +//import ConcurrencyPlus +//import LanguageServerProtocol +//import ProcessEnv +//import JSONRPC +// +//protocol LanguageExtension { +// var client: RemoteLanguageServer { get } +// +//} +// +//final class UnrestrictedProcessTransport { +// private var readHandler: ReadHandler = { _ in } +// private let process: HostedProcess +// private let taskQueue = TaskQueue() +// private var subscription: AnyCancellable? +// private let logger = Logger(subsystem: "com.chimehq.ChimeKit", category: "UnrestrictedProcessTransport") +// +// init(process: HostedProcess) { +// self.process = process +// } +// +// func beginMonitoringProcess() async throws { +// let task = taskQueue.addOperation { +// self.subscription = try await self.process.processEventPublisher +// .sink(receiveCompletion: { _ in +// }, receiveValue: { [weak self] event in +// switch event { +// case .stdout(let data): +// self?.readHandler(data) +// case .stderr(let data): +// let output = String(data: data, encoding: .utf8) ?? "" +// +// self?.logger.info("stderr: \(output, privacy: .public)") +// default: +// break +// } +// }) +// } +// +// try await task.value +// } +//} +// +//extension UnrestrictedProcessTransport: DataTransport { +// func write(_ data: Data) { +// taskQueue.addOperation { +// try await self.process.write(data) +// } +// } +// +// func setReaderHandler(_ handler: @escaping ReadHandler) { +// self.readHandler = handler +// } +// +// func close() { +// subscription?.cancel() +// } +//} +// +///// Provides an interface to a LSP language server hosted by an intermediary process. +//public class RemoteLanguageServer { +// private let wrappedServer: JSONRPCLanguageServer +// private var subscription: AnyCancellable? +// private let logger = Logger(subsystem: "com.chimehq.ChimeKit", category: "RemoteLanguageServer") +// +// private let process: HostedProcess +// private let taskQueue = TaskQueue() +// public var terminationHandler: (() -> Void)? +// +// init(named serviceName: String, parameters: Process.ExecutionParameters) throws { +// self.process = HostedProcess(named: serviceName, parameters: parameters) +// let transport = UnrestrictedProcessTransport(process: process) +// self.wrappedServer = JSONRPCLanguageServer(dataTransport: transport) +// +// taskQueue.addOperation { +// self.logger.debug("launching remote server") +// +// do { +// try await self.process.launch() +// +// self.subscription = try await self.process.processEventPublisher +// .sink(receiveCompletion: { _ in +// +// }, receiveValue: { event in +// switch event { +// case .terminated: +// self.terminationHandler?() +// default: +// break +// } +// }) +// +// try await transport.beginMonitoringProcess() +// } catch { +// self.logger.error("failed to launch: \(String(describing: error), privacy: .public)") +// } +// } +// } +// +// private func stopProcess() { +// self.taskQueue.addOperation { +// do { +// try await self.process.terminate() +// } catch { +// self.logger.error("failed to terminate: \(String(describing: error), privacy: .public)") +// } +// } +// } +// +// public var logMessages: Bool { +// get { return wrappedServer.logMessages } +// set { wrappedServer.logMessages = newValue } +// } +//} +// +//extension RemoteLanguageServer: LanguageServerProtocol.Server { +// public func setHandlers(_ handlers: ServerHandlers, completionHandler: @escaping (ServerError?) -> Void) { +// wrappedServer.setHandlers(handlers, completionHandler: completionHandler) +// } +// +// public func sendNotification(_ notif: ClientNotification, completionHandler: @escaping (ServerError?) -> Void) { +// taskQueue.addOperation { +// self.wrappedServer.sendNotification(notif, completionHandler: completionHandler) +// } +// } +// +// public func sendRequest(_ request: ClientRequest, completionHandler: @escaping (ServerResult) -> Void) { +// taskQueue.addOperation { +// self.wrappedServer.sendRequest(request, completionHandler: { (result: ServerResult) in +// if case .success = result, case .shutdown = request { +// self.stopProcess() +// } +// +// completionHandler(result) +// }) +// } +// } +//}