From ccb57f9a16b47aab55f786b976b0b8e89ff49f36 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sat, 18 Sep 2021 23:21:15 +0200 Subject: collecting map dependencies --- lib/Types.hs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'lib/Types.hs') diff --git a/lib/Types.hs b/lib/Types.hs index 79bbfab..2e683c0 100644 --- a/lib/Types.hs +++ b/lib/Types.hs @@ -1,5 +1,6 @@ {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} @@ -27,8 +28,8 @@ data Level = Warning | Suggestion | Info | Forbidden | Error | Fatal data Lint = Depends Dep | Lint Hint -- | TODO: add a reasonable representation of possible urls -newtype Dep = Dep Text - deriving (Generic, ToJSON) +data Dep = Local Text | Link Text | MapLink Text | LocalMap Text + deriving (Generic) data Hint = Hint { hintLevel :: Level @@ -42,8 +43,8 @@ hint level msg = Lint Hint { hintLevel = level, hintMsg = msg } -- | dependencies just have level Info lintLevel :: Lint -> Level -lintLevel (Lint h) = hintLevel h -lintLevel (Depends dep) = Info +lintLevel (Lint h) = hintLevel h +lintLevel (Depends _) = Info instance PrettyPrint Lint where prettyprint (Lint Hint { hintMsg, hintLevel } ) = @@ -57,5 +58,19 @@ instance ToJSON Lint where [ "hintMsg" .= prettyprint dep , "hintLevel" .= A.String "Dependency Info" ] +instance ToJSON Dep where + toJSON = \case + Local text -> json "local" text + Link text -> json "link" text + MapLink text -> json "mapservice" text + LocalMap text -> json "map" text + where + json :: A.Value -> Text -> A.Value + json kind text = A.object [ "kind" .= kind, "dep" .= text ] + instance PrettyPrint Dep where - prettyprint (Dep txt) = txt + prettyprint = \case + Local dep -> "[local dep: " <> dep <> "]" + Link dep -> "[link dep: " <> dep <> "]" + MapLink dep -> "[map service dep: " <> dep <> "]" + LocalMap dep -> "[local map dep: " <> dep <> "]" -- cgit v1.2.3