Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Sources/SourceKitD/sourcekitd_uids.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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")!
Expand Down Expand Up @@ -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")!
Expand Down Expand Up @@ -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")!
Expand Down
39 changes: 19 additions & 20 deletions Sources/SourceKitLSP/Swift/SwiftLanguageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -375,12 +369,27 @@ 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]?,
keys.cancelBuilds: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be set for the close rather than the open, right?

])
}

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
Expand All @@ -402,17 +411,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)
}
Expand Down