Skip to content

Commit aa0ed90

Browse files
authored
Merge pull request #1236 from ahoppen/6.0/merge-main-2024-05-07
Merge `main` into `release/6.0`
2 parents 0ccbf68 + 714ff2a commit aa0ed90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2087
-239
lines changed

CODEOWNERS renamed to .github/CODEOWNERS

-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88
# Order is important. The last matching pattern has the most precedence.
99

1010
# Owner of anything in SourceKit-LSP not owned by anyone else.
11-
# N: Ben Langmuir
12-
13-
# N: Alex Hoppen
14-
1511
* @benlangmuir @ahoppen

.github/ISSUE_TEMPLATE/BUG_REPORT.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Bug Report
2+
description: Something isn't working as expected
3+
labels: [bug]
4+
body:
5+
- type: input
6+
id: version
7+
attributes:
8+
label: Swift version
9+
description: Which version of Swift are you using? If you are unsure, insert the output of `path/to/swift --version`
10+
placeholder: Eg. swiftlang-5.10.0.13, swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a
11+
- type: input
12+
id: platform
13+
attributes:
14+
label: Platform
15+
description: What operating system are you seeing the issue on?
16+
placeholder: Eg. Ubuntu 22.04, Windows 11, macOS 14
17+
- type: input
18+
id: editor
19+
attributes:
20+
label: Editor
21+
description: Which text editor are you using?
22+
placeholder: Eg. Visual Studio Code with Swift plugin 1.9.0, neovim
23+
- type: dropdown
24+
id: reproduces-with-swift-6
25+
attributes:
26+
label: Does the issue reproduce with Swift 6?
27+
description: |
28+
Does the issue also reproduce using a [recent Swift 6 Development Snapshot](https://www.swift.org/download/#swift-60-development)?
29+
30+
We have made significant changes to SourceKit-LSP in Swift 6 and the issue might have already been fixed. If you didn’t try, that is fine.
31+
options:
32+
- "Yes"
33+
- "No"
34+
- I didn’t try
35+
- type: textarea
36+
id: description
37+
attributes:
38+
label: Description
39+
description: |
40+
A short description of the incorrect behavior.
41+
If you think this issue has been recently introduced and did not occur in an earlier version, please note that. If possible, include the last version that the behavior was correct in addition to your current version.
42+
- type: textarea
43+
id: steps-to-reproduce
44+
attributes:
45+
label: Steps to Reproduce
46+
description: If you have steps that reproduce the issue, please add them here. If you can share a project that reproduces the issue, please attach it.
47+
- type: textarea
48+
id: logging
49+
attributes:
50+
label: Logging
51+
description: |
52+
If you are using SourceKit-LSP from Swift 6, running `sourcekit-lsp diagnose` in terminal and attaching the generated bundle helps us diagnose the issue.
53+
The generated bundle might contain portions of your source code, so please only attach it if you feel comfortable sharing it.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Feature Request
2+
description: A suggestion for a new feature
3+
labels: [enhancement]
4+
body:
5+
- type: textarea
6+
id: description
7+
attributes:
8+
label: Description
9+
description: |
10+
A description of your proposed feature.
11+
Examples that show what's missing, or what new capabilities will be possible, are very helpful!
12+
If this feature unlocks new use-cases please describe them.
13+
Provide links to existing issues or external references/discussions, if appropriate.

.github/ISSUE_TEMPLATE/config.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See https://swift.org/LICENSE.txt for license information
7+
# See https://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
contact_links:
10+
- name: Discussion Forum
11+
url: https://forums.swift.org/c/development/sourcekit-lsp
12+
about: Ask and answer questions about SourceKit-LSP

Package.swift

+14
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ let package = Package(
168168
]
169169
),
170170

