Commit Graph

466 Commits

Author SHA1 Message Date
Alex Hoppen
3f7d9a7b76 Fix a non-deterministic test failure in testPrepareTargetAfterEditToDependency
We could get a `DiagnosticsRefreshRequest` before the modified target had been re-prepared.
2024-05-22 14:46:03 -07:00
Alex Hoppen
9e49f67455 Rename TestSourceKitLSPClient.handleNextRequest to handleSingleRequest
Since `handleNextRequest` handling doesn’t have to be in the order that the request handlers were specified anymore, the naming was misleading.
2024-05-22 13:31:58 -07:00
Alex Hoppen
950a74a260 Fix a negation issue that prevented parallel indexing 2024-05-22 13:31:58 -07:00
Alex Hoppen
328a02ada5 Fix a race condition that caused IndexProgressManager to create two WorkDoneProgress 2024-05-22 10:41:18 -07:00
Alex Hoppen
3e6319c3b9 Produce an index log for the client
This allows a user of SourceKit-LSP to inspect the result of background indexing. This allows a user of SourceKit-LSP to inspect the result of background indexing. I think this gives useful insights into what SourceKit-LSP is indexing and why/how it fails, if it fails, also for users of SourceKit-LSP.

rdar://127474136
Fixes #1265
2024-05-21 22:18:06 -07:00
Alex Hoppen
a88798129d Add an option to show the files that are currently being index / targets being prepared in the work done progress 2024-05-21 22:09:22 -07:00
Alex Hoppen
41b810b80c Cancel preparation tasks for editor functionality if the preparation task hasn't been started yet and the document is no longer active
When the user opens documents from three targets A, B, and C in quick succession, then we don’t want to schedule preparation of wait until A *and* B are finished preparing before preparing C.

Instead, we want to
- Finish for preparation of A to finish if it has already started by the time the file in C is opened. This is done so we always make progress during preparation and don’t get into a scenario where preparation is always cancelled if a user switches between two targets more quickly than it takes to prepare those targets.
- Not prepare B because it is no longer relevant and we haven’t started any progress here. Essentially, we pretend that the hop to B never happened.
2024-05-21 18:12:24 -07:00
Alex Hoppen
e295a4e95a Split up-to-date status tracking and index progress tracking
We were mixing the up-to-date status and in-progress status of an index task in `SemanticIndexManager`. This meant that a single `QueuedTask` in the task scheduler could be needed for eg. both preparation for editor functionality in a file of that target and to re-index a file in that target. This dual ownership made it unclear, which caller would be entitled to cancel the task. Furthermore, we needed to duplicate some logic from the preparation task dependencies in `SemanticIndexManager.prepare`.

To simplify things:
- Split the up-to-date status and the in-progress status into two different data structures
- Make the caller of `prepare` and `scheduleIndex` responsible for cancellation of the task it has scheduled. `TaskScheduler` might receive more scheduled tasks this way but the additional tasks should all be no-ops because the status is known to be up-to-date when they execute.
2024-05-20 21:01:40 -07:00
Alex Hoppen
d12c946988 Merge pull request #1321 from ahoppen/target-preparation-testing 2024-05-20 20:02:01 -07:00
Alex Hoppen
af6cdeba37 Merge pull request #1313 from ahoppen/only-mark-dependent-targets-as-out-of-date
When a file is changed, only mark targets that depend on it as out-of-date
2024-05-20 13:40:51 -07:00
Alex Hoppen
815fea827e Add infrastructure to test which targets are being prepared 2024-05-20 09:49:24 -07:00
Alex Hoppen
0ce2107f43 Merge pull request #1317 from ahoppen/prepare-target-test-failure
Fix non-deterministic test failure in `BackgroundIndexingTests.testPrepareTarget`
2024-05-20 09:44:44 -07:00
Alex Hoppen
9524753826 Introduce test hooks that can be used to monitor when preparation and index tasks finish 2024-05-17 16:46:14 -07:00
Alex Hoppen
2d27d57b66 Extract indexTaskDidFinish in SourceKitLSPServer.Options into a TestHooks struct 2024-05-17 16:30:47 -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
a850cb6849 When a file is changed, only mark targets that depend on it as out-of-date 2024-05-17 14:32:49 -07:00
Alex Hoppen
068b6dfe16 Fix non-deterministic test failure in BackgroundIndexingTests.testPrepareTarget
We could get `DocumentDiagnosticsRequest` triggered from file changes or old preparation operations during the initial build without actually having re-prepared the target after the file change. Make the test wait until it receives expected diagnostics after the file change.
2024-05-17 13:23:01 -07:00
Kim de Vos
b30f59502e Add folding operator for IfConfigClauseSyntax 2024-05-17 13:32:05 +02:00
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
c58fa70011 Don’t re-index all files that include a header when a header is modified
When a header is modified, we don’t we want to re-index all main files that include it. Instead, we just want to index one main to effectively re-index the header itself.

