Skip to content

Commit 66dd25e

Browse files
committed
Merge branch 'main' into release/6.0
2 parents 32f3b9d + 17c0a44 commit 66dd25e

32 files changed

+2027
-334
lines changed

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
134134

135135
for crashInfo in crashInfos {
136136
let dateFormatter = DateFormatter()
137+
dateFormatter.timeZone = NSTimeZone.local
137138
dateFormatter.dateStyle = .none
138139
dateFormatter.timeStyle = .medium
139140
let progressMessagePrefix = "Reducing Swift compiler crash at \(dateFormatter.string(from: crashInfo.date))"
@@ -304,7 +305,9 @@ public struct DiagnoseCommand: AsyncParsableCommand {
304305

305306
progressBar = PercentProgressAnimation(stream: stderrStream, header: "Diagnosing sourcekit-lsp issues")
306307

307-
let date = ISO8601DateFormatter().string(from: Date()).replacingOccurrences(of: ":", with: "-")
308+
let dateFormatter = ISO8601DateFormatter()
309+
dateFormatter.timeZone = NSTimeZone.local
310+
let date = dateFormatter.string(from: Date()).replacingOccurrences(of: ":", with: "-")
308311
let bundlePath = FileManager.default.temporaryDirectory
309312
.appendingPathComponent("sourcekitd-reproducer-\(date)")
310313
try FileManager.default.createDirectory(at: bundlePath, withIntermediateDirectories: true)
@@ -330,9 +333,9 @@ public struct DiagnoseCommand: AsyncParsableCommand {
330333
print(
331334
"""
332335
333-
Bundle created.
334-
When filing an issue at https://github.com/apple/sourcekit-lsp/issues/new,
335-
please attach the bundle located at
336+
Bundle created.
337+
When filing an issue at https://github.com/apple/sourcekit-lsp/issues/new,
338+
please attach the bundle located at
336339
\(bundlePath.path)
337340
"""
338341
)

Sources/Diagnose/SwiftFrontendCrashScraper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct SwiftFrontendCrashScraper {
7070
}
7171
let interestingString = fileContents[firstNewline...]
7272
let dateFormatter = DateFormatter()
73+
dateFormatter.timeZone = NSTimeZone.local
7374
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSS Z"
7475
let decoder = JSONDecoder()
7576
decoder.dateDecodingStrategy = .formatted(dateFormatter)

Sources/LSPLogging/NonDarwinLogging.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ public struct NonDarwinLogMessage: ExpressibleByStringInterpolation, Expressible
245245
/// a new `DateFormatter` is rather expensive and its the same for all loggers.
246246
private let dateFormatter = {
247247
let dateFormatter = DateFormatter()
248-
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
248+
dateFormatter.timeZone = NSTimeZone.local
249+
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSS Z"
249250
return dateFormatter
250251
}()
251252

@@ -299,11 +300,20 @@ public struct NonDarwinLogger: Sendable {
299300
guard level >= self.logLevel else { return }
300301
let date = Date()
301302
loggingQueue.async {
303+
// Truncate log message after 10.000 characters to avoid flooding the log with huge log messages (eg. from a
304+
// sourcekitd response). 10.000 characters was chosen because it seems to fit the result of most sourcekitd
305+
// responses that are not generated interface or global completion results (which are a lot bigger).
306+
var message = message().value.string(for: self.privacyLevel)
307+
if message.utf8.count > 10_000 {
308+
// Check for UTF-8 byte length first because that's faster since it doesn't need to count UTF-8 characters.
309+
// Truncate using `.prefix` to avoid cutting of in the middle of a UTF-8 multi-byte character.
310+
message = message.prefix(10_000) + "..."
311+
}
302312
// Start each log message with `[org.swift.sourcekit-lsp` so that it’s easy to split the log to the different messages
303313
logHandler(
304314
"""
305315
[\(subsystem):\(category)] \(level) \(dateFormatter.string(from: date))
306-
\(message().value.string(for: self.privacyLevel))
316+
\(message)
307317
---
308318
"""
309319
)

Sources/LanguageServerProtocol/Requests/OpenInterfaceRequest.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,24 @@ public struct OpenInterfaceRequest: TextDocumentRequest, Hashable {
2323
public var moduleName: String
2424

2525
/// The module group name.
26-
public var groupNames: [String]
26+
public var groupName: String?
2727

2828
/// The symbol USR to search for in the generated module interface.
2929
public var symbolUSR: String?
3030

31-
public init(textDocument: TextDocumentIdentifier, name: String, symbolUSR: String?) {
31+
public init(textDocument: TextDocumentIdentifier, name: String, groupName: String?, symbolUSR: String?) {
3232
self.textDocument = textDocument
3333
self.symbolUSR = symbolUSR
34-
// Stdlib Swift modules are all in the "Swift" module, but their symbols return a module name `Swift.***`.
35-
let splitName = name.split(separator: ".")
36-
self.moduleName = String(splitName[0])
37-
self.groupNames = [String.SubSequence](splitName.dropFirst()).map(String.init)
34+
self.moduleName = name
35+
self.groupName = groupName
3836
}
3937

4038
/// Name of interface module name with group names appended
4139
public var name: String {
42-
if groupNames.count > 0 {
43-
return "\(self.moduleName).\(self.groupNames.joined(separator: "."))"
44-
} else {
45-
return self.moduleName
40+
if let groupName {
41+
return "\(self.moduleName).\(groupName.replacing("/", with: "."))"
4642
}
43+
return self.moduleName
4744
}
4845
}
4946

Sources/LanguageServerProtocol/Requests/SymbolInfoRequest.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ public struct SymbolInfoRequest: TextDocumentRequest, Hashable {
4848
/// Detailed information about a symbol, such as the response to a `SymbolInfoRequest`
4949
/// **(LSP Extension)**.
5050
public struct SymbolDetails: ResponseType, Hashable {
51+
public struct ModuleInfo: Codable, Hashable, Sendable {
52+
/// The name of the module in which the symbol is defined.
53+
public let moduleName: String
54+
55+
/// If the symbol is defined within a subgroup of a module, the name of the group. Otherwise `nil`.
56+
public let groupName: String?
57+
58+
public init(moduleName: String, groupName: String? = nil) {
59+
self.moduleName = moduleName
60+
self.groupName = groupName
61+
}
62+
}
5163

5264
/// The name of the symbol, if any.
5365
public var name: String?
@@ -87,6 +99,11 @@ public struct SymbolDetails: ResponseType, Hashable {
8799
/// Optional because `clangd` does not return whether a symbol is dynamic.
88100
public var isDynamic: Bool?
89101

102+
/// Whether this symbol is defined in the SDK or standard library.
103+
///
104+
/// This property only applies to Swift symbols.
105+
public var isSystem: Bool?
106+
90107
/// If the symbol is dynamic, the USRs of the types that might be called.
91108
///
92109
/// This is relevant in the following cases
@@ -112,21 +129,31 @@ public struct SymbolDetails: ResponseType, Hashable {
112129
/// `B` may be called dynamically.
113130
public var receiverUsrs: [String]?
114131

132+
/// If the symbol is defined in a module that doesn't have source information associated with it, the name and group
133+
/// and group name that defines this symbol.
134+
///
135+
/// This property only applies to Swift symbols.
136+
public var systemModule: ModuleInfo?
137+
115138
public init(
116139
name: String?,
117140
containerName: String?,
118141
usr: String?,
119142
bestLocalDeclaration: Location?,
120143
kind: SymbolKind?,
121144
isDynamic: Bool?,
122-
receiverUsrs: [String]?
145+
isSystem: Bool?,
146+
receiverUsrs: [String]?,
147+
systemModule: ModuleInfo?
123148
) {
124149
self.name = name
125150
self.containerName = containerName
126151
self.usr = usr
127152
self.bestLocalDeclaration = bestLocalDeclaration
128153
self.kind = kind
129154
self.isDynamic = isDynamic
155+
self.isSystem = isSystem
130156
self.receiverUsrs = receiverUsrs
157+
self.systemModule = systemModule
131158
}
132159
}

Sources/LanguageServerProtocol/SupportTypes/TestItem.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public struct TestItem: ResponseType, Equatable {
3939
/// When `nil` the `label` is used.
4040
public let sortText: String?
4141

42+
/// Whether the test is disabled.
43+
public let disabled: Bool
44+
45+
/// The type of test, eg. the testing framework that was used to declare the test.
46+
public let style: String
47+
4248
/// The location of the test item in the source code.
4349
public let location: Location
4450

@@ -55,6 +61,8 @@ public struct TestItem: ResponseType, Equatable {
5561
label: String,
5662
description: String? = nil,
5763
sortText: String? = nil,
64+
disabled: Bool,
65+
style: String,
5866
location: Location,
5967
children: [TestItem],
6068
tags: [TestTag]
@@ -63,6 +71,8 @@ public struct TestItem: ResponseType, Equatable {
6371
self.label = label
6472
self.description = description
6573
self.sortText = sortText
74+
self.disabled = disabled
75+
self.style = style
6676
self.location = location
6777
self.children = children
6878
self.tags = tags

Sources/SKCore/BuildSystemManager.swift

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public actor BuildSystemManager {
4545
let fallbackBuildSystem: FallbackBuildSystem?
4646

4747
/// Provider of file to main file mappings.
48-
var _mainFilesProvider: MainFilesProvider?
48+
var mainFilesProvider: MainFilesProvider?
4949

5050
/// Build system delegate that will receive notifications about setting changes, etc.
51-
var _delegate: BuildSystemDelegate?
51+
var delegate: BuildSystemDelegate?
5252

5353
/// The root of the project that this build system manages. For example, for SwiftPM packages, this is the folder
5454
/// containing Package.swift. For compilation databases it is the root folder based on which the compilation database
@@ -71,7 +71,7 @@ public actor BuildSystemManager {
7171
precondition(!buildSystemHasDelegate)
7272
self.buildSystem = buildSystem
7373
self.fallbackBuildSystem = fallbackBuildSystem
74-
self._mainFilesProvider = mainFilesProvider
74+
self.mainFilesProvider = mainFilesProvider
7575
self.fallbackSettingsTimeout = fallbackSettingsTimeout
7676
await self.buildSystem?.setDelegate(self)
7777
}
@@ -82,21 +82,11 @@ public actor BuildSystemManager {
8282
}
8383

8484
extension BuildSystemManager {
85-
public var delegate: BuildSystemDelegate? {
86-
get { _delegate }
87-
set { _delegate = newValue }
88-
}
89-
9085
/// - Note: Needed so we can set the delegate from a different isolation context.
9186
public func setDelegate(_ delegate: BuildSystemDelegate?) {
9287
self.delegate = delegate
9388
}
9489

95-
public var mainFilesProvider: MainFilesProvider? {
96-
get { _mainFilesProvider }
97-
set { _mainFilesProvider = newValue }
98-
}
99-
10090
/// - Note: Needed so we can set the delegate from a different isolation context.
10191
public func setMainFilesProvider(_ mainFilesProvider: MainFilesProvider?) {
10292
self.mainFilesProvider = mainFilesProvider
@@ -204,15 +194,15 @@ extension BuildSystemManager: BuildSystemDelegate {
204194
public func fileBuildSettingsChanged(_ changedFiles: Set<DocumentURI>) async {
205195
let changedWatchedFiles = watchedFilesReferencing(mainFiles: changedFiles)
206196

207-
if !changedWatchedFiles.isEmpty, let delegate = self._delegate {
197+
if !changedWatchedFiles.isEmpty, let delegate = self.delegate {
208198
await delegate.fileBuildSettingsChanged(changedWatchedFiles)
209199
}
210200
}
211201

212202
public func filesDependenciesUpdated(_ changedFiles: Set<DocumentURI>) async {
213203
// Empty changes --> assume everything has changed.
214204
guard !changedFiles.isEmpty else {
215-
if let delegate = self._delegate {
205+
if let delegate = self.delegate {
216206
await delegate.filesDependenciesUpdated(changedFiles)
217207
}
218208
return
@@ -226,13 +216,13 @@ extension BuildSystemManager: BuildSystemDelegate {
226216
}
227217

228218
public func buildTargetsChanged(_ changes: [BuildTargetEvent]) async {
229-
if let delegate = self._delegate {
219+
if let delegate = self.delegate {
230220
await delegate.buildTargetsChanged(changes)
231221
}
232222
}
233223

234224
public func fileHandlingCapabilityChanged() async {
235-
if let delegate = self._delegate {
225+
if let delegate = self.delegate {
236226
await delegate.fileHandlingCapabilityChanged()
237227
}
238228
}

Sources/SKSupport/AsyncUtils.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ public extension Task {
7676
}
7777
}
7878

79+
public extension Task where Failure == Never {
80+
/// Awaits the value of the result.
81+
///
82+
/// If the current task is cancelled, this will cancel the subtask as well.
83+
var valuePropagatingCancellation: Success {
84+
get async {
85+
await withTaskCancellationHandler {
86+
return await self.value
87+
} onCancel: {
88+
self.cancel()
89+
}
90+
}
91+
}
92+
}
93+
7994
/// Allows the execution of a cancellable operation that returns the results
8095
/// via a completion handler.
8196
///

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,34 @@ public enum SkipUnless {
232232
}
233233
}
234234

235+
/// Checks whether the index contains a fix that prevents it from adding relations to non-indexed locals
236+
/// (https://github.com/apple/swift/pull/72930).
237+
public static func indexOnlyHasContainedByRelationsToIndexedDecls(
238+
file: StaticString = #file,
239+
line: UInt = #line
240+
) async throws {
241+
return try await skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
242+
let project = try await IndexedSingleSwiftFileTestProject(
243+
"""
244+
func foo() {}
245+
246+
func 1️⃣testFunc(x: String) {
247+
let myVar = foo
248+
}
249+
"""
250+
)
251+
let prepare = try await project.testClient.send(
252+
CallHierarchyPrepareRequest(
253+
textDocument: TextDocumentIdentifier(project.fileURI),
254+
position: project.positions["1️⃣"]
255+
)
256+
)
257+
let initialItem = try XCTUnwrap(prepare?.only)
258+
let calls = try await project.testClient.send(CallHierarchyOutgoingCallsRequest(item: initialItem))
259+
return calls != []
260+
}
261+
}
262+
235263
public static func longTestsEnabled() throws {
236264
if let value = ProcessInfo.processInfo.environment["SKIP_LONG_TESTS"], value == "1" || value == "YES" {
237265
throw XCTSkip("Long tests disabled using the `SKIP_LONG_TESTS` environment variable")

Sources/SourceKitLSP/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ target_sources(SourceKitLSP PRIVATE
2020
Clang/ClangLanguageService.swift)
2121
target_sources(SourceKitLSP PRIVATE
2222
Swift/AdjustPositionToStartOfIdentifier.swift
23+
Swift/CodeActions/ConvertIntegerLiteral.swift
24+
Swift/CodeActions/SyntaxCodeActionProvider.swift
25+
Swift/CodeActions/SyntaxCodeActions.swift
26+
Swift/CodeActions/SyntaxRefactoringCodeActionProvider.swift
2327
Swift/CodeCompletion.swift
2428
Swift/CodeCompletionSession.swift
2529
Swift/CommentXML.swift
@@ -38,6 +42,7 @@ target_sources(SourceKitLSP PRIVATE
3842
Swift/SourceKitD+ResponseError.swift
3943
Swift/SwiftCommand.swift
4044
Swift/SwiftLanguageService.swift
45+
Swift/SwiftTestingScanner.swift
4146
Swift/SymbolInfo.swift
4247
Swift/SyntaxHighlightingToken.swift
4348
Swift/SyntaxHighlightingTokens.swift

Sources/SourceKitLSP/SourceKitIndexDelegate.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Dispatch
1414
import IndexStoreDB
15+
import LSPLogging
1516
import SKCore
1617
import SKSupport
1718

@@ -51,17 +52,18 @@ public actor SourceKitIndexDelegate: IndexDelegate {
5152
private func processCompleted(_ count: Int) {
5253
pendingUnitCount -= count
5354
if pendingUnitCount == 0 {
54-
_indexChanged()
55+
indexChanged()
5556
}
5657

5758
if pendingUnitCount < 0 {
5859
assertionFailure("pendingUnitCount = \(pendingUnitCount) < 0")
5960
pendingUnitCount = 0
60-
_indexChanged()
61+
indexChanged()
6162
}
6263
}
6364

64-
func _indexChanged() {
65+
private func indexChanged() {
66+
logger.debug("IndexStoreDB changed")
6567
for callback in mainFilesChangedCallbacks {
6668
queue.async {
6769
await callback()

0 commit comments

Comments
 (0)