171+
// MARK: SemanticIndex
172+
173+
.target(
174+
name: "SemanticIndex",
175+
dependencies: [
176+
"LSPLogging",
177+
"SKCore",
178+
.product(name: "IndexStoreDB", package: "indexstore-db"),
179+
],
180+
exclude: ["CMakeLists.txt"]
181+
),
182+
171183
// MARK: SKCore
172184
// Data structures and algorithms useful across the project, but not necessarily
173185
// suitable for use in other packages.
@@ -300,9 +312,11 @@ let package = Package(
300312
name: "SourceKitLSP",
301313
dependencies: [
302314
"BuildServerProtocol",
315+
"CAtomics",
303316
"LanguageServerProtocol",
304317
"LanguageServerProtocolJSONRPC",
305318
"LSPLogging",
319+
"SemanticIndex",
306320
"SKCore",
307321
"SKSupport",
308322
"SKSwiftPMWorkspace",

Sources/CAtomics/include/CAtomics.h

+28
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,32 @@ static inline void atomic_uint8_set(AtomicUInt8 *atomic, uint8_t newValue) {
6363
atomic->value = newValue;
6464
}
6565

66+
// MARK: AtomicInt
67+
68+
typedef struct {
69+
_Atomic(int) value;
70+
} AtomicUInt32;
71+
72+
__attribute__((swift_name("AtomicUInt32.init(initialValue:)")))
73+
static inline AtomicUInt32 atomic_int_create(uint8_t initialValue) {
74+
AtomicUInt32 atomic;
75+
atomic.value = initialValue;
76+
return atomic;
77+
}
78+
79+
__attribute__((swift_name("getter:AtomicUInt32.value(self:)")))
80+
static inline uint32_t atomic_int_get(AtomicUInt32 *atomic) {
81+
return atomic->value;
82+
}
83+
84+
__attribute__((swift_name("setter:AtomicUInt32.value(self:_:)")))
85+
static inline void atomic_uint32_set(AtomicUInt32 *atomic, uint32_t newValue) {
86+
atomic->value = newValue;
87+
}
88+
89+
__attribute__((swift_name("AtomicUInt32.fetchAndIncrement(self:)")))
90+
static inline uint32_t atomic_uint32_fetch_and_increment(AtomicUInt32 *atomic) {
91+
return atomic->value++;
92+
}
93+
6694
#endif // SOURCEKITLSP_CATOMICS_H

Sources/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_subdirectory(Diagnose)
55
add_subdirectory(LanguageServerProtocol)
66
add_subdirectory(LanguageServerProtocolJSONRPC)
77
add_subdirectory(LSPLogging)
8+
add_subdirectory(SemanticIndex)
89
add_subdirectory(SKCore)
910
add_subdirectory(SKSupport)
1011
add_subdirectory(SKSwiftPMWorkspace)

Sources/Diagnose/DiagnoseCommand.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
309309
dateFormatter.timeZone = NSTimeZone.local
310310
let date = dateFormatter.string(from: Date()).replacingOccurrences(of: ":", with: "-")
311311
let bundlePath = FileManager.default.temporaryDirectory
312-
.appendingPathComponent("sourcekitd-reproducer-\(date)")
312+
.appendingPathComponent("sourcekit-lsp-diagnose-\(date)")
313313
try FileManager.default.createDirectory(at: bundlePath, withIntermediateDirectories: true)
314314

315315
if components.isEmpty || components.contains(.crashReports) {

Sources/LSPLogging/Logging.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
import Foundation
2323

24-
/// The subsystem that should be used for any logging by default.
25-
public let subsystem = "org.swift.sourcekit-lsp"
26-
2724
#if canImport(os) && !SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER
2825
import os // os_log
2926

@@ -44,5 +41,5 @@ public typealias Signposter = NonDarwinSignposter
4441

4542
/// The logger that is used to log any messages.
4643
public var logger: Logger {
47-
Logger(subsystem: subsystem, category: LoggingScope.scope)
44+
Logger(subsystem: LoggingScope.subsystem, category: LoggingScope.scope)
4845
}

Sources/LSPLogging/LoggingScope.swift

+35
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,50 @@
1313
import Foundation
1414

1515
public final class LoggingScope {
16+
/// The name of the current logging subsystem or `nil` if no logging scope is set.
17+
@TaskLocal fileprivate static var _subsystem: String?
18+
1619
/// The name of the current logging scope or `nil` if no logging scope is set.
1720
@TaskLocal fileprivate static var _scope: String?
1821

22+
/// The name of the current logging subsystem.
23+
public static var subsystem: String {
24+
return _subsystem ?? "org.swift.sourcekit-lsp"
25+
}
26+
1927
/// The name of the current logging scope.
2028
public static var scope: String {
2129
return _scope ?? "default"
2230
}
2331
}
2432

33+
/// Logs all messages created from the operation to the given subsystem.
34+
///
35+
/// This overrides the current logging subsystem.
36+
///
37+
/// - Note: Since this stores the logging subsystem in a task-local value, it only works when run inside a task.
38+
/// Outside a task, this is a no-op.
39+
public func withLoggingSubsystemAndScope<Result>(
40+
subsystem: String,
41+
scope: String?,
42+
_ operation: () throws -> Result
43+
) rethrows -> Result {
44+
return try LoggingScope.$_subsystem.withValue(subsystem) {
45+
return try LoggingScope.$_scope.withValue(scope, operation: operation)
46+
}
47+
}
48+
49+
/// Same as `withLoggingSubsystemAndScope` but allows the operation to be `async`.
50+
public func withLoggingSubsystemAndScope<Result>(
51+
subsystem: String,
52+
scope: String?,
53+
_ operation: () async throws -> Result
54+
) async rethrows -> Result {
55+
return try await LoggingScope.$_subsystem.withValue(subsystem) {
56+
return try await LoggingScope.$_scope.withValue(scope, operation: operation)
57+
}
58+
}
59+
2560
/// Create a new logging scope, which will be used as the category in any log messages created from the operation.
2661
///
2762
/// This overrides the current logging scope.

Sources/SKCore/BuildServerBuildSystem.swift

+9-5
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,14 @@ extension BuildServerBuildSystem: BuildSystem {
263263
///
264264
/// Returns `nil` if no build settings have been received from the build
265265
/// server yet or if no build settings are available for this file.
266-
public func buildSettings(for document: DocumentURI, language: Language) async throws -> FileBuildSettings? {
266+
public func buildSettings(for document: DocumentURI, language: Language) async -> FileBuildSettings? {
267267
return buildSettings[document]
268268
}
269269

270+
public func defaultLanguage(for document: DocumentURI) async -> Language? {
271+
return nil
272+
}
273+
270274
public func registerForChangeNotifications(for uri: DocumentURI) {
271275
let request = RegisterForChanges(uri: uri, action: .register)
272276
_ = self.buildServer?.send(request) { result in
@@ -317,14 +321,14 @@ extension BuildServerBuildSystem: BuildSystem {
317321
return .unhandled
318322
}
319323

320-
public func testFiles() async -> [DocumentURI] {
321-
// BuildServerBuildSystem does not support syntactic test discovery
324+
public func sourceFiles() async -> [SourceFileInfo] {
325+
// BuildServerBuildSystem does not support syntactic test discovery or background indexing.
322326
// (https://github.com/apple/sourcekit-lsp/issues/1173).
323327
return []
324328
}
325329

326-
public func addTestFilesDidChangeCallback(_ callback: @escaping () async -> Void) {
327-
// BuildServerBuildSystem does not support syntactic test discovery
330+
public func addSourceFilesDidChangeCallback(_ callback: @escaping () async -> Void) {
331+
// BuildServerBuildSystem does not support syntactic test discovery or background indexing.
328332
// (https://github.com/apple/sourcekit-lsp/issues/1173).
329333
}
330334
}

Sources/SKCore/BuildSystem.swift

+29-11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ public enum FileHandlingCapability: Comparable, Sendable {
2727
case handled
2828
}
2929

30+
public struct SourceFileInfo: Sendable {
31+
/// The URI of the source file.
32+
public let uri: DocumentURI
33+
34+
/// Whether the file might contain test cases. This property is an over-approximation. It might be true for files
35+
/// from non-test targets or files that don't actually contain any tests. Keeping this list of files with
36+
/// `mayContainTets` minimal as possible helps reduce the amount of work that the syntactic test indexer needs to
37+
/// perform.
38+
public let mayContainTests: Bool
39+
40+
public init(uri: DocumentURI, mayContainTests: Bool) {
41+
self.uri = uri
42+
self.mayContainTests = mayContainTests
43+
}
44+
}
45+
3046
/// Provider of FileBuildSettings and other build-related information.
3147
///
3248
/// The primary role of the build system is to answer queries for
@@ -71,6 +87,13 @@ public protocol BuildSystem: AnyObject, Sendable {
7187
/// file or if it hasn't computed build settings for the file yet.
7288
func buildSettings(for document: DocumentURI, language: Language) async throws -> FileBuildSettings?
7389

90+
/// If the build system has knowledge about the language that this document should be compiled in, return it.
91+
///
92+
/// This is used to determine the language in which a source file should be background indexed.
93+
///
94+
/// If `nil` is returned, the language based on the file's extension.
95+
func defaultLanguage(for document: DocumentURI) async -> Language?
96+
7497
/// Register the given file for build-system level change notifications, such
7598
/// as command line flag changes, dependency changes, etc.
7699
///
@@ -88,18 +111,13 @@ public protocol BuildSystem: AnyObject, Sendable {
88111

89112
func fileHandlingCapability(for uri: DocumentURI) async -> FileHandlingCapability
90113

91-
/// Returns the list of files that might contain test cases.
92-
///
93-
/// The returned file list is an over-approximation. It might contain tests from non-test targets or files that don't
94-
/// actually contain any tests. Keeping this list as minimal as possible helps reduce the amount of work that the
95-
/// syntactic test indexer needs to perform.
96-
func testFiles() async -> [DocumentURI]
114+
/// Returns the list of source files in the project.
115+
func sourceFiles() async -> [SourceFileInfo]
97116

98-
/// Adds a callback that should be called when the value returned by `testFiles()` changes.
117+
/// Adds a callback that should be called when the value returned by `sourceFiles()` changes.
99118
///
100-
/// The callback might also be called without an actual change to `testFiles`.
101-
func addTestFilesDidChangeCallback(_ callback: @Sendable @escaping () async -> Void) async
119+
/// The callback might also be called without an actual change to `sourceFiles`.
120+
func addSourceFilesDidChangeCallback(_ callback: @Sendable @escaping () async -> Void) async
102121
}
103122

104-
public let buildTargetsNotSupported =
105-
ResponseError.methodNotFound(BuildTargets.method)
123+
public let buildTargetsNotSupported = ResponseError.methodNotFound(BuildTargets.method)

0 commit comments

Comments
 (0)