Skip to content

Commit 3300c77

Browse files
authored
Merge pull request #1339 from ahoppen/dont-cancel-sourcekitd-request-on-close
2 parents ba7b03c + 00aebd6 commit 3300c77

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

Sources/SourceKitD/sourcekitd_uids.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ public struct sourcekitd_api_keys {
7171
public let moduleInterfaceName: sourcekitd_api_uid_t
7272
/// `key.hash`
7373
public let hash: sourcekitd_api_uid_t
74-
/// `key.compilerargs`
75-
public let compilerArgs: sourcekitd_api_uid_t
7674
/// `key.severity`
7775
public let severity: sourcekitd_api_uid_t
7876
/// `key.offset`
@@ -81,8 +79,6 @@ public struct sourcekitd_api_keys {
8179
public let length: sourcekitd_api_uid_t
8280
/// `key.sourcefile`
8381
public let sourceFile: sourcekitd_api_uid_t
84-
/// `key.sourcetext`
85-
public let sourceText: sourcekitd_api_uid_t
8682
/// `key.primary_file`
8783
public let primaryFile: sourcekitd_api_uid_t
8884
/// `key.enablesyntaxmap`
@@ -215,6 +211,8 @@ public struct sourcekitd_api_keys {
215211
public let deprecated: sourcekitd_api_uid_t
216212
/// `key.obsoleted`
217213
public let obsoleted: sourcekitd_api_uid_t
214+
/// `key.cancel_builds`
215+
public let cancelBuilds: sourcekitd_api_uid_t
218216
/// `key.removecache`
219217
public let removeCache: sourcekitd_api_uid_t
220218
/// `key.typeusr`
@@ -415,6 +413,10 @@ public struct sourcekitd_api_keys {
415413
public let ignoreStdlib: sourcekitd_api_uid_t
416414
/// `key.disable_implicit_modules`
417415
public let disableImplicitModules: sourcekitd_api_uid_t
416+
/// `key.compilerargs`
417+
public let compilerArgs: sourcekitd_api_uid_t
418+
/// `key.sourcetext`
419+
public let sourceText: sourcekitd_api_uid_t
418420
/// `key.codecomplete.sort.byname`
419421
public let sortByName: sourcekitd_api_uid_t
420422
/// `key.codecomplete.sort.useimportdepth`
@@ -495,12 +497,10 @@ public struct sourcekitd_api_keys {
495497
filePath = api.uid_get_from_cstr("key.filepath")!
496498
moduleInterfaceName = api.uid_get_from_cstr("key.module_interface_name")!
497499
hash = api.uid_get_from_cstr("key.hash")!
498-
compilerArgs = api.uid_get_from_cstr("key.compilerargs")!
499500
severity = api.uid_get_from_cstr("key.severity")!
500501
offset = api.uid_get_from_cstr("key.offset")!
501502
length = api.uid_get_from_cstr("key.length")!
502503
sourceFile = api.uid_get_from_cstr("key.sourcefile")!
503-
sourceText = api.uid_get_from_cstr("key.sourcetext")!
504504
primaryFile = api.uid_get_from_cstr("key.primary_file")!
505505
enableSyntaxMap = api.uid_get_from_cstr("key.enablesyntaxmap")!
506506
enableStructure = api.uid_get_from_cstr("key.enablesubstructure")!
@@ -567,6 +567,7 @@ public struct sourcekitd_api_keys {
567567
introduced = api.uid_get_from_cstr("key.introduced")!
568568
deprecated = api.uid_get_from_cstr("key.deprecated")!
569569
obsoleted = api.uid_get_from_cstr("key.obsoleted")!
570+
cancelBuilds = api.uid_get_from_cstr("key.cancel_builds")!
570571
removeCache = api.uid_get_from_cstr("key.removecache")!
571572
typeUsr = api.uid_get_from_cstr("key.typeusr")!
572573
containerTypeUsr = api.uid_get_from_cstr("key.containertypeusr")!
@@ -667,6 +668,8 @@ public struct sourcekitd_api_keys {
667668
includeSystemModules = api.uid_get_from_cstr("key.include_system_modules")!
668669
ignoreStdlib = api.uid_get_from_cstr("key.ignore_stdlib")!
669670
disableImplicitModules = api.uid_get_from_cstr("key.disable_implicit_modules")!
671+
compilerArgs = api.uid_get_from_cstr("key.compilerargs")!
672+
sourceText = api.uid_get_from_cstr("key.sourcetext")!
670673
sortByName = api.uid_get_from_cstr("key.codecomplete.sort.byname")!
671674
useImportDepth = api.uid_get_from_cstr("key.codecomplete.sort.useimportdepth")!
672675
groupOverloads = api.uid_get_from_cstr("key.codecomplete.group.overloads")!

Sources/SourceKitLSP/Swift/SwiftLanguageService.swift

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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,27 @@ 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+
keys.cancelBuilds: 0,
386+
])
387+
}
388+
378389
public func openDocument(_ note: DidOpenTextDocumentNotification) async {
379390
cancelInFlightPublishDiagnosticsTask(for: note.textDocument.uri)
380391
await diagnosticReportManager.removeItemsFromCache(with: note.textDocument.uri)
381392

382-
let keys = self.keys
383-
384393
guard let snapshot = self.documentManager.open(note) else {
385394
// Already logged failure.
386395
return
@@ -402,17 +411,7 @@ extension SwiftLanguageService {
402411
)
403412
}
404413

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-
414+
let req = openDocumentSourcekitdRequest(snapshot: snapshot, compileCommand: buildSettings)
416415
_ = try? await self.sourcekitd.send(req, fileContents: snapshot.text)
417416
await publishDiagnosticsIfNeeded(for: note.textDocument.uri)
418417
}

0 commit comments

Comments
 (0)