KTIJ-35157 Scripts: importScripts doesn't import files - fix#3464
KTIJ-35157 Scripts: importScripts doesn't import files - fix#3464imeszaros wants to merge 3 commits intoJetBrains:masterfrom
Conversation
Implemented imported script resolution in DefaultKotlinScriptEntityProvider, and added a new implementation of K2IdeScriptAdditionalIdeaDependenciesProvider.
Fixed an issue that could cause resolution to fail for a script that imports another script and the script configuration for the imported script was reloaded at least once previously.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
...org/jetbrains/kotlin/idea/core/script/k2/configurations/DefaultKotlinScriptEntityProvider.kt
Show resolved
Hide resolved
| return getRelatedModules(file, project).flatMap { | ||
| index.findEntitiesByUrl(it.toVirtualFileUrl(manager)) | ||
| }.filterIsInstance<KotlinScriptEntity>().flatMap { it.dependencies.mapNotNull { currentSnapshot.resolve(it) } } | ||
| } |
There was a problem hiding this comment.
Duplicated getRelatedLibraries implementation across providers
Low Severity
The getRelatedLibraries implementation in DefaultKotlinScriptDependenciesProvider is character-for-character identical to MainKtsScriptDependenciesProvider. The two classes differ only in which entity provider getRelatedModules delegates to. This duplicated logic increases maintenance burden and risks inconsistent bug fixes if one copy is updated without the other.
Avoid potential endless loop in case of import cycle.
|
You have used all of your free Bugbot PR reviews. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |


My attempt to fix the issue of the corresponding ticket: https://youtrack.jetbrains.com/issue/KTIJ-35157
I worked based on the information shared in the ticket and used the MainKts classes as an example.
This is my very first contribution to the project, so I'm of course not entirely sure I did the right thing everywhere, but these changes fix the issue for me.
Additionally, I fixed another issue I discovered that could cause resolution to fail for a script that imports another script and the script configuration for the imported script was reloaded at least once previously. This fix is in a separate commit.
Note
Medium Risk
Touches script dependency resolution and Workspace Model updates; mistakes could cause missed or repeated script resolution and incorrect library/module dependency propagation.
Overview
Fixes K2 scripting so standard
.ktsimportScriptsare tracked and trigger resolution of the imported scripts (mirroring the MainKts behavior), including cleanup of the import graph when a script entity is removed.Registers a new
k2IdeScriptAdditionalIdeaDependenciesProviderfor default scripts and addsDefaultKotlinScriptDependenciesProviderto surface related imported scripts and their libraries via the Workspace Model. Also deduplicates shared logic by movingimportedScriptsextraction and theVirtualFilecomparator intoKotlinScriptEntityProviderand adjusting MainKts resolution to avoid re-processing already-known scripts.Written by Cursor Bugbot for commit 5b07062. This will update automatically on new commits. Configure here.