From 3a217d1200254fb9180b9198e63c6534831168e8 Mon Sep 17 00:00:00 2001
From: SeeBasTStick <sebastian.stock@hhu.de>
Date: Tue, 11 Aug 2020 16:56:20 +0200
Subject: [PATCH] fixed bug where error from failing probcli (due to wrong
 path) was not shown

---
 .../kotlin/b/language/server/BDocumentService.kt   |  6 ++++++
 .../server/proBMangement/ProBCommandLineAccess.kt  | 14 +++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/main/kotlin/b/language/server/BDocumentService.kt b/src/main/kotlin/b/language/server/BDocumentService.kt
index a855090..490e7e1 100644
--- a/src/main/kotlin/b/language/server/BDocumentService.kt
+++ b/src/main/kotlin/b/language/server/BDocumentService.kt
@@ -7,6 +7,7 @@ import b.language.server.proBMangement.ProBCommandLineAccess
 import b.language.server.proBMangement.ProBInterface
 import org.eclipse.lsp4j.*
 import org.eclipse.lsp4j.services.TextDocumentService
+import java.io.IOException
 import java.util.concurrent.ConcurrentHashMap
 
 class BDocumentService(private val server: Server, private val communicator: CommunicatorInterface) : TextDocumentService {
@@ -64,8 +65,13 @@ class BDocumentService(private val server: Server, private val communicator: Com
                 communicator.sendDebugMessage("invalidating old files $invalidFiles", MessageType.Info)
                 issueTracker[currentUri] = filesWithProblems.toSet()
             }catch (e : PathCouldNotBeCreatedException ){
+                communicator.sendDebugMessage("error path could not be created", MessageType.Info)
                 communicator.showMessage(e.message!!, MessageType.Error)
             }catch (e : CommandCouldNotBeExecutedException){
+                communicator.sendDebugMessage("command could not be executed", MessageType.Info)
+                communicator.showMessage(e.message!!, MessageType.Error)
+            }catch (e : IOException){
+                communicator.sendDebugMessage("command could not be executed", MessageType.Info)
                 communicator.showMessage(e.message!!, MessageType.Error)
             }
         }
diff --git a/src/main/kotlin/b/language/server/proBMangement/ProBCommandLineAccess.kt b/src/main/kotlin/b/language/server/proBMangement/ProBCommandLineAccess.kt
index bd34568..a75f679 100644
--- a/src/main/kotlin/b/language/server/proBMangement/ProBCommandLineAccess.kt
+++ b/src/main/kotlin/b/language/server/proBMangement/ProBCommandLineAccess.kt
@@ -1,6 +1,5 @@
 package b.language.server.proBMangement
 
-import b.language.server.communication.Communicator
 import b.language.server.communication.CommunicatorInterface
 import b.language.server.dataStorage.Problem
 import b.language.server.dataStorage.Settings
@@ -90,7 +89,7 @@ class ProBCommandLineAccess(val communicator : CommunicatorInterface) : ProBInte
      * @return success of the action
      */
     fun createFolder(errorDict : File, errorPath: File) : Boolean{
-        communicator.sendDebugMessage("creating errorDict $errorDict and errorFile $errorPath", MessageType.Info)
+        communicator.sendDebugMessage("creating -----huhu----- errorDict $errorDict and errorFile $errorPath", MessageType.Info)
         errorDict.mkdirs()
         FileWriter(errorPath, false).close()
         return errorDict.exists() && errorPath.exists()
@@ -99,15 +98,20 @@ class ProBCommandLineAccess(val communicator : CommunicatorInterface) : ProBInte
     /**
      * Executes the given command
      * @param command to execute
-     * @throws CommandCouldNotBeExecutedException the command failed to reach probcli
+     * @throws CommandCouldNotBeExecutedException probcli failed to execute the given command
+     * @throws IOException failed to reach probcli
      */
     fun performActionOnDocument(command : String) {
-        val process : Process = Runtime.getRuntime().exec(command)
+
+        val process: Process = Runtime.getRuntime().exec(command)
+
         val output : InputStream = process.inputStream
 
-        process.waitFor() //we must wait here to ensure correct behavior when reading an error
 
+       // process.waitFor() //we must wait here to ensure correct behavior when reading an error
+        val exitStatus = process.onExit()
         val outputAsString  = String(output.readAllBytes())
+        communicator.sendDebugMessage("output of execution + ${exitStatus.isCompletedExceptionally}", MessageType.Info)
         if(!outputAsString.contains("ProB Command Line Interface")){
             throw CommandCouldNotBeExecutedException("Error when trying to call probcli with command $command")
         }
-- 
GitLab