13
13
import Dispatch
14
14
import LSPLogging
15
15
import LanguageServerProtocol
16
+ import SKCore
16
17
import SKSupport
17
18
import SourceKitD
18
19
import SwiftExtensions
@@ -92,6 +93,7 @@ class CodeCompletionSession {
92
93
static func completionList(
93
94
sourcekitd: any SourceKitD ,
94
95
snapshot: DocumentSnapshot ,
96
+ options: SourceKitLSPOptions ,
95
97
indentationWidth: Trivia ? ,
96
98
completionPosition: Position ,
97
99
completionUtf8Offset: Int ,
@@ -122,6 +124,7 @@ class CodeCompletionSession {
122
124
let session = CodeCompletionSession (
123
125
sourcekitd: sourcekitd,
124
126
snapshot: snapshot,
127
+ options: options,
125
128
indentationWidth: indentationWidth,
126
129
utf8Offset: completionUtf8Offset,
127
130
position: completionPosition,
@@ -139,6 +142,7 @@ class CodeCompletionSession {
139
142
140
143
private let sourcekitd : any SourceKitD
141
144
private let snapshot : DocumentSnapshot
145
+ private let options : SourceKitLSPOptions
142
146
/// The inferred indentation width of the source file the completion is being performed in
143
147
private let indentationWidth : Trivia ?
144
148
private let utf8StartOffset : Int
@@ -158,13 +162,15 @@ class CodeCompletionSession {
158
162
private init (
159
163
sourcekitd: any SourceKitD ,
160
164
snapshot: DocumentSnapshot ,
165
+ options: SourceKitLSPOptions ,
161
166
indentationWidth: Trivia ? ,
162
167
utf8Offset: Int ,
163
168
position: Position ,
164
169
compileCommand: SwiftCompileCommand ? ,
165
170
clientSupportsSnippets: Bool
166
171
) {
167
172
self . sourcekitd = sourcekitd
173
+ self . options = options
168
174
self . indentationWidth = indentationWidth
169
175
self . snapshot = snapshot
170
176
self . utf8StartOffset = utf8Offset
@@ -193,7 +199,11 @@ class CodeCompletionSession {
193
199
keys. compilerArgs: compileCommand? . compilerArgs as [ SKDRequestValue ] ? ,
194
200
] )
195
201
196
- let dict = try await sourcekitd. send ( req, fileContents: snapshot. text)
202
+ let dict = try await sourcekitd. send (
203
+ req,
204
+ timeout: options. sourcekitdRequestTimeoutOrDefault,
205
+ fileContents: snapshot. text
206
+ )
197
207
self . state = . open
198
208
199
209
guard let completions: SKDResponseArray = dict [ keys. results] else {
@@ -226,7 +236,11 @@ class CodeCompletionSession {
226
236
keys. codeCompleteOptions: optionsDictionary ( filterText: filterText) ,
227
237
] )
228
238
229
- let dict = try await sourcekitd. send ( req, fileContents: snapshot. text)
239
+ let dict = try await sourcekitd. send (
240
+ req,
241
+ timeout: options. sourcekitdRequestTimeoutOrDefault,
242
+ fileContents: snapshot. text
243
+ )
230
244
guard let completions: SKDResponseArray = dict [ keys. results] else {
231
245
return CompletionList ( isIncomplete: false , items: [ ] )
232
246
}
@@ -269,7 +283,7 @@ class CodeCompletionSession {
269
283
keys. name: snapshot. uri. pseudoPath,
270
284
] )
271
285
logger. info ( " Closing code completion session: \( self . description) " )
272
- _ = try ? await sourcekitd. send ( req, fileContents: nil )
286
+ _ = try ? await sourcekitd. send ( req, timeout : options . sourcekitdRequestTimeoutOrDefault , fileContents: nil )
273
287
self . state = . closed
274
288
}
275
289
}
0 commit comments