-
Notifications
You must be signed in to change notification settings - Fork 314
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
When the build system sends an update for build targets, update the index for the files in those targets #2013
Conversation
@swift-ci Please test |
e1c84fe
to
d090fb0
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
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.
d090fb0
to
e5ede0f
Compare
…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.
e5ede0f
to
15c34bf
Compare
@swift-ci Please test |
.mainFilesContainingFile(uri: uri, crossLanguage: false) | ||
.sorted(by: { $0.stringValue < $1.stringValue }).first | ||
guard let mainFile else { | ||
return nil |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@swift-ci Please test |
This way we don’t need to rebuild the set every time we call `filesToIndex(toCover:)`.
d37a1e0
to
fe750f6
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
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.