@@ -335,13 +335,7 @@ extension SwiftLanguageService {
335
335
] )
336
336
_ = try ? await self . sourcekitd. send ( closeReq, fileContents: nil )
337
337
338
- let openReq = sourcekitd. dictionary ( [
339
- keys. request: self . requests. editorOpen,
340
- keys. name: path,
341
- keys. sourceText: snapshot. text,
342
- keys. compilerArgs: compileCmd? . compilerArgs as [ SKDRequestValue ] ? ,
343
- ] )
344
-
338
+ let openReq = openDocumentSourcekitdRequest ( snapshot: snapshot, compileCommand: compileCmd)
345
339
_ = try ? await self . sourcekitd. send ( openReq, fileContents: snapshot. text)
346
340
347
341
if await capabilityRegistry. clientSupportsPullDiagnostics ( for: . swift) {
@@ -375,12 +369,26 @@ extension SwiftLanguageService {
375
369
376
370
// MARK: - Text synchronization
377
371
372
+ private func openDocumentSourcekitdRequest(
373
+ snapshot: DocumentSnapshot ,
374
+ compileCommand: SwiftCompileCommand ?
375
+ ) -> SKDRequestDictionary {
376
+ return sourcekitd. dictionary ( [
377
+ keys. request: self . requests. editorOpen,
378
+ keys. name: snapshot. uri. pseudoPath,
379
+ keys. sourceText: snapshot. text,
380
+ keys. enableSyntaxMap: 0 ,
381
+ keys. enableStructure: 0 ,
382
+ keys. enableDiagnostics: 0 ,
383
+ keys. syntacticOnly: 1 ,
384
+ keys. compilerArgs: compileCommand? . compilerArgs as [ SKDRequestValue ] ? ,
385
+ ] )
386
+ }
387
+
378
388
public func openDocument( _ note: DidOpenTextDocumentNotification ) async {
379
389
cancelInFlightPublishDiagnosticsTask ( for: note. textDocument. uri)
380
390
await diagnosticReportManager. removeItemsFromCache ( with: note. textDocument. uri)
381
391
382
- let keys = self . keys
383
-
384
392
guard let snapshot = self . documentManager. open ( note) else {
385
393
// Already logged failure.
386
394
return
@@ -402,17 +410,7 @@ extension SwiftLanguageService {
402
410
)
403
411
}
404
412
405
- let req = sourcekitd. dictionary ( [
406
- keys. request: self . requests. editorOpen,
407
- keys. name: note. textDocument. uri. pseudoPath,
408
- keys. sourceText: snapshot. text,
409
- keys. enableSyntaxMap: 0 ,
410
- keys. enableStructure: 0 ,
411
- keys. enableDiagnostics: 0 ,
412
- keys. syntacticOnly: 1 ,
413
- keys. compilerArgs: buildSettings? . compilerArgs as [ SKDRequestValue ] ? ,
414
- ] )
415
-
413
+ let req = openDocumentSourcekitdRequest ( snapshot: snapshot, compileCommand: buildSettings)
416
414
_ = try ? await self . sourcekitd. send ( req, fileContents: snapshot. text)
417
415
await publishDiagnosticsIfNeeded ( for: note. textDocument. uri)
418
416
}
0 commit comments