Commit Graph

26 Commits

Author SHA1 Message Date
Alex Hoppen
bc6751eb36 Merge branch 'main' into 6.0/merge-main-2024-06-17 2024-06-17 17:20:44 -07:00
Alex Hoppen
202d723c77 When performing jump-to-definition on a method implementing a protocol requirement, jump to the requirement
rdar://129412482
2024-06-08 10:29:18 -07:00
Alex Hoppen
9a067371c2 Merge branch 'main' into 6.0/merge-main-2024-05-21
# Conflicts:
#	Sources/SKSwiftPMWorkspace/SwiftPMBuildSystem.swift
2024-05-21 11:07:56 -07:00
Doug Gregor
c2af2f5337 Merge pull request #1240 from DougGregor/code-action-add-target
Add code actions for adding library/executable/macro targets to a package manifest
2024-05-17 15:24:11 -07:00
Alex Hoppen
d555ccdebb Revert "Fix deprecated ByteSourceRange"
This reverts commit c5699fb4dd.
2024-05-14 15:39:11 -07:00
Alex Hoppen
70b62b05c0 Merge branch 'main' into 6.0/merge-main-2024-05-14 2024-05-14 15:35:23 -07:00
Alex Hoppen
7e7df04b48 Make the SourceKitLSP module build in Swift 6 mode
Swift 6 mode didn’t find any notable data races. But it’s good to know Swift 6 will prevent future ones.
2024-05-13 21:28:42 -07:00
Kim de Vos
c5699fb4dd Fix deprecated ByteSourceRange 2024-05-10 10:50:57 +02:00
Alex Hoppen
f1d6a081d2 Don’t show Add documentation refactoring for declarations that are not on a new line 2024-05-08 15:05:35 -07:00
Alex Hoppen
449d2a9b39 Fix a bug that caused documentation to be added at the start of the declaration’s trivia
This meant that if there were two newlines before the declaration, the documentation would be separated to the declaration by one newline and if the declaration was at the start of a line, the declaration would be on the same line as the doc comment, effectively making the documentation part of a comment.
2024-05-08 14:56:09 -07:00
Alex Hoppen
e3c498e3f1 Address my own review comments to #1179
Addresses a few minor comments and the following major ones:
- Add test cases for the syntax refactorings
- Don’t report code actions for refactorings that don’t actually modify the source
- Instead of just looking at the parent of the token of the selected range, walk up the syntax tree to find the syntax node to refactor. This makes the refactorings available in a lot more locations.
2024-05-08 14:56:09 -07:00
Doug Gregor
78f6132fb2 Add code actions for adding library/executable/macro targets to a package manifest 2024-05-07 23:29:44 -07:00
Doug Gregor
638fd5b7ce Add separate "add test" manifest actions for XCTest and Swift Testing 2024-05-07 22:52:51 -07:00
Alex Hoppen
714ff2a620 Adjustment because trimmedRange is not available in swift-syntax release/6.0 2024-05-07 11:45:39 -07:00
Doug Gregor
d4bbf9ccc1 Address review comments 2024-05-06 17:57:07 -07:00
Doug Gregor
037e55e9d6 Handle unexpected nodes following a closure 2024-05-06 14:32:29 -07:00
Doug Gregor
e54c99eebd Add a syntactic "Add Codable structs from JSON" code action
Add a syntactic action that takes JSON pasted into a Swift file or
placed in a string literal, then turns it into a set of Codable
structs that can represent the JSON. Our typical example starts like
this:

```
{
    "name": "Produce",
    "shelves": [
        {
            "name": "Discount Produce",
            "product": {
                "name": "Banana",
                "points": 200,
                "description": "A banana that's perfectly ripe."
            }
        }
    ]
}
```

and turns into this:

```swift
struct JSONValue: Codable {
    var name: String
    var shelves: [Shelves]

    struct Shelves: Codable {
        var name: String
        var product: Product

        struct Product: Codable {
            var description: String
            var name: String
            var points: Double
        }
    }
}
```

When converting to JSON, we attempt to reason about multiple JSON
objects on the same level to detect when there are optional fields,
due to either an explicit null or due to the absence of fields in some
of the JSON objects that are conceptually stored together.

The refactoring itself would live down in the swift-syntax package if
not for its dependency on Foundation. We'll move it when appropriate.
2024-05-06 13:53:14 -07:00
Alex Hoppen
329e3d3297 Use as(DeclSyntaxEnum.self) instead of force-unwrapping 2024-05-06 08:36:01 -07:00
Alex Hoppen
f8d0c6098b Use TokenSyntax.indentationOfLine from SwiftBasicFormat instead of duplicating indentation inferring logic 2024-05-06 08:25:21 -07:00
Doug Gregor
b628738473 Add "Add documentation" code action to stub out documentation for a function
This code action takes an undocumented function declaration like

    func refactor(syntax: DeclSyntax, in context: Void) -> DeclSyntax?

and adds stub documentation for the parameters / result / etc., like this:

    /// A description
    /// - Parameters:
    ///   - syntax:
    ///   - context:
    ///
    /// - Returns:
2024-05-04 15:08:12 -07:00
Doug Gregor
ab32186382 Generalize SyntaxRefactoringCodeActionProvider to work with EditRefactoringProvider
Rather than only adapt refactoring actions that conform to
SyntaxRefactoringProvider, which takes a syntax node and produces a
syntax node, adapt to the less-constraining EditRefactoringProvider,
which takes a syntax node and produces edits. We can map edits over
just as effectively.
2024-05-04 14:16:51 -07:00
Doug Gregor
3674e7f663 Address code review feedback 2024-04-24 21:56:55 -07:00
Doug Gregor
5428b9c250 Reformat 2024-04-24 21:25:55 -07:00
Doug Gregor
0830a95a72 Address code review and add "Add product to export this target" action 2024-04-24 21:25:55 -07:00
Doug Gregor
531d5777a7 Add refactoring action for adding a test target to a package manifest
Leverage the newly-introduced package manifest editing tools in SwiftPM
to create a package editing refactoring operation. This operation can
be triggered from the a target in the manifest itself, e.g.,

    .target(name: "MyLib")

and will add a test target to the package manifest that depends on
this target, i.e.,

    .testTarget(
      name: "MyLibTests",
      dependencies: [ "MyLib" ]
    )

It will also create a new source file `Tests/MyLibTests/MyLibTests.swift`
that that imports both MyLib and XCTest, and contains an XCTestCase subclass
with one test to get you started.
2024-04-24 21:25:54 -07:00
Doug Gregor
a8b61a52d3 Introduce new refactoring code actions based on the Swift syntax tree.
This change includes a number of new refactoring code actions that
build on the syntax refactorings for the SwiftRefactor module of swift-syntax:

  * Add digit separators to an integer literal, e.g., `1000000` ->
    `1_000_000`.
  * Remove digit separators from an integer literal, e.g., 1_000_000 ->
    1000000.
  * Format a raw string literal, e.g., `"Hello \#(world)"` ->
    `##"Hello\#(world)"##`
  * Migrate to new if let syntax, e.g., `if let x = x { ... }` ->
    `if let x { ... }`
  * Replace opaque parameters with generic parameters, e.g.,
    `func f(p: some P)` --> `func f<T1: P>(p: T1)`.

This is generally easy to do, requiring one conformance to provide a name for the refactoring:

    extension AddSeparatorsToIntegerLiteral: SyntaxRefactoringCodeActionProvider {
      public static var title: String { "Add digit separators" }
    }
2024-04-16 23:00:20 -07:00