1313import Dispatch
1414import LSPLogging
1515import LanguageServerProtocol
16+ import SKCore
1617import SKSupport
1718import SourceKitD
1819import SwiftExtensions
@@ -92,6 +93,7 @@ class CodeCompletionSession {
9293 static func completionList(
9394 sourcekitd: any SourceKitD ,
9495 snapshot: DocumentSnapshot ,
96+ options: SourceKitLSPOptions ,
9597 indentationWidth: Trivia ? ,
9698 completionPosition: Position ,
9799 completionUtf8Offset: Int ,
@@ -122,6 +124,7 @@ class CodeCompletionSession {
122124 let session = CodeCompletionSession (
123125 sourcekitd: sourcekitd,
124126 snapshot: snapshot,
127+ options: options,
125128 indentationWidth: indentationWidth,
126129 utf8Offset: completionUtf8Offset,
127130 position: completionPosition,
@@ -139,6 +142,7 @@ class CodeCompletionSession {
139142
140143 private let sourcekitd : any SourceKitD
141144 private let snapshot : DocumentSnapshot
145+ private let options : SourceKitLSPOptions
142146 /// The inferred indentation width of the source file the completion is being performed in
143147 private let indentationWidth : Trivia ?
144148 private let utf8StartOffset : Int
@@ -158,13 +162,15 @@ class CodeCompletionSession {
158162 private init (
159163 sourcekitd: any SourceKitD ,
160164 snapshot: DocumentSnapshot ,
165+ options: SourceKitLSPOptions ,
161166 indentationWidth: Trivia ? ,
162167 utf8Offset: Int ,
163168 position: Position ,
164169 compileCommand: SwiftCompileCommand ? ,
165170 clientSupportsSnippets: Bool
166171 ) {
167172 self . sourcekitd = sourcekitd
173+ self . options = options
168174 self . indentationWidth = indentationWidth
169175 self . snapshot = snapshot
170176 self . utf8StartOffset = utf8Offset
@@ -193,7 +199,11 @@ class CodeCompletionSession {
193199 keys. compilerArgs: compileCommand? . compilerArgs as [ SKDRequestValue ] ? ,
194200 ] )
195201
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+ )
197207 self . state = . open
198208
199209 guard let completions: SKDResponseArray = dict [ keys. results] else {
@@ -226,7 +236,11 @@ class CodeCompletionSession {
226236 keys. codeCompleteOptions: optionsDictionary ( filterText: filterText) ,
227237 ] )
228238
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+ )
230244 guard let completions: SKDResponseArray = dict [ keys. results] else {
231245 return CompletionList ( isIncomplete: false , items: [ ] )
232246 }
@@ -269,7 +283,7 @@ class CodeCompletionSession {
269283 keys. name: snapshot. uri. pseudoPath,
270284 ] )
271285 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 )
273287 self . state = . closed
274288 }
275289 }
0 commit comments