Last active
January 15, 2025 11:51
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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