Skip to content

Commit

Permalink
APIs to get server capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Nov 2, 2022
1 parent 6de93e9 commit 289a24f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Sources/LanguageClient/InitializingServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import os.log

public enum InitializingServerError: Error {
case noStateProvider
case capabilitiesUnavailable
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
Expand Down Expand Up @@ -59,6 +60,26 @@ public class InitializingServer {
block(caps)
}
}

/// Return the capabilities of the server.
///
/// This will not start the server, and will throw if it is not running.
public var capabilities: ServerCapabilities {
get async throws {
return try await withCheckedThrowingContinuation { continuation in
let op = BlockOperation {
guard let caps = self.state.capabilities else {
continuation.resume(throwing: InitializingServerError.capabilitiesUnavailable)
return
}

continuation.resume(returning: caps)
}

self.enqueueInitDependantOperation(op)
}
}
}
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
Expand Down
22 changes: 22 additions & 0 deletions Sources/LanguageClient/RestartingServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ public class RestartingServer {
}
}

/// Return the capabilities of the server.
///
/// This will start the server if it is not running.
public var capabilities: LanguageServerProtocol.ServerCapabilities {
get async throws {
return try await withCheckedThrowingContinuation { continuation in
startServerIfNeeded { result in
switch result {
case .failure(let error):
continuation.resume(throwing: error)
case .success(let server):
Task {
let caps = try await server.capabilities

continuation.resume(returning: caps)
}
}
}
}
}
}

public func shutdownAndExit(block: @escaping (ServerError?) -> Void) {
queue.addOperation {
guard case .running(let server) = self.state else {
Expand Down

0 comments on commit 289a24f

Please sign in to comment.