From d6e5e9c947d2ea61441d8a5c56960ae5d4de6250 Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Tue, 4 Aug 2020 11:06:34 +0200 Subject: [PATCH 01/13] Added links to Gitter, Troubleshooting, Github to error controller layout --- IHP/ErrorController.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/IHP/ErrorController.hs b/IHP/ErrorController.hs index bdf9b5cce..51b56bd85 100644 --- a/IHP/ErrorController.hs +++ b/IHP/ErrorController.hs @@ -139,6 +139,24 @@ renderError errorTitle view = H.docTypeHtml ! A.lang "en" $ [hsx| margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif; } + + .ihp-error-other-solutions { + margin-top: 2rem; + padding-top: 0.5rem; + font-size: 1rem; + color: hsla(196, 13%, 80%, 1); + border-top: 1px solid hsla(196, 13%, 60%, 0.4); + } + + .ihp-error-other-solutions a { + color: hsla(196, 13%, 80%, 0.9); + text-decoration: none !important; + margin-right: 1rem; + font-size: 0.8rem; + } + .ihp-error-other-solutions a:hover { + color: hsla(196, 13%, 80%, 1); + } @@ -148,6 +166,12 @@ renderError errorTitle view = H.docTypeHtml ! A.lang "en" $ [hsx|
{view}
+ +
+ Ask the IHP Community on Gitter + Check the Troubleshooting + Open a GitHub Issue +
From afe4a683db9e35e0efe3e637990f5a1006db64c1 Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Tue, 4 Aug 2020 11:13:42 +0200 Subject: [PATCH 02/13] Fixed build --- IHP/Server.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IHP/Server.hs b/IHP/Server.hs index b52f05c3e..dd3ad12cb 100644 --- a/IHP/Server.hs +++ b/IHP/Server.hs @@ -57,6 +57,6 @@ run = do runServer $ staticMiddleware $ sessionMiddleware $ - requestLoggerMiddleware $ + FrameworkConfig.requestLoggerMiddleware $ methodOverridePost $ application From bdabadfcbdda220886771e943cae55cf134c82a3 Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Thu, 6 Aug 2020 09:56:31 +0200 Subject: [PATCH 03/13] Added forEachWithIndex function --- IHP/HaskellSupport.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/IHP/HaskellSupport.hs b/IHP/HaskellSupport.hs index 8ed2a3e52..0e9fba6e7 100644 --- a/IHP/HaskellSupport.hs +++ b/IHP/HaskellSupport.hs @@ -21,6 +21,7 @@ module IHP.HaskellSupport ( , isToday , isToday' , forEach +, forEachWithIndex , textToInt , isWeekend , todayIsWeekend @@ -174,6 +175,13 @@ forEach :: (MonoFoldable mono, Applicative m) => mono -> (Element mono -> m ()) forEach elements function = forM_ elements function {-# INLINE forEach #-} + +-- | Example: +-- forEachWithIndex users \(index, user) -> putStrLn (tshow user) +forEachWithIndex :: (Applicative m) => [a] -> ((Int, a) -> m ()) -> m () +forEachWithIndex elements function = forM_ (ClassyPrelude.zip [0..] elements) function +{-# INLINE forEachWithIndex #-} + -- | Parses a text to an int. Returns @Nothing@ on failure. -- -- __Example:__ From 167fd4eeb36ba9ff01bbb5060d9ba18b5e56bdd7 Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Thu, 6 Aug 2020 09:56:47 +0200 Subject: [PATCH 04/13] First draft of improved error screen --- IHP/IDE/Logs/Controller.hs | 9 ++ IHP/IDE/StatusServer.hs | 121 ++++++++++++++++++------ IHP/IDE/ToolServer/Helper/Controller.hs | 7 +- IHP/IDE/ToolServer/Types.hs | 1 + IHP/ViewSupport.hs | 2 +- 5 files changed, 107 insertions(+), 33 deletions(-) diff --git a/IHP/IDE/Logs/Controller.hs b/IHP/IDE/Logs/Controller.hs index ba28d63d9..0c921b073 100644 --- a/IHP/IDE/Logs/Controller.hs +++ b/IHP/IDE/Logs/Controller.hs @@ -1,6 +1,7 @@ module IHP.IDE.Logs.Controller where import IHP.ControllerPrelude +import IHP.IDE.ToolServer.Helper.Controller import IHP.IDE.ToolServer.Types import IHP.IDE.ToolServer.ViewContext import IHP.IDE.Logs.View.Logs @@ -37,6 +38,14 @@ instance Controller LogsController where render LogsView { .. } + action OpenEditorAction = do + let path = param @Text "path" + let line = paramOrDefault @Int 0 "line" + let col = paramOrDefault @Int 0 "col" + openEditor path line col + + renderPlain "" + readDevServerState :: (?controllerContext :: ControllerContext) => IO DevServer.AppState readDevServerState = theDevServerContext |> get #appStateRef diff --git a/IHP/IDE/StatusServer.hs b/IHP/IDE/StatusServer.hs index 39a2f4a62..72c863cef 100644 --- a/IHP/IDE/StatusServer.hs +++ b/IHP/IDE/StatusServer.hs @@ -15,6 +15,8 @@ import qualified Network.HTTP.Types as HTTP import qualified Data.ByteString.Char8 as ByteString import IHP.IDE.Types import IHP.IDE.PortConfig +import IHP.IDE.ToolServer.Types +import IHP.IDE.ToolServer.Routes import ClassyPrelude (async, uninterruptibleCancel, catch, forever) startStatusServer :: (?context :: Context) => IO () @@ -98,53 +100,110 @@ notifyBrowserOnApplicationOutput StatusServerPaused { serverRef, clients, standa pure () notifyBrowserOnApplicationOutput _ _ = putStrLn "StatusServer: Cannot notify clients as not in running state" -renderErrorView :: ByteString -> ByteString -> Bool -> Html5.Html + +data CompilerError = CompilerError { errorMessage :: [ByteString], isWarning :: Bool } deriving (Show) + +renderErrorView :: (?context :: Context) => ByteString -> ByteString -> Bool -> Html5.Html renderErrorView standardOutput errorOutput isCompiling = [hsx| {title} - + - -
{inner}
-
-
{errorOutput}
-
{standardOutput}
+ +
+

{inner}

+
{forEach (parseErrorOutput errorOutput) renderError}
+
{standardOutput}
- + + |] where + parseErrorOutput output = + splitToSections (ByteString.lines output) [] + |> map identifySection + where + splitToSections :: [ByteString] -> [[ByteString]] -> [[ByteString]] + splitToSections [] result = result + splitToSections ("":lines) result = splitToSections lines result + splitToSections lines result = + let (error :: [ByteString], rest) = span (\line -> line /= "") lines + in splitToSections rest ((error |> filter (/= "")):result) + + identifySection :: [ByteString] -> CompilerError + identifySection lines | "warning" `ByteString.isInfixOf` (fromMaybe "" (headMay lines)) = CompilerError { errorMessage = lines, isWarning = True } + identifySection lines = CompilerError { errorMessage = lines, isWarning = False } + title = if isCompiling then [hsx|Compiling...|] else [hsx|Compilation Error|] inner = if isCompiling - then [hsx|

Is compiling

|] - else [hsx|

Error while compiling

|] - - websocketHandler = preEscapedToHtml [plain| - var socket = new WebSocket("ws://localhost:" + window.location.port); - socket.onclose = function () { setTimeout(() => window.location.reload(), 500); } - socket.onmessage = function (event) { - if (event.data === 'clear') { - stdout.innerText = ''; - stderr.innerText = ''; - } else { - var c = (event.data.substr(0, 6) === 'stdout' ? stdout : stderr); - c.innerText = c.innerText + "\\n" + event.data.substr(6); - } - } - |] - - style = preEscapedToHtml [plain| - body { - font-size: 16px; - font-family: -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; - } - |] + then [hsx|Is compiling|] + else [hsx|Problems found while compiling|] + + renderError CompilerError { errorMessage, isWarning } = [hsx| +
+ {forEachWithIndex errorMessage renderLine} +
+ |] + + renderLine (0, line) = [hsx| + {filePath} +