This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show warnings in the problems tab
- Loading branch information
1 parent
f8bdf86
commit 0369f55
Showing
6 changed files
with
125 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,93 @@ | ||
module Lunarbox.Component.Editor.Problems where | ||
|
||
import Prelude | ||
import Data.Filterable (filterMap) | ||
import Data.Maybe (Maybe(..)) | ||
import Halogen.HTML as HH | ||
import Halogen.HTML.Events (onClick) | ||
import Lunarbox.Component.Icon (icon) | ||
import Lunarbox.Component.Utils (className) | ||
import Lunarbox.Data.Dataflow.TypeError (TypeError, getLocation, printError) | ||
import Lunarbox.Component.Utils (className, whenElem) | ||
import Lunarbox.Data.Dataflow.Expression.Lint (LintError) | ||
import Lunarbox.Data.Dataflow.Expression.Lint as LintError | ||
import Lunarbox.Data.Dataflow.TypeError (TypeError) | ||
import Lunarbox.Data.Dataflow.TypeError as TypeError | ||
import Lunarbox.Data.Editor.Location (Location(..)) | ||
import Lunarbox.Data.String (toHtml) | ||
|
||
type ProblemsInput a | ||
= { typeErrors :: Array (TypeError Location) | ||
, lintingErrors :: Array (LintError Location) | ||
, navigateTo :: Location -> a | ||
} | ||
|
||
-- Icons | ||
error :: forall h a. HH.HTML h a | ||
error = icon "error" | ||
errorIcon :: forall h a. HH.HTML h a | ||
errorIcon = icon "error" | ||
|
||
warning :: forall h a. HH.HTML h a | ||
warning = icon "warning" | ||
warningIcon :: forall h a. HH.HTML h a | ||
warningIcon = icon "warning" | ||
|
||
-- The actual component | ||
problems :: forall h a. ProblemsInput a -> HH.HTML h a | ||
problems { typeErrors: [] } = HH.main [ className "problems__empty" ] [ HH.text "No errors here!" ] | ||
problems { typeErrors: [], lintingErrors: [] } = HH.main [ className "problems__empty" ] [ HH.text "No errors here!" ] | ||
|
||
problems { typeErrors, navigateTo } = | ||
problems { typeErrors, lintingErrors, navigateTo } = | ||
HH.main [ className "problems__container" ] | ||
$ filterMap | ||
( \{ typeError, location } -> | ||
if location == UnknownLocation then | ||
Nothing | ||
else | ||
Just | ||
$ HH.section [ className "problems__card problems__card--error" ] | ||
[ HH.div [ className "problems__card-header" ] | ||
[ HH.div [ className "problems__card-icon" ] [ error ] | ||
, HH.button | ||
[ className "problems__card-location" | ||
, onClick $ const $ Just $ navigateTo location | ||
] | ||
[ HH.text $ show location | ||
] | ||
] | ||
, HH.div [ className "problems__card-message" ] | ||
[ toHtml $ printError typeError ] | ||
] | ||
) | ||
$ (\typeError -> { typeError, location: getLocation typeError }) | ||
<$> typeErrors | ||
$ typeErrorHtml | ||
<> lintingErrorHtml | ||
where | ||
mkProblem = createProblemMaker navigateTo | ||
|
||
typeErrorHtml = | ||
( \error -> | ||
mkProblem | ||
{ level: Error | ||
, message: TypeError.printError error | ||
, location: TypeError.getLocation error | ||
} | ||
) | ||
<$> typeErrors | ||
|
||
lintingErrorHtml = | ||
( \error -> | ||
mkProblem | ||
{ level: Warning | ||
, message: "not here yet" | ||
, location: LintError.getLocation error | ||
} | ||
) | ||
<$> lintingErrors | ||
|
||
-- | Data about how to color a problem | ||
data ProblemLevel | ||
= Warning | ||
| Error | ||
|
||
type ProblemConfig | ||
= { level :: ProblemLevel, message :: String, location :: Location | ||
} | ||
|
||
-- | Create the html for a problem | ||
createProblemMaker :: forall h a. (Location -> a) -> ProblemConfig -> HH.HTML h a | ||
createProblemMaker navigateTo { location, message, level } = | ||
whenElem (location /= UnknownLocation) \_ -> | ||
HH.section | ||
[ className $ "problems__card " | ||
<> case level of | ||
Warning -> "problems__card--warning" | ||
Error -> "problems__card--error" | ||
] | ||
[ HH.div [ className "problems__card-header" ] | ||
[ HH.div [ className "problems__card-icon" ] | ||
[ case level of | ||
Warning -> warningIcon | ||
Error -> errorIcon | ||
] | ||
, HH.button | ||
[ className "problems__card-location" | ||
, onClick $ const $ Just $ navigateTo location | ||
] | ||
[ HH.text $ show location | ||
] | ||
] | ||
, HH.div [ className "problems__card-message" ] | ||
[ HH.text message ] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters