Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Populate FileIndexMap during sync instead of using the Gradle Tooling API directly #5708

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pablobaxter
Copy link

This resolves the issue where the FileIndexMap triggers a Gradle build configuration separate from the IDE sync. It gives a project resolver to the IDE to indicate that SqlDelightPropertiesFile can be queried during sync, and sets it as part of the internal IDE data structure for later retrieval.

It also resolves the issue where the SqlDelight plugin was creating multiple Gradle daemons.

Example of syncing with the plugin while viewing a .sq file.
Sync-test-ezgif com-video-to-gif-converter


As a side note, there is potential for improvement, as the IDE plugin can instead own the ToolingModelBuilder that lives in the Gradle plugin, although that would require much more work and discussions out of scope of this PR.

@joshfriend
Copy link
Contributor

I am pretty sure this closes #5628

@pablobaxter
Copy link
Author

There's something off with the PropertiesModelBuilder in the SqlDelightPlugin. The PropertiesModelBuilder takes in a collection of SqlDelightDatabase, however this is done for every project this plugin is applied to. It also seems to register the PropertiesModelBuilder on each project, potentially with a different collection of databases. So when the Gradle tooling queries for a model, it may not have the correct databases set for the specific project.

@hfhbd hfhbd self-requested a review March 22, 2025 08:52
@hfhbd
Copy link
Collaborator

hfhbd commented Mar 22, 2025

There's something off with the PropertiesModelBuilder in the SqlDelightPlugin. The PropertiesModelBuilder takes in a collection of SqlDelightDatabase, however this is done for every project this plugin is applied to. It also seems to register the PropertiesModelBuilder on each project, potentially with a different collection of databases. So when the Gradle tooling queries for a model, it may not have the correct databases set for the specific project.

AFAIK , the Gradle Tooling will be run for each Gradle project. So the IntelliJ sync should also be run isolated for each Gradle project.
But the IDEA plugin does not need any module dependencies at all, it just needs the sqldelight files from the other project.

I will rewrite the sqldelight Gradle plugin to support project isolation today and also will change the SqlDelightPropertiesFile. This file is currently used as Gradle task input and as Idea model, but that's problematic due the same reason you mention.

@pablobaxter
Copy link
Author

AFAIK , the Gradle Tooling will be run for each Gradle project

Yes, but the problem is with how the builder is registered. It's done so each time the plugin is applied, which can be multiple times, when it should only be registered once. The model builder provides the Project object in the buildAll() function to perform any project specific actions, such as grabbing the registered extensions.

it just needs the sqldelight files from the other project.

If this is the case, we may not even need the model builder at all. If we can add the sqldelight files as a source set via Gradle, that can be queried from the DataNode in the IDEA plugin after a sync is completed.

@hfhbd
Copy link
Collaborator

hfhbd commented Mar 22, 2025

If we can add the sqldelight files as a source set via Gradle, that can be queried from the DataNode in the IDEA plugin after a sync is completed.

Do you mean a Gradle SourceDirectorySet? That's the direction I want to rewrite the sqldelight Gradle plugin.

@pablobaxter
Copy link
Author

Do you mean a Gradle SourceDirectorySet? That's the direction I want to rewrite the sqldelight Gradle plugin.

Yep! I think that will expose the files to the IDEA plugin, which we can then query for. Just out of curiosity, is the only place to expect the sqldelight files in the directory sqldelight under the main or similar folder?

@hfhbd
Copy link
Collaborator

hfhbd commented Mar 24, 2025

Just out of curiosity, is the only place to expect the sqldelight files in the directory sqldelight under the main or similar folder?

Yes, commonMain or just main.

@pablobaxter
Copy link
Author

Yes, commonMain or just main.

If this is the case, we can get the path to this directory without adding it as a source to Gradle via the ContentRootData object in IntelliJ, which would contain the sources root path (which contains the src and resources directory). However, if this path can be changed, it'll need to be queried from Gradle via the Tooling API then.

@@ -8,163 +8,63 @@ import app.cash.sqldelight.dialect.api.SqlDelightDialect
import app.cash.sqldelight.intellij.FileIndex
import app.cash.sqldelight.intellij.SqlDelightFileIndexImpl
import app.cash.sqldelight.intellij.notifications.FileIndexingNotification
import app.cash.sqldelight.intellij.notifications.FileIndexingNotification.UnconfiguredReason.Syncing
import app.cash.sqldelight.intellij.resolvers.SQL_DELIGHT_MODEL_KEY
import com.android.tools.idea.gradle.project.sync.GradleSyncState
Copy link
Collaborator

Choose a reason for hiding this comment

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

this wont work for not android studio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants