Commit Graph

664 Commits

Author SHA1 Message Date
Alex Hoppen
72083762a4 When interacting with a document, prepare the target it belongs to
Whenever we get request for a document, open it or edit it, trigger a preparation of its target, but don’t block any interaction based on it. This should ensure that the target is usually prepared when the user is interacting with it.

We need to track the preparation status of targets somewhat accurately in `SemanticIndexManager`, so we don’t unnecessarily re-prepare a target. When updating the index store, it is acceptable to schedule another `UpdateIndexStoreTaskDescription` because it will early exit based on an `mtime` check with the unit file. Null builds of a target take significantly longer and thus we want to avoid them.

Fixes #1252
rdar://127474003
2024-05-16 10:40:47 -07:00
Alex Hoppen
546bb3230e Update index as files are modified on disk
Fixes #1251
rdar://127476161
2024-05-15 11:00:13 -07:00
Alex Hoppen
fff4dc4a9d Merge pull request #1300 from ahoppen/diagnostic-source-name
Change compiler’s diagnostic provider name to `SourceKit`
2024-05-14 13:25:54 -07:00
Alex Hoppen
7baffde1db Change compiler’s diagnostic provider name to SourceKit
The fact that they are coming from a service named `sourcekitd` should be an implentation detail of SourceKit-LSP and shouldn’t be exposed to users. Use the generic `SourceKit` term, which is vague about which SourceKit the diagnostics are coming from.
2024-05-14 10:02:35 -07:00
Alex Hoppen
a6389e58e2 Show a work done progress that shows the index progress
This makes it a lot easier to work on background indexing because you can easily see how background indexing is making progress.

Resolves #1257
rdar://127474057
2024-05-14 06:39:48 -07:00
Alex Hoppen
d70a68f37c Wait until initialization has finished before starting a work done progress 2024-05-14 06:38:22 -07:00
Alex Hoppen
c399b43858 Don’t pass the finished taskDescription to indexTaskDidFinish callback
This follows the general paradigm that callbacks shouldn’t carry much state and instead only notify an observer that state has changed, which the observer can then poll.
2024-05-14 06:38:22 -07:00
Alex Hoppen
5cce99b920 Make IndexTaskDescription protocol-based instead of enum-based
This simplifies the implementation.
2024-05-14 06:38:21 -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
4bff5603b4 Merge pull request #1250 from kimdv/kimdv/2532-merge-incrementaledit-and-sourceedit
Use new API's from SwiftSyntax SourceEdit
2024-05-13 08:27:02 -07:00
Alex Hoppen
740262cb24 Don’t set forceResolvedVersions to true when we have an index build directory
When `SwiftPMBuildSystem` operates on a ` .index-build` directory, it owns the checkouts and is thus also allowed to resolve the package versions. This is necessary
2024-05-10 14:43:32 -07:00
Alex Hoppen
5e83d7d904 Support background preparation of targets 2024-05-10 11:58:04 -07:00
Kim de Vos
ed61630875 Replace IncrementalEdit with SourceEdit 2024-05-10 10:50:57 +02:00
Kim de Vos
c5699fb4dd Fix deprecated ByteSourceRange 2024-05-10 10:50:57 +02:00
Kim de Vos
a71b428568 Remove ?? position as it never was used 2024-05-10 10:25:49 +02:00
Paul LeMarquand
6a791fd7ca Merge pull request #1227 from plemarquand/merge-extension-tests
Merge tests defined in extensions
2024-05-09 20:51:16 -04:00
Alex Hoppen
80694a35bf Merge pull request #1237 from ahoppen/refactoring-review-comments
Address my own review comments to #1179
2024-05-09 12:02:33 -07:00
Paul LeMarquand
baa3f616c9 Handle XCTest extensions 2024-05-08 23:01:41 -04: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
Paul LeMarquand
e740bb3394 Dont expose isExtension on TestItem 2024-05-08 14:30:16 -04:00
Alex Hoppen
a643749def Log an error if we couldn't find the definition of a USR in the index 2024-05-08 10:40:05 -07:00
Alex Hoppen
efba8ce9bc Merge pull request #1216 from ahoppen/background-indexing
Implement initial background indexing of a project
2024-05-08 10:35:18 -07:00
Doug Gregor
638fd5b7ce Add separate "add test" manifest actions for XCTest and Swift Testing 2024-05-07 22:52:51 -07:00
Paul LeMarquand
adfae1a77f Prioritize tests defined in type definition over those in extensions
Sort the list of test items prioritizing those defined in the
originating type definition over those in extensions.
2024-05-07 13:55:55 -04:00
Paul LeMarquand
03e2b4f82d Document mergeTestsInExtensions() 2024-05-07 13:39:25 -04:00
Paul LeMarquand
7b315680c9 Merge tests defined in extensions
Merge the XCTests and swift-testing tests defined in extensions into
their parent TestItems.

This is done as another pass after the TestScanner visitors have walked
the tree.

Fixes #1218
2024-05-07 13:39:25 -04:00
Alex Hoppen
624d4b690d Merge pull request #1230 from ahoppen/no-noop-rename-edits
Don’t report no-op rename edits
2024-05-07 07:12:05 -07:00
Alex Hoppen
22e3eea2aa Merge pull request #1231 from ahoppen/log-request-id
Log request ID of received requests
2024-05-07 07:11:56 -07:00
Alex Hoppen
bdddc2ba41 Merge pull request #1196 from ahoppen/tests-for-objc-xctest
Fix test discovery for Objective-C XCTests
2024-05-06 21:53:16 -07:00
Alex Hoppen
30459c7b54 Don’t report no-op rename edits
When renaming `func test(foo: Int) {}` to `test2(foo:)`, rename used to report an edit from `foo` to `foo`, which clutters the refactor preview view. We shouldn’t report edits if no text is actually changed.

rdar://127291815
2024-05-06 21:37:11 -07:00
Alex Hoppen
60c8391f0e Merge pull request #1229 from ahoppen/fix-enum-case-rename-issue
Prevent rename of argument labels for enum cases
2024-05-06 21:36:17 -07:00
Doug Gregor
d4bbf9ccc1 Address review comments 2024-05-06 17:57:07 -07:00
Alex Hoppen
c0d0d8368d Log request ID of received requests
Useful for correlating request IDs with cancellation notifications.
2024-05-06 17:48:35 -07:00
Alex Hoppen
56402044e2 Prevent rename of argument labels for enum cases
Renaming an enum case currently caused invalid code to be generated because we would rename eg. `myCase(String)` to `myNewCase(_ String)`.

Fixing the underlying issue requires changes to `sourcekitd`, that are out-of-scope at the moment. For now, just suppress argument label rename for enum cases in SourceKit-LSP and avoid generating invalid code even if just the base name is modified.

rdar://127248157
2024-05-06 17:07:26 -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
Alex Hoppen
6a9a95f9fd Fix test discovery for Objective-C XCTests
There were two issues with Objective-C XCTest discovery:
1. We were relying on syntactic test discovery after a document is edited. But since we don't have syntactic test discovery for Objective-C tests, this meant that all tests would disappear as a document got edited. Until we get syntactic test discovery for Objective-C, use the semantic index to discover tests, even if they are out-of-date.
2. We were assuming that the `DocumentSymbols` request returned `[DocumentSymbol]` to find the ranges of tests. But clangd returns the alternative `[SymbolInformation]`, which meant that we were only returning the position of a test function’s name instead of the test function’s range.

rdar://126810202
2024-05-06 08:17:09 -07:00
Alex Hoppen
1a5d1321a1 Implement initial background indexing of a project
Implements an initial background index when the project is opened.

The following will be implemented in follow-up PRs:
- Resolving package dependencies
- Preparing dependent modules
- Watching for file updates
2024-05-05 14:26:52 -07:00
Alex Hoppen
e71aa5d35e Merge pull request #1214 from ahoppen/background-index-preparation
Miscellaneous commits in preparation for background indexing
2024-05-05 14:26:11 -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
Alex Hoppen
47850f47cd Allow overriding the current logging subsystem 2024-05-03 14:48:15 -07:00
Alex Hoppen
8590a4bdc2 Use an atomic for notificationIDForLogging
This allows us to get rid of the lock.
2024-05-03 14:48:15 -07:00
Alex Hoppen
d114399270 Add method on Process that waits until exit and sends a SIGINT to the process if the Task is cancelled 2024-05-03 14:48:15 -07:00
Alex Hoppen
1f87e7fc4b Move CheckedIndex to a new SemanticIndex module 2024-05-03 14:48:15 -07:00
Alex Hoppen
5e4f1b03bf Generalize BuildSystem.testFiles to return all source files in a project 2024-05-03 14:48:15 -07:00