wasyl
07/04/2024, 12:15 PMshow results in generated code
unchecked. I have similar issue with other generated code like classes from Apollo-Kotlin plugin. I see https://youtrack.jetbrains.com/issue/KT-45161/Gradle-Support-registering-generated-sources-with-the-Kotlin-model, but is there a reliable way to workaround this and mark the sources as generated easily?christophsturm
07/04/2024, 12:21 PMplugins {
idea
}
idea {
module {
generatedSourceDirs.add(File(layout.buildDirectory.get().asFile, "generated-sources/kotlin-dsl-accessors/kotlin"))
generatedSourceDirs.add(File(layout.buildDirectory.get().asFile, "generated-sources/kotlin-dsl-plugins/kotlin"))
}
}
wasyl
07/04/2024, 12:23 PMidea
plugin, even if it would be something to configure in IDEwasyl
07/04/2024, 12:24 PMidea
plugin which would mean folks just always get generated code usage suggestions etc.? 😕mbonnin
07/04/2024, 12:31 PMwasyl
07/04/2024, 1:00 PMbod
07/04/2024, 1:06 PMbuild
folders ignored by default, like .git
is for instance? (In Settings | Editor | File Types | Ignored File Types and Folders)wasyl
07/04/2024, 1:14 PMbod
07/04/2024, 1:14 PMEmil Kantis
07/04/2024, 2:37 PMwasyl
07/04/2024, 2:37 PMimport com.intellij.openapi.extensions.LoadingOrder
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.GeneratedSourcesFilter
import com.intellij.openapi.vfs.VirtualFile
class MarkGeneratedDirectoriesPlugin : GeneratedSourcesFilter() {
override fun isGeneratedSource(file: VirtualFile, project: Project): Boolean {
val path = file.path
return path.contains("/build/generated/ksp/") || path.contains("/build/generated/source")
}
}
GeneratedSourcesFilter.EP_NAME.point.registerExtension(MarkGeneratedDirectoriesPlugin(), LoadingOrder.LAST, pluginDisposable)
loaded in https://github.com/dkandalov/live-plugin/. I don't know how to mark sources as generated once, but this seems to filter out the generated files from find usages
resultswasyl
07/04/2024, 2:37 PMAsked for the same a bit back..oh hey, I was there 😄
Emil Kantis
07/04/2024, 2:38 PMmbonnin
07/04/2024, 2:40 PMmbonnin
07/04/2024, 2:40 PMshow results in generated code
setting appliesmbonnin
07/04/2024, 2:40 PMmbonnin
07/04/2024, 2:41 PMwasyl
07/04/2024, 2:46 PMignore
the files, I don't see the paths I marked as generated when searching for usages, and I do see them again when I check show results in generated code
. The code calling to generated files is also green. This is all much better than the default behavior already.
I don't see entire directory marked as generated sources root, and I expect the plugin to be inefficient since I see the filter method called a lot. For now I'll observe if I can see performance impact and if yes, I'll look for a way to mark entire directories as generated (possibly overriding them being marked as sources
I guess?). But IntelliJ platform is new to me so I struggle to even know where to start 😄bod
07/04/2024, 2:47 PMwasyl
07/04/2024, 2:49 PMI think we still want the generated sources being marked as a “source root” (for navigation)?I don't think so, I mean generally if you select some directory under
build
you can mark it either as source root
or generated source root
. I think using source root
is precisely not great because it shows usages in those files even when show usages in generated sources
option is disabled. 90% of the time I don't care what generated sources do, and I'd even say that for search usages
action, generated code is never relevant — if there are no other usages, usually when I remove the class, the generated code disappears toowasyl
07/04/2024, 2:51 PMmbonnin
07/04/2024, 2:53 PMmbonnin
07/04/2024, 2:54 PMSourceDirectorySet
where I understand a “source root” as an item of SourceDirectorySet.srcDirs() but not sure what the actual definition for IDEA is.mbonnin
07/04/2024, 2:55 PMsrcDir()
removes the blue folder in IDEAmbonnin
07/04/2024, 2:56 PMsrcDir(directory, isGenerated)
wasyl
07/04/2024, 2:59 PMsrcDir()
right now is the only thing you can do but it has downsides. Overall the issue is disappointing since it used to work for Kapt iirc and having generated code marked as generated is such an important functionality. But yeah, currently KGP doesn't have a generated source directory
source set/metadata iiucbod
07/04/2024, 3:04 PMbod
07/04/2024, 3:05 PMwasyl
07/04/2024, 3:07 PMbod
07/04/2024, 3:08 PM