Commit Graph

34 Commits

Author SHA1 Message Date
Alex Hoppen
f8002f72fd Support building SourceKit-LSP without a dependency on SwiftPM
(cherry picked from commit 5326852ea8)
2025-01-23 11:43:10 -08:00
Alex Hoppen
1d7c27bc4b Adopt MemberImportVisibility 2024-11-05 21:04:01 -08:00
Alex Hoppen
8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen
0bb605d641 Remove a few workarounds that should no longer be needed 2024-08-07 10:00:04 -07:00
Alex Hoppen
2a99abdd4d Merge pull request #1593 from ahoppen/swift-6-cmake
Build in Swift 6 mode using CMake
2024-07-30 19:45:07 -07:00
Alex Hoppen
03de5c1408 Build in Swift 6 mode using CMake
The CMake build should only be run when building an entire toolchain, which means that we are guaranteed to have a Swift 6 compiler at hand and can unconditionally enable Swift 6 mode.
2024-07-30 16:47:44 -07:00
Alex Hoppen
ea9bf37634 Make SourceKit-LSP build without warnings
Fixes all build warnings in SourceKit-LSP so that it builds without any issues using recent Swift development snapshots (`swift-DEVELOPMENT-SNAPSHOT-2024-07-22-a` and `swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-24-a`)
2024-07-25 15:45:22 -07:00
Alex Hoppen
8c34a76f59 Rename LSPLogging to SKLogging 2024-07-25 09:11:13 -07:00
Alex Hoppen
82e54ef6f5 Merge pull request #1575 from AppAppWorks/fix-leading-trivia-convert-string-concatenation-to-string-interpolation
Fix for trivia not preserved after string interpolation conversion
2024-07-22 16:44:43 -07:00
Alex Hoppen
8e3bb6bd2f Merge pull request #1573 from ahoppen/package-access-level 2024-07-20 21:55:38 -07:00
Kai Lau
db3867bdbb fixed the issue that leading and trailing trivia are lost after string interpolation conversion 2024-07-20 16:45:40 -07:00
Alex Hoppen
2877675bd5 Adopt package access level
Change a l public declarations to the `package` access level, accept for:
- The `LanguageServerProtocol` module
- The `BuildServerProtocol` module
- `InProcessClient.InProcessSourceKitLSPClient`
- `LanguageServerProtocolJSONRPC` (I would like to create a more ergonomic API for this like `InProcessSourceKitLSPClient` in the future, but for now, we’ll leave it public)

Unfortunately, our pattern of marking functions as `@_spi(Testing) public` no longer works with the `package` access level because declarations at the `package` access level cannot be marked as SPI. I have decided to just mark these functions as `package`. Alternatives would be:
- Add an underscore to these functions, like we did for functions exposed for testing before the introduction of `SPI`
- Use `@testable` import in the test targets and mark the methods as `internal`

Resolves #1315
rdar://128295618
2024-07-19 09:54:30 -07:00
Kai Lau
17e33a672b Convert String Concatenation to String Interpolation
added `ConvertStringConcatenationToStringInterpolation` to convert string concatenation to string interpolation:
- the string concatenation must contain at least one string literal
- the number of pound symbols in the resulting string interpolation is determined by the highest number of pound symbols among all string literals in the string concatenation
- multiline string literals are not supported
registered in `SyntaxCodeActions.allSyntaxCodeActions`
registered in Sources/SourceKitLSP/CMakeLists
created a test in `CodeActionTests`
2024-07-17 14:57:30 -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
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
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
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