From 76da45444f88b3183ee62e247f33d945b7b5c9f0 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Thu, 23 May 2024 13:41:40 -0700 Subject: [PATCH 1/3] Re-generate sourcekitd UIDs --- Sources/SourceKitD/sourcekitd_uids.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Sources/SourceKitD/sourcekitd_uids.swift b/Sources/SourceKitD/sourcekitd_uids.swift index f3f2df312..e28734a3d 100644 --- a/Sources/SourceKitD/sourcekitd_uids.swift +++ b/Sources/SourceKitD/sourcekitd_uids.swift @@ -71,8 +71,6 @@ public struct sourcekitd_api_keys { public let moduleInterfaceName: sourcekitd_api_uid_t /// `key.hash` public let hash: sourcekitd_api_uid_t - /// `key.compilerargs` - public let compilerArgs: sourcekitd_api_uid_t /// `key.severity` public let severity: sourcekitd_api_uid_t /// `key.offset` @@ -81,8 +79,6 @@ public struct sourcekitd_api_keys { public let length: sourcekitd_api_uid_t /// `key.sourcefile` public let sourceFile: sourcekitd_api_uid_t - /// `key.sourcetext` - public let sourceText: sourcekitd_api_uid_t /// `key.primary_file` public let primaryFile: sourcekitd_api_uid_t /// `key.enablesyntaxmap` @@ -215,6 +211,8 @@ public struct sourcekitd_api_keys { public let deprecated: sourcekitd_api_uid_t /// `key.obsoleted` public let obsoleted: sourcekitd_api_uid_t + /// `key.cancel_builds` + public let cancelBuilds: sourcekitd_api_uid_t /// `key.removecache` public let removeCache: sourcekitd_api_uid_t /// `key.typeusr` @@ -415,6 +413,10 @@ public struct sourcekitd_api_keys { public let ignoreStdlib: sourcekitd_api_uid_t /// `key.disable_implicit_modules` public let disableImplicitModules: sourcekitd_api_uid_t + /// `key.compilerargs` + public let compilerArgs: sourcekitd_api_uid_t + /// `key.sourcetext` + public let sourceText: sourcekitd_api_uid_t /// `key.codecomplete.sort.byname` public let sortByName: sourcekitd_api_uid_t /// `key.codecomplete.sort.useimportdepth` @@ -495,12 +497,10 @@ public struct sourcekitd_api_keys { filePath = api.uid_get_from_cstr("key.filepath")! moduleInterfaceName = api.uid_get_from_cstr("key.module_interface_name")! hash = api.uid_get_from_cstr("key.hash")! - compilerArgs = api.uid_get_from_cstr("key.compilerargs")! severity = api.uid_get_from_cstr("key.severity")! offset = api.uid_get_from_cstr("key.offset")! length = api.uid_get_from_cstr("key.length")! sourceFile = api.uid_get_from_cstr("key.sourcefile")! - sourceText = api.uid_get_from_cstr("key.sourcetext")! primaryFile = api.uid_get_from_cstr("key.primary_file")! enableSyntaxMap = api.uid_get_from_cstr("key.enablesyntaxmap")! enableStructure = api.uid_get_from_cstr("key.enablesubstructure")! @@ -567,6 +567,7 @@ public struct sourcekitd_api_keys { introduced = api.uid_get_from_cstr("key.introduced")! deprecated = api.uid_get_from_cstr("key.deprecated")! obsoleted = api.uid_get_from_cstr("key.obsoleted")! + cancelBuilds = api.uid_get_from_cstr("key.cancel_builds")! removeCache = api.uid_get_from_cstr("key.removecache")! typeUsr = api.uid_get_from_cstr("key.typeusr")! containerTypeUsr = api.uid_get_from_cstr("key.containertypeusr")! @@ -667,6 +668,8 @@ public struct sourcekitd_api_keys { includeSystemModules = api.uid_get_from_cstr("key.include_system_modules")! ignoreStdlib = api.uid_get_from_cstr("key.ignore_stdlib")! disableImplicitModules = api.uid_get_from_cstr("key.disable_implicit_modules")! + compilerArgs = api.uid_get_from_cstr("key.compilerargs")! + sourceText = api.uid_get_from_cstr("key.sourcetext")! sortByName = api.uid_get_from_cstr("key.codecomplete.sort.byname")! useImportDepth = api.uid_get_from_cstr("key.codecomplete.sort.useimportdepth")! groupOverloads = api.uid_get_from_cstr("key.codecomplete.group.overloads")! From c5e29b19fa985caf423db07767d812019c473a01 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Fri, 10 May 2024 15:57:59 -0700 Subject: [PATCH 2/3] =?UTF-8?q?Don=E2=80=99t=20load=20the=20syntax=20map?= =?UTF-8?q?=20etc=20when=20re-opening=20a=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Swift/SwiftLanguageService.swift | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift b/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift index acadc4609..ed341adb6 100644 --- a/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift +++ b/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift @@ -335,13 +335,7 @@ extension SwiftLanguageService { ]) _ = try? await self.sourcekitd.send(closeReq, fileContents: nil) - let openReq = sourcekitd.dictionary([ - keys.request: self.requests.editorOpen, - keys.name: path, - keys.sourceText: snapshot.text, - keys.compilerArgs: compileCmd?.compilerArgs as [SKDRequestValue]?, - ]) - + let openReq = openDocumentSourcekitdRequest(snapshot: snapshot, compileCommand: compileCmd) _ = try? await self.sourcekitd.send(openReq, fileContents: snapshot.text) if await capabilityRegistry.clientSupportsPullDiagnostics(for: .swift) { @@ -375,12 +369,26 @@ extension SwiftLanguageService { // MARK: - Text synchronization + private func openDocumentSourcekitdRequest( + snapshot: DocumentSnapshot, + compileCommand: SwiftCompileCommand? + ) -> SKDRequestDictionary { + return sourcekitd.dictionary([ + keys.request: self.requests.editorOpen, + keys.name: snapshot.uri.pseudoPath, + keys.sourceText: snapshot.text, + keys.enableSyntaxMap: 0, + keys.enableStructure: 0, + keys.enableDiagnostics: 0, + keys.syntacticOnly: 1, + keys.compilerArgs: compileCommand?.compilerArgs as [SKDRequestValue]?, + ]) + } + public func openDocument(_ note: DidOpenTextDocumentNotification) async { cancelInFlightPublishDiagnosticsTask(for: note.textDocument.uri) await diagnosticReportManager.removeItemsFromCache(with: note.textDocument.uri) - let keys = self.keys - guard let snapshot = self.documentManager.open(note) else { // Already logged failure. return @@ -402,17 +410,7 @@ extension SwiftLanguageService { ) } - let req = sourcekitd.dictionary([ - keys.request: self.requests.editorOpen, - keys.name: note.textDocument.uri.pseudoPath, - keys.sourceText: snapshot.text, - keys.enableSyntaxMap: 0, - keys.enableStructure: 0, - keys.enableDiagnostics: 0, - keys.syntacticOnly: 1, - keys.compilerArgs: buildSettings?.compilerArgs as [SKDRequestValue]?, - ]) - + let req = openDocumentSourcekitdRequest(snapshot: snapshot, compileCommand: buildSettings) _ = try? await self.sourcekitd.send(req, fileContents: snapshot.text) await publishDiagnosticsIfNeeded(for: note.textDocument.uri) } From 00aebd665945b1bcbf1390dc97ec72d234407635 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Thu, 23 May 2024 13:58:54 -0700 Subject: [PATCH 3/3] =?UTF-8?q?Don=E2=80=99t=20cancel=20build=20when=20clo?= =?UTF-8?q?sing=20a=20document?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In SourceKit-LSP, we can get into the following situation: 1. We open A.swift 2. We issue a request for A.swift, the request takes a while to execute 3. The dependencies of A.swift are updated, which causes us to reopen the document in sourcekitd, so that the AST is rebuilt 4. This shouldn’t cause the request from (2) to be cancelled. We should continue executing it and only re-open the document after the request from (2) has finished rdar://127475366 --- Sources/SourceKitLSP/Swift/SwiftLanguageService.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift b/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift index ed341adb6..69a3b5cdb 100644 --- a/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift +++ b/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift @@ -382,6 +382,7 @@ extension SwiftLanguageService { keys.enableDiagnostics: 0, keys.syntacticOnly: 1, keys.compilerArgs: compileCommand?.compilerArgs as [SKDRequestValue]?, + keys.cancelBuilds: 0, ]) }