Commit Graph

7 Commits

Author SHA1 Message Date
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
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
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