@@ -335,13 +335,7 @@ extension SwiftLanguageService {
335335 ] )
336336 _ = try ? await self . sourcekitd. send ( closeReq, fileContents: nil )
337337
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)
345339 _ = try ? await self . sourcekitd. send ( openReq, fileContents: snapshot. text)
346340
347341 if await capabilityRegistry. clientSupportsPullDiagnostics ( for: . swift) {
@@ -375,12 +369,26 @@ extension SwiftLanguageService {
375369
376370 // MARK: - Text synchronization
377371
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+
378388 public func openDocument( _ note: DidOpenTextDocumentNotification ) async {
379389 cancelInFlightPublishDiagnosticsTask ( for: note. textDocument. uri)
380390 await diagnosticReportManager. removeItemsFromCache ( with: note. textDocument. uri)
381391
382- let keys = self . keys
383-
384392 guard let snapshot = self . documentManager. open ( note) else {
385393 // Already logged failure.
386394 return
@@ -402,17 +410,7 @@ extension SwiftLanguageService {
402410 )
403411 }
404412
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)
416414 _ = try ? await self . sourcekitd. send ( req, fileContents: snapshot. text)
417415 await publishDiagnosticsIfNeeded ( for: note. textDocument. uri)
418416 }
0 commit comments