Skip to content

Commit

Permalink
fix(#31): Only include stdout for json parsing
Browse files Browse the repository at this point in the history
Closes #31
  • Loading branch information
timo-reymann committed Jun 25, 2021
1 parent 443fd48 commit 5c306a3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.process.OSProcessHandler
import com.intellij.execution.process.ProcessAdapter
import com.intellij.execution.process.ProcessEvent
import com.intellij.execution.process.ProcessOutputType
import com.intellij.execution.process.ProcessOutputType.*
import com.intellij.javascript.nodejs.interpreter.NodeCommandLineConfigurator
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterRef
import com.intellij.notification.Notification
Expand All @@ -18,6 +20,7 @@ import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.jetbrains.rd.util.error
import com.jetbrains.rd.util.getLogger
import com.jetbrains.rd.util.warn
import de.timo_reymann.mjml_support.bundle.MjmlBundle
import de.timo_reymann.mjml_support.editor.renderError
import de.timo_reymann.mjml_support.settings.MjmlSettings
Expand Down Expand Up @@ -58,16 +61,15 @@ class MjmlRenderer(
}

private fun captureOutput(commandLine: GeneralCommandLine): Pair<Int, String> {
val line = AtomicInteger(0)
val processHandler = OSProcessHandler(commandLine)
val buffer = StringBuffer()
processHandler.addProcessListener(object : ProcessAdapter() {
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
// First line is command output, remove it
if (line.incrementAndGet() == 1) {
return
when (outputType) {
STDOUT -> buffer.append(event.text)
// stderr may contain duplicates from errors (due to hard coded console.error in mjml code)
STDERR -> getLogger<MjmlRenderer>().warn { event.text }
}
buffer.append(event.text)
}
})

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
]]></description>
<change-notes><![CDATA[
<ul>
<li>TBD
<li>1.15.1
<ul>
<li>Fix mj-include inspection inside xml (related to <a href="https://github.com/timo-reymann/intellij-mjml-support/issues/23">#23</a>)</li>
<li>Fix plugin crash on unknown/invalid tags (<a href="https://github.com/timo-reymann/intellij-mjml-support/issues/31">#31</a>)</li>
</ul>
</li>
<li>1.15.0
Expand Down

0 comments on commit 5c306a3

Please sign in to comment.