Skip to content

Commit 27a1c3a

Browse files
Update to latest Extendable, LanguageClient; concurrency warnings
1 parent cef43ff commit 27a1c3a

File tree

6 files changed

+64
-33
lines changed

6 files changed

+64
-33
lines changed

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ let package = Package(
1212
],
1313
dependencies: [
1414
.package(url: "https://github.com/ChimeHQ/AsyncXPCConnection", from: "1.0.0"),
15-
.package(url: "https://github.com/ChimeHQ/Extendable", from: "0.1.1"),
15+
.package(url: "https://github.com/ChimeHQ/Extendable", from: "0.3.0"),
1616
.package(url: "https://github.com/ChimeHQ/ProcessEnv", from: "1.0.0"),
17-
.package(url: "https://github.com/ChimeHQ/LanguageClient", from: "0.7.1"),
18-
.package(url: "https://github.com/ChimeHQ/LanguageServerProtocol", from: "0.12.0"),
17+
.package(url: "https://github.com/ChimeHQ/LanguageClient", from: "0.8.0"),
18+
.package(url: "https://github.com/ChimeHQ/LanguageServerProtocol", from: "0.13.0"),
1919
.package(url: "https://github.com/mattmassicotte/Queue", from: "0.1.4"),
2020
.package(url: "https://github.com/ChimeHQ/JSONRPC", from: "0.9.0"),
2121
],

Sources/ChimeExtensionInterface/ChimeExtension.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ extension ChimeExtension {
3838
}
3939
}
4040

41-
public var configuration: ConnectingAppExtensionConfiguration {
42-
return globalConfiguration
41+
public nonisolated var configuration: ConnectingAppExtensionConfiguration {
42+
MainActor.runUnsafely {
43+
return globalConfiguration
44+
}
4345
}
4446
}
4547

@@ -53,8 +55,10 @@ public protocol SidebarChimeUIExtension<Scene>: ChimeExtension {
5355

5456
@available(macOS 13.0, *)
5557
extension SidebarChimeUIExtension {
56-
public var configuration: AppExtensionSceneConfiguration {
57-
return AppExtensionSceneConfiguration(self.scene, configuration: globalConfiguration)
58+
public nonisolated var configuration: AppExtensionSceneConfiguration {
59+
MainActor.runUnsafely {
60+
return AppExtensionSceneConfiguration(self.scene, configuration: globalConfiguration)
61+
}
5862
}
5963
}
6064

@@ -69,6 +73,8 @@ public protocol DocumentSyncedChimeUIExtension<Scene>: ChimeExtension {
6973
@available(macOS 13.0, *)
7074
extension DocumentSyncedChimeUIExtension {
7175
public var configuration: AppExtensionSceneConfiguration {
72-
return AppExtensionSceneConfiguration(self.scene, configuration: globalConfiguration)
76+
MainActor.runUnsafely {
77+
return AppExtensionSceneConfiguration(self.scene, configuration: globalConfiguration)
78+
}
7379
}
7480
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Foundation
2+
3+
extension MainActor {
4+
/// Execute the given body closure on the main actor without enforcing MainActor isolation.
5+
///
6+
/// It will crash if run on any non-main thread.
7+
@_unavailableFromAsync
8+
static func runUnsafely<T>(_ body: @MainActor () throws -> T) rethrows -> T {
9+
#if swift(>=5.9)
10+
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
11+
return try MainActor.assumeIsolated(body)
12+
}
13+
#endif
14+
15+
dispatchPrecondition(condition: .onQueue(.main))
16+
return try withoutActuallyEscaping(body) { fn in
17+
try unsafeBitCast(fn, to: (() throws -> T).self)()
18+
}
19+
}
20+
}
21+

Sources/ChimeExtensionInterface/Scenes.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Extendable
66

77
/// Identifier used to distinuish scenes provided by an extension.
88
public enum ChimeExtensionSceneIdentifier: String, CaseIterable, Hashable, Codable, Sendable {
9-
case main
9+
case main
1010
}
1111

1212
/// Base protocol used by all Chime extension scenes.
@@ -29,17 +29,19 @@ extension AppExtensionSceneGroup: ChimeExtensionScene {
2929
@available(macOS 13.0, *)
3030
@MainActor
3131
public struct SidebarScene<Content: View>: ChimeExtensionScene {
32-
private let content: () -> Content
32+
private let content: () -> Content
3333

34-
public init(content: @escaping () -> Content) {
35-
self.content = content
36-
}
34+
public init(content: @escaping () -> Content) {
35+
self.content = content
36+
}
3737

38-
public var body: some AppExtensionScene {
39-
ConnectingAppExtensionScene(sceneID: ChimeExtensionSceneIdentifier.main.rawValue) { _, connection in
40-
SceneContextView(connection: connection, content)
38+
public nonisolated var body: some AppExtensionScene {
39+
MainActor.runUnsafely {
40+
ConnectingAppExtensionScene(sceneID: ChimeExtensionSceneIdentifier.main.rawValue) { _, connection in
41+
SceneContextView(connection: connection, content)
42+
}
4143
}
42-
}
44+
}
4345
}
4446

4547
/// An editor sidebar view with a horizontal size kept in sync with the current document.
@@ -59,9 +61,11 @@ public struct DocumentSyncedScene<Content: View>: ChimeExtensionScene {
5961
self.content = content
6062
}
6163

62-
public var body: some AppExtensionScene {
63-
ConnectingAppExtensionScene(sceneID: ChimeExtensionSceneIdentifier.main.rawValue) { _, connection in
64-
SceneContextView(connection: connection, content)
64+
public nonisolated var body: some AppExtensionScene {
65+
MainActor.runUnsafely {
66+
ConnectingAppExtensionScene(sceneID: ChimeExtensionSceneIdentifier.main.rawValue) { _, connection in
67+
SceneContextView(connection: connection, content)
68+
}
6569
}
6670
}
6771
}

Sources/ChimeLSPAdapter/LSPDocumentService.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ extension LSPDocumentService: DocumentService {
8080
let params = DidChangeTextDocumentParams(textDocument: versionedId,
8181
contentChanges: events)
8282

83-
try await serverHostInterface.server.textDocumentDidChange(params: params)
83+
try await serverHostInterface.server.textDocumentDidChange(params)
8484
}
8585

8686
func didApplyChange(_ change: CombinedTextChange) throws {
@@ -119,7 +119,7 @@ extension LSPDocumentService: DocumentService {
119119
serverHostInterface.enqueue(barrier: true) { server, _, _ in
120120
let params = WillSaveTextDocumentParams(textDocument: id, reason: .manual)
121121

122-
try await server.textDocumentWillSave(params: params)
122+
try await server.textDocumentWillSave(params)
123123
}
124124
}
125125

@@ -146,7 +146,7 @@ extension LSPDocumentService: CompletionService {
146146
let params = CompletionParams(textDocument: textDocId, position: lspPosition, context: lspContext)
147147

148148
do {
149-
let response = try await server.completion(params: params)
149+
let response = try await server.completion(params)
150150

151151

152152
let fallbackRange = TextRange.range(NSRange(location: location, length: 0))
@@ -179,7 +179,7 @@ extension LSPDocumentService: FormattingService {
179179
insertSpaces: configuration.indentIsSoft)
180180
let params = DocumentFormattingParams(textDocument: textDocId, options: options)
181181

182-
let response = try await server.formatting(params: params)
182+
let response = try await server.formatting(params)
183183

184184
let transformer = transformers.textEditsTransformer
185185

@@ -212,7 +212,7 @@ extension LSPDocumentService: FormattingService {
212212
end: Position(line: 1, character: 0))
213213
let params = CodeActionParams(textDocument: textDocId, range: range, context: context)
214214

215-
let response = try await server.codeAction(params: params)
215+
let response = try await server.codeAction(params)
216216

217217
return transformers.organizeImportsTransformer(uri, response)
218218
}
@@ -225,7 +225,7 @@ extension LSPDocumentService: SemanticDetailsService {
225225
let textDocId = try context.textDocumentIdentifier
226226
let params = TextDocumentPositionParams(textDocument: textDocId, position: position.lspPosition)
227227

228-
let response = try await server.hover(params: params)
228+
let response = try await server.hover(params)
229229

230230
return transformers.hoverTransformer(position, response)
231231
}
@@ -238,7 +238,7 @@ extension LSPDocumentService: DefinitionService {
238238
let textDocId = try context.textDocumentIdentifier
239239
let params = TextDocumentPositionParams(textDocument: textDocId, position: position.lspPosition)
240240

241-
let definition = try await server.definition(params: params)
241+
let definition = try await server.definition(params)
242242

243243
return transformers.definitionTransformer(definition)
244244
}
@@ -257,13 +257,13 @@ extension LSPDocumentService: TokenService {
257257
if deltas, let lastId = lastResultId {
258258
let params = SemanticTokensDeltaParams(textDocument: id, previousResultId: lastId)
259259

260-
return try await server.semanticTokensFullDelta(params: params)
260+
return try await server.semanticTokensFullDelta(params)
261261
}
262262

263263
let params = SemanticTokensParams(textDocument: id)
264264

265265
// translate into a delta response
266-
return try await server.semanticTokensFull(params: params).map { .optionA($0) }
266+
return try await server.semanticTokensFull(params).map { .optionA($0) }
267267
}
268268

269269
func tokens(in range: CombinedTextRange) async throws -> [ChimeExtensionInterface.Token] {

Sources/ChimeLSPAdapter/LSPProjectService.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ extension LSPProjectService {
263263
let params = DidChangeWatchedFilesParams(changes: [event])
264264

265265
serverHostInterface.enqueue(barrier: true) { server, _, _ in
266-
try await server.workspaceDidChangeWatchedFiles(params: params)
266+
try await server.workspaceDidChangeWatchedFiles(params)
267267
}
268268
}
269269

@@ -336,7 +336,7 @@ extension LSPProjectService: ApplicationService {
336336
let item = try await docConnection.textDocumentItem
337337

338338
let params = DidOpenTextDocumentParams(textDocument: item)
339-
try await server.textDocumentDidOpen(params: params)
339+
try await server.textDocumentDidOpen(params)
340340
}
341341
}
342342

@@ -362,7 +362,7 @@ extension LSPProjectService: ApplicationService {
362362
let id = try docContext.textDocumentIdentifier
363363

364364
let param = DidCloseTextDocumentParams(textDocument: id)
365-
try await server.textDocumentDidClose(params: param)
365+
try await server.textDocumentDidClose(param)
366366
}
367367
}
368368

@@ -402,7 +402,7 @@ extension LSPProjectService: SymbolQueryService {
402402
}
403403

404404
let params = WorkspaceSymbolParams(query: query)
405-
let result = try await server.workspaceSymbol(params: params)
405+
let result = try await server.workspaceSymbol(params)
406406

407407
return transformers.workspaceSymbolResponseTransformer(result)
408408
}

0 commit comments

Comments
 (0)