Skip to content

Commit

Permalink
feat(marketplace): replace LightVirtualFile with ScratchRootType for …
Browse files Browse the repository at this point in the history
…temp files #165

Use ScratchRootType to create temporary scratch files instead of LightVirtualFile, improving file handling and integration with the IDE.
  • Loading branch information
phodal committed Dec 19, 2024
1 parent e08c831 commit 11c1082
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ open class ShireRunConfigurationProfileState(

console!!.attachToProcess(processHandler)

var shireFile: ShireFile? = ShireFile.lookup(myProject, configuration.getScriptPath())
if (shireFile == null) {
shireFile = tryLoadFromDataContext()
}

val shireFile: ShireFile? = ShireFile.lookup(myProject, configuration.getScriptPath())
if (shireFile == null) {
console!!.print("File not found: ${configuration.getScriptPath()}", ConsoleViewContentType.ERROR_OUTPUT)
processHandler.exitWithError()
Expand Down Expand Up @@ -118,15 +114,6 @@ open class ShireRunConfigurationProfileState(
return DefaultExecutionResult(console, processHandler)
}

private fun tryLoadFromDataContext(): ShireFile? {
val dataContext = DataManager.getInstance().dataContextFromFocusAsync.blockingGet(10000)
?: throw IllegalStateException("No data context found")

val data = SimpleDataContext.getProjectContext(myProject).getData(SHIRE_VIRTUAL_KEY)

return dataContext.getData(SHIRE_VIRTUAL_KEY) ?: data
}

override fun dispose() {
console?.dispose()
executionConsole?.dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ class ShireFileRunService : FileRunService {

val shireConfiguration = setting.configuration as ShireConfiguration
shireConfiguration.name = virtualFile.nameWithoutExtension

if (virtualFile is LightVirtualFile) {
val dataContext = SimpleDataContext.builder()
.add<ShireFile>(ShireRunConfigurationProfileState.SHIRE_VIRTUAL_KEY, psiFile).build()

}

shireConfiguration.setScriptPath(virtualFile.path)

runManager.setTemporaryConfiguration(setting)
Expand Down
15 changes: 13 additions & 2 deletions src/main/kotlin/com/phodal/shire/marketplace/ui/MarketplaceView.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.phodal.shire.marketplace.ui

import com.intellij.ide.scratch.ScratchRootType
import com.intellij.lang.Language
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
Expand Down Expand Up @@ -42,8 +44,17 @@ class MarketplaceView(val project: Project) : Disposable {
return
}

val file = LightVirtualFile("temp.shire", prompt)
FileRunService.provider(project, file)?.runFile(project, file, null)
val createScratchFile = ScratchRootType.getInstance().createScratchFile(
project,
"shire-temp.shire",
Language.findLanguageByID("Shire"),
prompt
)

val file = createScratchFile!!
val result = FileRunService.provider(project, file)?.runFile(project, file, null)
// delete scracth file?
println(result)
}
})
val borderPanel = JPanel(BorderLayout())
Expand Down

0 comments on commit 11c1082

Please sign in to comment.