Skip to content

Merge main into release/6.0 #1236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9dc166d
Rename diagnose bundle created on disk from `sourcekitd-reproducer` t…
ahoppen May 3, 2024
59130de
Delete unnecessary imports of `IndexStoreDB`
ahoppen Apr 25, 2024
7d49916
Make `BuildServerBuildSystem.buildSettings(for:language:)` not throwing
ahoppen Apr 29, 2024
a954964
Move `Collection.partition(intoNumberOfBatches:)` to `SKSupport`
ahoppen Apr 29, 2024
46f0d1b
Fix issue in `AsyncQueue` that didn’t respect the requested task prio…
ahoppen May 2, 2024
e5254c0
Allow `serverOptions` to be specified on `SwiftPMTestProject`
ahoppen Apr 29, 2024
9c01f87
Pass all `SourceKitLSPServer.Options` to `Workspace`
ahoppen Apr 29, 2024
221c9b2
Move logic to select the toolchain for a document from `SourceKitLSPS…
ahoppen May 2, 2024
5e4f1b0
Generalize `BuildSystem.testFiles` to return all source files in a pr…
ahoppen Apr 29, 2024
1f87e7f
Move `CheckedIndex` to a new `SemanticIndex` module
ahoppen May 2, 2024
932f92c
Expose `pollForUnitChangesAndWait` on `CheckedIndex`
ahoppen May 2, 2024
9ff1ff1
Allow querying the build system for the language of a document
ahoppen May 2, 2024
d114399
Add method on `Process` that waits until exit and sends a `SIGINT` to…
ahoppen May 2, 2024
8590a4b
Use an atomic for `notificationIDForLogging`
ahoppen May 2, 2024
47850f4
Allow overriding the current logging subsystem
ahoppen May 2, 2024
28d0dd3
Log messages from `TaskScheduler` to a different subsystem
ahoppen May 2, 2024
d4b1586
Merge pull request #1220 from ahoppen/rename-diagnose-bundle
ahoppen May 3, 2024
555df60
[build-script-helper] Prefer just-built plugins to SDK plugins
rintaro May 1, 2024
ee6d696
Merge pull request #1221 from rintaro/toolchain-plugin
rintaro May 4, 2024
ab32186
Generalize SyntaxRefactoringCodeActionProvider to work with EditRefac…
DougGregor Apr 25, 2024
b628738
Add "Add documentation" code action to stub out documentation for a f…
DougGregor Apr 26, 2024
c298626
Update test for new refactoring action
DougGregor May 5, 2024
ccea54f
Merge pull request #1206 from DougGregor/add-documentation-code-action
DougGregor May 5, 2024
e71aa5d
Merge pull request #1214 from ahoppen/background-index-preparation
ahoppen May 5, 2024
73b2e26
Add GitHub issue templates
ahoppen May 6, 2024
9f7e7b0
Move `CODEOWNERS` to `.github` folder
ahoppen May 6, 2024
6a9a95f
Fix test discovery for Objective-C XCTests
ahoppen Apr 21, 2024
f8d0c60
Use `TokenSyntax.indentationOfLine` from SwiftBasicFormat instead of …
ahoppen May 6, 2024
329e3d3
Use `as(DeclSyntaxEnum.self)` instead of force-unwrapping
ahoppen May 6, 2024
5e1ff2d
Merge pull request #1225 from ahoppen/add-documentation-followup
ahoppen May 6, 2024
e54c99e
Add a syntactic "Add Codable structs from JSON" code action
DougGregor Apr 25, 2024
037e55e
Handle unexpected nodes following a closure
DougGregor May 6, 2024
5640204
Prevent rename of argument labels for enum cases
ahoppen May 7, 2024
c0d0d83
Log request ID of received requests
ahoppen May 7, 2024
d4bbf9c
Address review comments
DougGregor May 7, 2024
7e5f87f
Merge pull request #1205 from DougGregor/convert-json-to-codable
DougGregor May 7, 2024
d7deae7
Merge pull request #1224 from ahoppen/issue-template
ahoppen May 7, 2024
60c8391
Merge pull request #1229 from ahoppen/fix-enum-case-rename-issue
ahoppen May 7, 2024
30459c7
Don’t report no-op rename edits
ahoppen May 7, 2024
bdddc2b
Merge pull request #1196 from ahoppen/tests-for-objc-xctest
ahoppen May 7, 2024
22e3eea
Merge pull request #1231 from ahoppen/log-request-id
ahoppen May 7, 2024
624d4b6
Merge pull request #1230 from ahoppen/no-noop-rename-edits
ahoppen May 7, 2024
18fd0a7
Merge branch 'main' into release/6.0
ahoppen May 7, 2024
714ff2a
Adjustment because `trimmedRange` is not available in swift-syntax `r…
ahoppen May 7, 2024
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
4 changes: 0 additions & 4 deletions CODEOWNERS → .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@
# Order is important. The last matching pattern has the most precedence.

# Owner of anything in SourceKit-LSP not owned by anyone else.
# N: Ben Langmuir
# E: [email protected]
# N: Alex Hoppen
# E: [email protected]
* @benlangmuir @ahoppen
53 changes: 53 additions & 0 deletions .github/ISSUE_TEMPLATE/BUG_REPORT.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Bug Report
description: Something isn't working as expected
labels: [bug]
body:
- type: input
id: version
attributes:
label: Swift version
description: Which version of Swift are you using? If you are unsure, insert the output of `path/to/swift --version`
placeholder: Eg. swiftlang-5.10.0.13, swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a
- type: input
id: platform
attributes:
label: Platform
description: What operating system are you seeing the issue on?
placeholder: Eg. Ubuntu 22.04, Windows 11, macOS 14
- type: input
id: editor
attributes:
label: Editor
description: Which text editor are you using?
placeholder: Eg. Visual Studio Code with Swift plugin 1.9.0, neovim
- type: dropdown
id: reproduces-with-swift-6
attributes:
label: Does the issue reproduce with Swift 6?
description: |
Does the issue also reproduce using a [recent Swift 6 Development Snapshot](https://www.swift.org/download/#swift-60-development)?

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.
options:
- "Yes"
- "No"
- I didn’t try
- type: textarea
id: description
attributes:
label: Description
description: |
A short description of the incorrect behavior.
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.
- type: textarea
id: steps-to-reproduce
attributes:
label: Steps to Reproduce
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.
- type: textarea
id: logging
attributes:
label: Logging
description: |
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.
The generated bundle might contain portions of your source code, so please only attach it if you feel comfortable sharing it.
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/FEATURE_REQUEST.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Feature Request
description: A suggestion for a new feature
labels: [enhancement]
body:
- type: textarea
id: description
attributes:
label: Description
description: |
A description of your proposed feature.
Examples that show what's missing, or what new capabilities will be possible, are very helpful!
If this feature unlocks new use-cases please describe them.
Provide links to existing issues or external references/discussions, if appropriate.
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2024 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for Swift project authors

contact_links:
- name: Discussion Forum
url: https://forums.swift.org/c/development/sourcekit-lsp
about: Ask and answer questions about SourceKit-LSP
14 changes: 14 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ let package = Package(
]
),

// MARK: SemanticIndex

.target(
name: "SemanticIndex",
dependencies: [
"LSPLogging",
"SKCore",
.product(name: "IndexStoreDB", package: "indexstore-db"),
],
exclude: ["CMakeLists.txt"]
),

