Skip to content

KTIJ-35157 Scripts: importScripts doesn't import files - fix#3464

Open
imeszaros wants to merge 3 commits intoJetBrains:masterfrom
imeszaros:KTIJ-35157-Scripts-importScripts-doesn't-import-files
Open

KTIJ-35157 Scripts: importScripts doesn't import files - fix#3464
imeszaros wants to merge 3 commits intoJetBrains:masterfrom
imeszaros:KTIJ-35157-Scripts-importScripts-doesn't-import-files

Conversation

@imeszaros
Copy link
Copy Markdown

@imeszaros imeszaros commented Mar 19, 2026

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 .kts importScripts are 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 k2IdeScriptAdditionalIdeaDependenciesProvider for default scripts and adds DefaultKotlinScriptDependenciesProvider to surface related imported scripts and their libraries via the Workspace Model. Also deduplicates shared logic by moving importedScripts extraction and the VirtualFile comparator into KotlinScriptEntityProvider and 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.

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.
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

return getRelatedModules(file, project).flatMap {
index.findEntitiesByUrl(it.toVirtualFileUrl(manager))
}.filterIsInstance<KotlinScriptEntity>().flatMap { it.dependencies.mapNotNull { currentSnapshot.resolve(it) } }
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

Avoid potential endless loop in case of import cycle.
@cursor
Copy link
Copy Markdown

cursor bot commented Mar 19, 2026

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.

@BartvHelvert BartvHelvert added the Kotlin Pull requests for Kotlin IntelliJ plugin label Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Kotlin Pull requests for Kotlin IntelliJ plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants