Commit Graph

695 Commits

Author SHA1 Message Date
Alex Hoppen
ecacd7ba2c Show work done progress while a source file is being prepared for editor functionality
While `SemanticIndexManager.inProgressPrepareForEditorTask` is not `nil`, show a work done progress in the editor that the current file is being prepared for editor functionality.

I decided to use the indexing progress indicator for this for now because I think it’s too spammy if SourceKit-LSP has two different progress indicators for preparation and indexing. I’ll need to see how this feels like in practice.

rdar://128722609
2024-05-25 10:40:35 -07:00
Alex Hoppen
84007caf6e Merge pull request #1343 from ahoppen/generating-build-graph-logging 2024-05-24 22:09:40 -07:00
Alex Hoppen
069e8a2ca4 Call indexProgressManager.indexStatusDidChange when workspaces in the SourceKitLSPServer are modified
`IndexProgressManager` iterates over all workspaces in the SourceKitLSPServer. Modifying workspaces might thus update the index progress status.
2024-05-24 17:31:00 -07:00
Alex Hoppen
2b04ad6c32 Merge pull request #1347 from ahoppen/cancel-builds-0-on-close
Set `cancelBuilds` to 0 on close instead of open
2024-05-24 17:15:22 -07:00
Alex Hoppen
1ea20eb28f Show a work done progress while the semantic index is rebuilding a build graph
Rebuilding the build graph can take a while (initial loading of the build graph takes ~7s for sourcekit-lsp) and it’s good to show some progress during this time.
2024-05-24 11:23:15 -07:00
Alex Hoppen
31a8cf333f Merge pull request #1345 from ahoppen/reset-workdoneprogress-state
Reset the state of `WorkDoneProgressState` when the progress has ended
2024-05-24 11:01:52 -07:00
Alex Hoppen
cdc4f2b732 Set cancelBuilds to 0 on close instead of open 2024-05-24 10:10:53 -07:00
Alex Hoppen
88de421495 Reset the state of WorkDoneProgressState when the progress has ended
Otherwise, we will never show the progress again.
2024-05-24 07:34:46 -07:00
Alex Hoppen
7cf9f15d85 Merge pull request #1340 from ahoppen/watch-for-source-file-changes
Watch for changes to source files
2024-05-23 23:16:30 -07:00
Alex Hoppen
5fffb0a4c9 Watch for changes to source files
We used to only watch for file creation and deletion because that might modify build settings but for background indexing, we also need to watch for changes to the files, so we can invalidate the up-to-date status of the target.
2024-05-23 14:03:33 -07:00
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
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
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
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
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
fcc527f23b Merge pull request #1318 from ahoppen/log-in-localconnection
Move `LocalConnection` to `LSPTestSupport`
2024-05-20 09:45:37 -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
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
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
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
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
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