File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed
Sources/SwiftSourceKitPlugin Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,18 @@ final class Connection {
113
113
sourcekitd. ideApi. connection_dispose ( impl)
114
114
}
115
115
116
+ //// A function that can be called to cancel a request with a request.
117
+ ///
118
+ /// This is not a member function on `Connection` so that `CompletionProvider` can store
119
+ /// this closure in a member and call it even while the `CompletionProvider` actor is busy
120
+ /// fulfilling a completion request and thus can't access `connection`.
121
+ var cancellationFunc : @Sendable ( RequestHandle ) -> Void {
122
+ nonisolated ( unsafe) let impl = self . impl
123
+ return { [ sourcekitd] handle in
124
+ sourcekitd. ideApi. cancel_request ( impl, handle. handle)
125
+ }
126
+ }
127
+
116
128
func openDocument( path: String , contents: String , compilerArguments: [ String ] ? = nil ) {
117
129
if documents [ path] != nil {
118
130
logger. error ( " Document at ' \( path) ' is already open " )
@@ -219,10 +231,6 @@ final class Connection {
219
231
)
220
232
}
221
233
222
- func cancel( handle: RequestHandle ) {
223
- sourcekitd. ideApi. cancel_request ( impl, handle. handle)
224
- }
225
-
226
234
func markCachedCompilerInstanceShouldBeInvalidated( ) {
227
235
sourcekitd. ideApi. connection_mark_cached_compiler_instance_should_be_invalidated ( impl, nil )
228
236
}
Original file line number Diff line number Diff line change @@ -86,6 +86,9 @@ actor CompletionProvider {
86
86
87
87
private let connection : Connection
88
88
89
+ /// See `Connection.cancellationFunc`
90
+ private nonisolated let cancel : @Sendable ( RequestHandle ) -> Void
91
+
89
92
/// The XPC custom buffer kind for `CompletionResultsArray`
90
93
private let completionResultsBufferKind : UInt64
91
94
@@ -101,17 +104,12 @@ actor CompletionProvider {
101
104
opaqueIDEInspectionInstance: opaqueIDEInspectionInstance? . value,
102
105
sourcekitd: sourcekitd
103
106
)
107
+ self . cancel = connection. cancellationFunc
104
108
self . completionResultsBufferKind = completionResultsBufferKind
105
109
}
106
110
107
111
nonisolated func cancel( handle: RequestHandle ) {
108
- Task {
109
- await self . cancelImpl ( handle: handle)
110
- }
111
- }
112
-
113
- private func cancelImpl( handle: RequestHandle ) {
114
- connection. cancel ( handle: handle)
112
+ self . cancel ( handle)
115
113
}
116
114
117
115
func handleDocumentOpen( _ request: SKDRequestDictionaryReader ) {
You can’t perform that action at this time.
0 commit comments