Skip to content

Instantly share code, notes, and snippets.

@dkandalov
Last active January 15, 2025 11:51
Show Gist options
  • Select an option

  • Save dkandalov/11051113 to your computer and use it in GitHub Desktop.

Select an option

Save dkandalov/11051113 to your computer and use it in GitHub Desktop.
Simplistic "compile and run haskell" IntelliJ action (see https://github.com/dkandalov/live-plugin)
import com.intellij.notification.*
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.progress.PerformInBackgroundOption
import static liveplugin.PluginUtil.*
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.fileEditor.FileDocumentManager
if (isIdeStartup) return
registerAction("compile-c", "alt C, alt R", { AnActionEvent event ->
def project = event.project
VirtualFile file = currentFileIn(project)
def docManager = FileDocumentManager.instance
def document = docManager.getDocument(file)
if (document != null) docManager.saveDocument(document)
if (file.extension != "hs") return
doInBackground("Compiling", false, PerformInBackgroundOption.ALWAYS_BACKGROUND, {
try {
def command = "ghc --make ${file.path}"
def result = execute(command)
def output = "> " + command + "\n" + result.stdout + "\n------\n" + result.stderr
if (result.exitCode == 0) {
command = file.parent.path + "/" + file.nameWithoutExtension
result = execute(command)
output += "> " + command + "\n" + result.stdout + "\n------\n" + result.stderr
}
showInConsole(output, project)
} catch (Exception e) {
showInConsole(e, project)
}
})
})
show("Loaded execute command action")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment