Skip to content

When the build system sends an update for build targets, update the index for the files in those targets #2013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Feb 27, 2025

For each file in the changed targets, we still check whether it has an up-to-date unit based on timestamps. The important thing for this change is that we start indexing files for which we only receive build settings after an update from the build server.

While doing this, I found a couple ways in which we could clean up/improve SemanticIndexManager. These changes should be reviewable commit-by-commit.

@ahoppen
Copy link
Member Author

ahoppen commented Feb 27, 2025

@swift-ci Please test

@ahoppen ahoppen force-pushed the clean-background-index-up-to-date-checks branch from e1c84fe to d090fb0 Compare February 27, 2025 20:00
@ahoppen
Copy link
Member Author

ahoppen commented Feb 27, 2025

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 27, 2025

@swift-ci Please test Windows

ahoppen added 4 commits March 1, 2025 09:24
We had checks for whether we need to index a file or if it is up-to-date in multiple places of `SemanticIndexManager`. Centralize them in `filesToCover(toIndex:)`, so that it’s easier to reason about them.
Indexing a header via a main file and indexing the main file itself are two different index tasks that update the `indexStoreUpToDateTracker` in different ways. We should thus consider them differently in `inProgressIndexTasks` as well.
…ndex for the files in those targets

For each file in the changed targets, we still check whether it has an up-to-date unit based on timestamps. The important thing for this change is that we start indexing files for which we only receive build settings after an update from the build server.
@ahoppen ahoppen force-pushed the clean-background-index-up-to-date-checks branch from d090fb0 to e5ede0f Compare March 3, 2025 16:41
…nce an in-progress index was requested

This fixes the following problem, which caused files to get indexed twice: You open a workspace, which schedules initial indexing. While we are waiting for the build graph generation from the build server, the build servers sends `buildTarget/didChange` notification to SourceKit-LSP (eg. because it has finished loading the build graph). This causes all files in the changed targets to be scheduled for re-indexing since new files might be present in the updated targets. And since we have already started indexing of those files, we assumed that we need to index them again because the contents might have changed.

To fix this, keep track of the file’s modification time at the time at which we scheduled indexing for it. If that time hasn’t changed and we have an in-progress indexing operation for it, there is no need to schedule another one.
@ahoppen ahoppen force-pushed the clean-background-index-up-to-date-checks branch from e5ede0f to 15c34bf Compare March 3, 2025 21:10
@ahoppen
Copy link
Member Author

ahoppen commented Mar 3, 2025

@swift-ci Please test

.mainFilesContainingFile(uri: uri, crossLanguage: false)
.sorted(by: { $0.stringValue < $1.stringValue }).first
guard let mainFile else {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we log in this case (ie. we have a file that isn't known to the project)? Or did you do that and it is that too spammy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

private func filesToIndex(
toCover files: some Collection<DocumentURI> & Sendable
toCover files: some Collection<DocumentURI> & Sendable,
indexFilesWithUpToDateUnits: Bool
) async -> [FileToIndex] {
let sourceFiles = await orLog("Getting source files in project") {
Set(try await buildSystemManager.sourceFiles(includeNonBuildableFiles: false).keys)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was here before, but this could be fairly large depending on the project - probably not great to reconstruct the set every time this is called.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Caching the set now.

@ahoppen
Copy link
Member Author

ahoppen commented Mar 3, 2025

@swift-ci Please test

This way we don’t need to rebuild the set every time we call `filesToIndex(toCover:)`.
@ahoppen ahoppen force-pushed the clean-background-index-up-to-date-checks branch from d37a1e0 to fe750f6 Compare March 3, 2025 21:58
@ahoppen
Copy link
Member Author

ahoppen commented Mar 3, 2025

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 3, 2025

@swift-ci Please test Windows

@ahoppen ahoppen merged commit bafd8ba into swiftlang:main Mar 4, 2025
3 checks passed
@ahoppen ahoppen deleted the clean-background-index-up-to-date-checks branch March 4, 2025 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants