From e78bceb220bddd2099d527127b171669893954f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Giraud?= Date: Sat, 6 Nov 2021 10:38:47 +0100 Subject: [PATCH] check invalid file before compile in annotator / change log (#362) --- .../ide/annotations/BsErrorAnnotator.java | 11 +++++++++-- .../ide/annotations/ResErrorAnnotator.java | 17 +++++++++++------ .../reason/ide/console/ORToolWindowManager.java | 1 + 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/com/reason/ide/annotations/BsErrorAnnotator.java b/src/com/reason/ide/annotations/BsErrorAnnotator.java index 67f99d24a..632800a50 100644 --- a/src/com/reason/ide/annotations/BsErrorAnnotator.java +++ b/src/com/reason/ide/annotations/BsErrorAnnotator.java @@ -111,6 +111,13 @@ private BsErrorAnnotator() { File cmtFile; List info; + // https://github.com/giraud/reasonml-idea-plugin/issues/362 + // lib directory can be invalidated after a clean + if (!initialInfo.libRoot.isValid()) { + LOG.debug("lib directory is invalid, skip compilation"); + return null; + } + if (initialInfo.oldFormat) { assert initialInfo.tempFile != null; File baseFile = new File(initialInfo.tempFile.getParent(), FileUtil.getNameWithoutExtension(initialInfo.tempFile)); @@ -210,8 +217,8 @@ private BsErrorAnnotator() { } return processListener.getOutputInfo(); - } catch (IOException e) { - ORNotification.notifyError("Bucklescript", "Execution exception", e.getMessage(), null); + } catch (Exception e) { + LOG.info("Execution error", e); } finally { if (process != null) { process.destroyForcibly(); diff --git a/src/com/reason/ide/annotations/ResErrorAnnotator.java b/src/com/reason/ide/annotations/ResErrorAnnotator.java index 12239dba5..65323147a 100644 --- a/src/com/reason/ide/annotations/ResErrorAnnotator.java +++ b/src/com/reason/ide/annotations/ResErrorAnnotator.java @@ -1,6 +1,5 @@ package com.reason.ide.annotations; -import com.intellij.execution.*; import com.intellij.execution.process.*; import com.intellij.openapi.editor.*; import com.intellij.openapi.project.*; @@ -11,7 +10,6 @@ import com.reason.comp.bs.*; import com.reason.comp.rescript.*; import jpsplugin.com.reason.*; -import org.apache.tools.ant.taskdefs.*; import org.jetbrains.annotations.*; import java.io.*; @@ -75,6 +73,13 @@ private ResErrorAnnotator() { long compilationStartTime = System.currentTimeMillis(); + // https://github.com/giraud/reasonml-idea-plugin/issues/362 + // lib directory can be invalidated after a clean + if (!initialInfo.libRoot.isValid()) { + LOG.debug("lib directory is invalid, skip compilation"); + return null; + } + List info = compile((ResResolvedCompiler) initialInfo.compiler, arguments, initialInfo.libRoot); if (LOG.isTraceEnabled()) { @@ -94,14 +99,14 @@ private ResErrorAnnotator() { return new AnnotationResult(info, initialInfo.editor, cmtFile); } - @NotNull static List compile(@NotNull ResResolvedCompiler compiler, @NotNull List arguments, @NotNull VirtualFile workDir) { + static @NotNull List compile(@NotNull ResResolvedCompiler compiler, @NotNull List arguments, @NotNull VirtualFile workDir) { List command = new ArrayList<>(); command.add(compiler.getPath()); command.addAll(arguments.stream().filter(s -> !"-bin-annot".equals(s)).collect(Collectors.toList())); if (LOG.isTraceEnabled()) { LOG.trace(Joiner.join(" ", command.toArray(new String[0]))); - LOG.trace(" work dir", workDir); + LOG.trace(" work dir" + (workDir.isValid() ? " [valid]" : " [not valid]"), workDir); } Process process = null; @@ -120,8 +125,8 @@ private ResErrorAnnotator() { } } return processListener.getOutputInfo(); - } catch (IOException e) { - ORNotification.notifyError("Rescript", "Execution exception", e.getMessage(), null); + } catch (Exception e) { + LOG.info("Execution error", e); } finally { if (process != null) { process.destroy(); diff --git a/src/com/reason/ide/console/ORToolWindowManager.java b/src/com/reason/ide/console/ORToolWindowManager.java index 1b952182b..d28a7c5bf 100644 --- a/src/com/reason/ide/console/ORToolWindowManager.java +++ b/src/com/reason/ide/console/ORToolWindowManager.java @@ -51,6 +51,7 @@ private void setToolWindowAvailable(@NotNull String id, @Nullable Compiler compi ReadAction.nonBlocking(() -> compiler.getFullVersion(null)) // slow operation not allowed on UI thread .finishOnUiThread(ModalityState.defaultModalityState(), version -> consoleView.print("Detected compiler: " + version + "\n", ConsoleViewContentType.NORMAL_OUTPUT)) + .coalesceBy(compiler) .submit(AppExecutorUtil.getAppExecutorService()); } });