I originally implemented re-indexing of all files that include the header but on second thought, headers are like Swift modules, where we also don’t re-index all dependencies either. And if you change a low-level header that’s included by the entire project, you probably don’t want the indexer to go off and re-index the entire project.
2024-05-15 20:10:07 -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
227012801c Make SourceKitLSPTests build in Swift 6 mode 2024-05-14 15:04: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
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
1fb087fb55 Merge pull request #1292 from ahoppen/sourcekitlsp-in-swift-6-mode
Make the `SourceKitLSP` module build in Swift 6 mode
2024-05-14 06:15:16 -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
61a21347da Index clang files
Fixes #1253
rdar://127474135
2024-05-13 17:51:15 -07:00
Alex Hoppen
13176b012d Address review comments 2024-05-10 14:43:32 -07:00
Alex Hoppen
5e83d7d904 Support background preparation of targets 2024-05-10 11:58:04 -07: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
Alex Hoppen
d4dd57861c Introduce a notion of ConfiguredTargets into the build system
Instead of asking for build settings of a file, the build system manager asks for the targets of a file and then asks for the build settings of that file in a specific target. This has two advantages:
- We know about targets and can prepare the targets for background indexing
- Once we support build systems in which a single file can be part of multiple targets, we can have a centralized place that picks preferred targets for a file, eg. based on user configuration
2024-05-08 16:02:11 -07: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
a6f85d88b5 Add test cases that check code actions invoked from a range 2024-05-08 14:56:09 -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
efba8ce9bc Merge pull request #1216 from ahoppen/background-indexing
Implement initial background indexing of a project
2024-05-08 10:35:18 -07:00
Alex Hoppen
fb30a2fb36 Merge pull request #1232 from ahoppen/package-swift-handled
Return `fileHandlingCapability.handled` for all files that `SwiftPMBuildSystem` has build settings for
2024-05-08 10:16:57 -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
Paul LeMarquand
d8d6cd1e0f Test case for multiple extensions with no type declaration 2024-05-07 13:55:58 -04: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
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
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
Alex Hoppen
f3f8860d7a Return fileHandlingCapability.handled for all files that SwiftPMBuildSystem has build settings for
Previously, `SwiftPMBuildSystem` would report `.unhandled` as the file handling capability for `Package.swift`. In single workspace-folder setups, this was not an issue because we would always default to using the build system of the first/only workspace folder, which was the only `SwiftPMBuildSystem` and then returned compiler arguments despite saying that it couldn’t handle `Package.swift`.

This, however, breaks if you have a setup with multi workspace folders, where we can’t rely on the first workspace folder being able to provide build settings for the package manifest.

To fix this, report `.handled` file handling capability for all files that `SwiftPMBuildSystem` can compute build settings for.

Fixes #1210
rdar://127351614
2024-05-06 18:30:37 -07:00
Doug Gregor
d4bbf9ccc1 Address review comments 2024-05-06 17:57:07 -07:00