// MARK: SKCore
// Data structures and algorithms useful across the project, but not necessarily
// suitable for use in other packages.
Expand Down Expand Up @@ -300,9 +312,11 @@ let package = Package(
name: "SourceKitLSP",
dependencies: [
"BuildServerProtocol",
"CAtomics",
"LanguageServerProtocol",
"LanguageServerProtocolJSONRPC",
"LSPLogging",
"SemanticIndex",
"SKCore",
"SKSupport",
"SKSwiftPMWorkspace",
Expand Down
28 changes: 28 additions & 0 deletions Sources/CAtomics/include/CAtomics.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,32 @@ static inline void atomic_uint8_set(AtomicUInt8 *atomic, uint8_t newValue) {
atomic->value = newValue;
}

// MARK: AtomicInt

typedef struct {
_Atomic(int) value;
} AtomicUInt32;

__attribute__((swift_name("AtomicUInt32.init(initialValue:)")))
static inline AtomicUInt32 atomic_int_create(uint8_t initialValue) {
AtomicUInt32 atomic;
atomic.value = initialValue;
return atomic;
}

__attribute__((swift_name("getter:AtomicUInt32.value(self:)")))
static inline uint32_t atomic_int_get(AtomicUInt32 *atomic) {
return atomic->value;
}

__attribute__((swift_name("setter:AtomicUInt32.value(self:_:)")))
static inline void atomic_uint32_set(AtomicUInt32 *atomic, uint32_t newValue) {
atomic->value = newValue;
}

__attribute__((swift_name("AtomicUInt32.fetchAndIncrement(self:)")))
static inline uint32_t atomic_uint32_fetch_and_increment(AtomicUInt32 *atomic) {
return atomic->value++;
}

#endif // SOURCEKITLSP_CATOMICS_H
1 change: 1 addition & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_subdirectory(Diagnose)
add_subdirectory(LanguageServerProtocol)
add_subdirectory(LanguageServerProtocolJSONRPC)
add_subdirectory(LSPLogging)
add_subdirectory(SemanticIndex)
add_subdirectory(SKCore)
add_subdirectory(SKSupport)
add_subdirectory(SKSwiftPMWorkspace)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Diagnose/DiagnoseCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {
dateFormatter.timeZone = NSTimeZone.local
let date = dateFormatter.string(from: Date()).replacingOccurrences(of: ":", with: "-")
let bundlePath = FileManager.default.temporaryDirectory
.appendingPathComponent("sourcekitd-reproducer-\(date)")
.appendingPathComponent("sourcekit-lsp-diagnose-\(date)")
try FileManager.default.createDirectory(at: bundlePath, withIntermediateDirectories: true)

if components.isEmpty || components.contains(.crashReports) {
Expand Down
5 changes: 1 addition & 4 deletions Sources/LSPLogging/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

import Foundation

/// The subsystem that should be used for any logging by default.
public let subsystem = "org.swift.sourcekit-lsp"

#if canImport(os) && !SOURCEKITLSP_FORCE_NON_DARWIN_LOGGER
import os // os_log

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

/// The logger that is used to log any messages.
public var logger: Logger {
Logger(subsystem: subsystem, category: LoggingScope.scope)
Logger(subsystem: LoggingScope.subsystem, category: LoggingScope.scope)
}
35 changes: 35 additions & 0 deletions Sources/LSPLogging/LoggingScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,50 @@
import Foundation

public final class LoggingScope {
/// The name of the current logging subsystem or `nil` if no logging scope is set.
@TaskLocal fileprivate static var _subsystem: String?

/// The name of the current logging scope or `nil` if no logging scope is set.
@TaskLocal fileprivate static var _scope: String?

/// The name of the current logging subsystem.
public static var subsystem: String {
return _subsystem ?? "org.swift.sourcekit-lsp"
}

/// The name of the current logging scope.
public static var scope: String {
return _scope ?? "default"
}
}

/// Logs all messages created from the operation to the given subsystem.
///
/// This overrides the current logging subsystem.
///
/// - Note: Since this stores the logging subsystem in a task-local value, it only works when run inside a task.
/// Outside a task, this is a no-op.
public func withLoggingSubsystemAndScope<Result>(
subsystem: String,
scope: String?,
_ operation: () throws -> Result
) rethrows -> Result {
return try LoggingScope.$_subsystem.withValue(subsystem) {
return try LoggingScope.$_scope.withValue(scope, operation: operation)
}
}

/// Same as `withLoggingSubsystemAndScope` but allows the operation to be `async`.
public func withLoggingSubsystemAndScope<Result>(
subsystem: String,
scope: String?,
_ operation: () async throws -> Result
) async rethrows -> Result {
return try await LoggingScope.$_subsystem.withValue(subsystem) {
return try await LoggingScope.$_scope.withValue(scope, operation: operation)
}
}

/// Create a new logging scope, which will be used as the category in any log messages created from the operation.
///
/// This overrides the current logging scope.
Expand Down
14 changes: 9 additions & 5 deletions Sources/SKCore/BuildServerBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,14 @@ extension BuildServerBuildSystem: BuildSystem {
///
/// Returns `nil` if no build settings have been received from the build
/// server yet or if no build settings are available for this file.
public func buildSettings(for document: DocumentURI, language: Language) async throws -> FileBuildSettings? {
public func buildSettings(for document: DocumentURI, language: Language) async -> FileBuildSettings? {
return buildSettings[document]
}

public func defaultLanguage(for document: DocumentURI) async -> Language? {
return nil
}

public func registerForChangeNotifications(for uri: DocumentURI) {
let request = RegisterForChanges(uri: uri, action: .register)
_ = self.buildServer?.send(request) { result in
Expand Down Expand Up @@ -317,14 +321,14 @@ extension BuildServerBuildSystem: BuildSystem {
return .unhandled
}

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

public func addTestFilesDidChangeCallback(_ callback: @escaping () async -> Void) {
// BuildServerBuildSystem does not support syntactic test discovery
public func addSourceFilesDidChangeCallback(_ callback: @escaping () async -> Void) {
// BuildServerBuildSystem does not support syntactic test discovery or background indexing.
// (https://github.com/apple/sourcekit-lsp/issues/1173).
}
}
Expand Down
40 changes: 29 additions & 11 deletions Sources/SKCore/BuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ public enum FileHandlingCapability: Comparable, Sendable {
case handled
}

public struct SourceFileInfo: Sendable {
/// The URI of the source file.
public let uri: DocumentURI

/// Whether the file might contain test cases. This property is an over-approximation. It might be true for files
/// from non-test targets or files that don't actually contain any tests. Keeping this list of files with
/// `mayContainTets` minimal as possible helps reduce the amount of work that the syntactic test indexer needs to
/// perform.
public let mayContainTests: Bool

public init(uri: DocumentURI, mayContainTests: Bool) {
self.uri = uri
self.mayContainTests = mayContainTests
}
}

/// Provider of FileBuildSettings and other build-related information.
///
/// The primary role of the build system is to answer queries for
Expand Down Expand Up @@ -71,6 +87,13 @@ public protocol BuildSystem: AnyObject, Sendable {
/// file or if it hasn't computed build settings for the file yet.
func buildSettings(for document: DocumentURI, language: Language) async throws -> FileBuildSettings?

/// If the build system has knowledge about the language that this document should be compiled in, return it.
///
/// This is used to determine the language in which a source file should be background indexed.
///
/// If `nil` is returned, the language based on the file's extension.
func defaultLanguage(for document: DocumentURI) async -> Language?

/// Register the given file for build-system level change notifications, such
/// as command line flag changes, dependency changes, etc.
///
Expand All @@ -88,18 +111,13 @@ public protocol BuildSystem: AnyObject, Sendable {

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

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

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

public let buildTargetsNotSupported =
ResponseError.methodNotFound(BuildTargets.method)
public let buildTargetsNotSupported = ResponseError.methodNotFound(BuildTargets.method)
Loading