Commit Graph

1555 Commits

Author SHA1 Message Date
Alex Hoppen
00aebd6659 Don’t cancel build when closing a document
In SourceKit-LSP, we can get into the following situation:
1. We open A.swift
2. We issue a request for A.swift, the request takes a while to execute
3. The dependencies of A.swift are updated, which causes us to reopen the document in sourcekitd, so that the AST is rebuilt
4. This shouldn’t cause the request from (2) to be cancelled. We should continue executing it and only re-open the document after the request from (2) has finished

rdar://127475366
2024-05-23 13:59:39 -07:00
Alex Hoppen
c5e29b19fa Don’t load the syntax map etc when re-opening a file 2024-05-23 13:54:49 -07:00
Alex Hoppen
76da45444f Re-generate sourcekitd UIDs 2024-05-23 13:41:40 -07:00
Alex Hoppen
ed5655a5ac Merge pull request #1328 from ahoppen/parallel-indexing 2024-05-22 22:53:26 -07:00
Alex Hoppen
69a584c80e Merge pull request #1334 from ahoppen/respect-failed-work-done-progress-creation
Respect failed work done progress creation
2024-05-22 15:35:55 -07:00
Alex Hoppen
bc1cd2cb71 Merge pull request #1332 from ahoppen/review-comments-1322-1326
Address review comments to #1322 and #1326
2024-05-22 15:35:02 -07:00
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
927056b7e9 Merge pull request #1327 from ahoppen/signposts
Add signposts for background preparation and indexing
2024-05-22 13:30:13 -07:00
Alex Hoppen
60864fe864 Respect failed work done progress creation
When the client replies with an error to the `CreateWorkDoneProgressRequest`, we shouldn’t be sending updates for it.
2024-05-22 10:55:57 -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
8f8ff454d7 Address review comments to #1326 2024-05-22 09:14:31 -07:00
Alex Hoppen
04d8c6be9a Address review comments to #1322 2024-05-22 08:52:26 -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
da96d45443 Add a development subcommand to index a project
This allows us to run `sourcekit-lsp index --project /path/to/project` to index a project. Intended to debugging purposes, eg.
- Profile the time it takes to index a project
- See if the project can be indexed successfully
- Look at signposts generated during indexing in Instruments to see whether indexing or preparation is the bottleneck and how well we can parallelize tasks.
2024-05-21 22:29:52 -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
44acd0d550 Merge pull request #1325 from ahoppen/fix-topological-sorting
Fix issue that caused topological order to be incorrect
2024-05-21 22:03:41 -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
ce34ec25a3 Fix issue that caused topological order to be incorrect 2024-05-21 18:05:11 -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
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
0da052757e Merge pull request #1314 from ahoppen/command-line-sanitization
Generalize the removal of compiler argument options during indexing
2024-05-20 13:40:44 -07:00
Alex Hoppen
815fea827e Add infrastructure to test which targets are being prepared 2024-05-20 09:49:24 -07:00
Alex Hoppen
5e8197c5cf Merge pull request #1316 from ahoppen/review-comments-1302
Address review comments to #1302
2024-05-20 09:45:52 -07:00
Alex Hoppen
fcc527f23b Merge pull request #1318 from ahoppen/log-in-localconnection
Move `LocalConnection` to `LSPTestSupport`
2024-05-20 09:45:37 -07:00
Alex Hoppen
79d50f33c8 Merge pull request #1319 from ahoppen/remove-taskscheduler-logging
Remove status logging from `TaskScheduler`
2024-05-20 09:44: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
2d27d57b66 Extract indexTaskDidFinish in SourceKitLSPServer.Options into a TestHooks struct 2024-05-17 16:30:47 -07:00
Alex Hoppen
c01c6763c8 Extract tuple from SemanticIndexManager.preparationStatus into a struct 2024-05-17 15:56:05 -07:00
Alex Hoppen
6a132ad7d9 Remove status logging from TaskScheduler
The logging from `TaskScheduler` was really verbose (and somewhat useful during its development) but it turns out that it’s just noise in real-world debugging. So, let’s remove it.
2024-05-17 15:37:26 -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
fb0801aaac Merge pull request #1311 from ahoppen/review-comments-1307
Don't re-prepare a target if there is already a smaller preparation task for it scheduled
2024-05-17 15:28:00 -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
5a7ab33c4b Merge pull request #1310 from ahoppen/review-comments-1249
Address review comments to #1249
2024-05-17 14:36:09 -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
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
56640c19c5 Address review comments to #1302 2024-05-17 13:27:51 -07:00
Alex Hoppen
195d3af74e Move LocalConnection to LSPTestSupport
We weren’t logging requests sent to a `TestSourceKitLSPClient` because we were assuming that `JSONRPCConnection` logs those requests in `SourceKitLSPServer`. But no logging happens in `LocalConnection`, which `TestSourceKitLSPClient` uses.

Since `LangaugeServerProtcol` can’t depend on `LSPLogging`, move the type to `LSPTestsSupport`.
2024-05-17 11:59:40 -07:00
Alex Hoppen
372673f3c2 Address review comments to #1249 2024-05-17 06:23:08 -07:00
Kim de Vos
b30f59502e Add folding operator for IfConfigClauseSyntax 2024-05-17 13:32:05 +02:00
Alex Hoppen
c1073a4158 Don't re-prepare a target if there is already a smaller preparation task for it scheduled 2024-05-16 15:52:40 -07:00
Alex Hoppen
0600809a71 Address review comments to #1306 2024-05-16 14:56:33 -07: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
61b772094e Track which targets are up-to-date and avoid preparation of targets that are known to be up-to-date
Fixes #1258
rdar://127475948
2024-05-16 10:08:26 -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