Skip to content

Commit

Permalink
check invalid file before compile in annotator / change log (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed Nov 6, 2021
1 parent ea7dec6 commit e78bceb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/com/reason/ide/annotations/BsErrorAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ private BsErrorAnnotator() {
File cmtFile;
List<OutputInfo> 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));
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 11 additions & 6 deletions src/com/reason/ide/annotations/ResErrorAnnotator.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -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.*;
Expand Down Expand Up @@ -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<OutputInfo> info = compile((ResResolvedCompiler) initialInfo.compiler, arguments, initialInfo.libRoot);

if (LOG.isTraceEnabled()) {
Expand All @@ -94,14 +99,14 @@ private ResErrorAnnotator() {
return new AnnotationResult(info, initialInfo.editor, cmtFile);
}

@NotNull static List<OutputInfo> compile(@NotNull ResResolvedCompiler compiler, @NotNull List<String> arguments, @NotNull VirtualFile workDir) {
static @NotNull List<OutputInfo> compile(@NotNull ResResolvedCompiler compiler, @NotNull List<String> arguments, @NotNull VirtualFile workDir) {
List<String> 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;
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/com/reason/ide/console/ORToolWindowManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
});
Expand Down

0 comments on commit e78bceb

Please sign in to comment.