Commit Graph

27 Commits

Author SHA1 Message Date
Alex Hoppen
950a74a260 Fix a negation issue that prevented parallel indexing 2024-05-22 13:31:58 -07:00
Alex Hoppen
82637937f6 Add signposts for background preparation and indexing
This allows nice visualization of the indexing progress in Instruments.
2024-05-22 06:46:06 -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
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
3f9ff29ee3 Merge pull request #1309 from ahoppen/review-comments-1306
Address review comments to #1306
2024-05-20 13:40:58 -07:00
Alex Hoppen
815fea827e Add infrastructure to test which targets are being prepared 2024-05-20 09:49:24 -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
6695859c4b Improve handling of main file vs header file during indexing
Essentially fix two issues in updating the index store:
1. If there was one task to index `HeaderA.h` through `main.c` and one to index `HeaderB.h` through `main.c`, we would not declare a dependency between them in the task scheduler, which meant that we could have two concurrent and racing index tasks for `main.c`. Declare a dependency between any two files that have the same main file
2. `UpdateIndexStoreTaskDescription` was computing the target to index a file in independently of `SemanticIndexManager`. While they currently always line up, we should pass the target in which to index a file to the `UpdateIndexStoreTaskDescription`. Only this way can we guarantee that we actually prepared the target that the file will be indexed in.
2024-05-17 15:28:42 -07:00
Alex Hoppen
5bad2c540f Generalize the removal of compiler argument options during indexing
The existing ad-hoc logic was not quite correct because it didn’t eg. remove `-MT/depfile` because it assumed that `-MT` was followed by a space. It also didn’t take into account that `serialize-diagnostics` can be spelled with a single dash or two dashes.

Create a `CompilerCommandLineOption` type that forces decisions to be made about the dash spelling and argument styles, which should help avoid problems like this in the future.
2024-05-17 14:16: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
597932c0b7 Merge pull request #1303 from ahoppen/review-comments-1216
Address review comment to #1216
2024-05-15 15:46:58 -07:00
Alex Hoppen
f10eac3ace Address review comment to #1216 2024-05-15 12:36:27 -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
c9b51f9b34 Allow client request handlers specified on TestSourceKitLSPClient to be executed in any order 2024-05-14 06:38:22 -07:00
Alex Hoppen
0dc5cdd7c7 Call indexTaskDidFinish from SemanticIndexManager
This fixes a bug where `indexTaskDidFinish` would also get called when a task is cancelled to be rescheduled.
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
0f097e61f0 Merge pull request #1289 from ahoppen/index-c-files
Index clang files
2024-05-14 06:14:00 -07:00
Alex Hoppen
61a21347da Index clang files
Fixes #1253
rdar://127474135
2024-05-13 17:51:15 -07:00
Alex Hoppen
70e373c1fa Make all non-test modules except for SourceKitLSP build in Swift 6 mode
This would have caught a race condition in background indexing that was caused by accessing `CheckedIndex` from multiple threads despite it not being thread-safe.
2024-05-13 10:05:25 -07:00
Alex Hoppen
5e83d7d904 Support background preparation of targets 2024-05-10 11:58:04 -07:00
Alex Hoppen
7b4bbeb39d Address review comments to #1216 2024-05-09 15:19:31 -07:00
Alex Hoppen
a1d10d8bed Fall back to launching subprocesses without a working directory
Details from https://github.com/apple/sourcekit-lsp/issues/1271

> Amazon Linux 2 and CentOS 7 have a glibc that doesn’t support `posix_spawn_file_actions_addchdir_np` and thus `TSCBasic.Process` can’t launch a process on these platforms with the working directory set. We currently fall back to launching the index tasks without a working directory on these platforms, which I think is fine because SwiftPM gives us compiler arguments with absolute paths. But we should figure something out.
>
> Using `Foundation.Process` is not an option because it runs `chdir` on the current process for Posix platforms, which is racy if there are multiple subprocesses being spawned simultaneously. On Windows `TSCBasic.Processs` uses `Foundation.Process` and `Foundation.Process` properly set the working directory of the subprocesses on Windows, so Windows is not a problem.

rdar://127797048
2024-05-09 10:26:23 -07:00
Alex Hoppen
0ae3d80c5c Fix Windows build failure
Windows has `ProcessResult.ExitStatus.abnormal` instead of ` `ProcessResult.ExitStatus.signalled`
2024-05-05 14:53:42 -07:00
Alex Hoppen
a6a76c66cc Conjure up an output file path so that indexing of two files produces different unit files 2024-05-05 14:26:52 -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