{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE ScopedTypeVariables   #-}
{-# OPTIONS_GHC -Wwarn #-}
{-# LANGUAGE LambdaCase            #-}

{- |
Eval Plugin entry point.
-}
module Ide.Plugin.Eval (
    descriptor,
    Log(..)
    ) where

import           Development.IDE              (IdeState)
import           Development.IDE.Types.Logger (Pretty (pretty), Recorder,
                                               WithPriority, cmapWithPrio)
import qualified Ide.Plugin.Eval.CodeLens     as CL
import           Ide.Plugin.Eval.Config
import           Ide.Plugin.Eval.Rules        (rules)
import qualified Ide.Plugin.Eval.Rules        as EvalRules
import           Ide.Types                    (ConfigDescriptor (..),
                                               PluginDescriptor (..), PluginId,
                                               defaultConfigDescriptor,
                                               defaultPluginDescriptor,
                                               mkCustomConfig, mkPluginHandler)
import           Language.LSP.Types

newtype Log = LogEvalRules EvalRules.Log deriving Int -> Log -> ShowS
[Log] -> ShowS
Log -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Log] -> ShowS
$cshowList :: [Log] -> ShowS
show :: Log -> String
$cshow :: Log -> String
showsPrec :: Int -> Log -> ShowS
$cshowsPrec :: Int -> Log -> ShowS
Show

instance Pretty Log where
  pretty :: forall ann. Log -> Doc ann
pretty = \case
    LogEvalRules Log
log -> forall a ann. Pretty a => a -> Doc ann
pretty Log
log

-- |Plugin descriptor
descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
descriptor :: Recorder (WithPriority Log)
-> PluginId -> PluginDescriptor IdeState
descriptor Recorder (WithPriority Log)
recorder PluginId
plId =
    (forall ideState. PluginId -> PluginDescriptor ideState
defaultPluginDescriptor PluginId
plId)
        { pluginHandlers :: PluginHandlers IdeState
pluginHandlers = forall (m :: Method 'FromClient 'Request) ideState.
PluginRequestMethod m =>
SClientMethod m
-> PluginMethodHandler ideState m -> PluginHandlers ideState
mkPluginHandler SMethod 'TextDocumentCodeLens
STextDocumentCodeLens PluginMethodHandler IdeState 'TextDocumentCodeLens
CL.codeLens
        , pluginCommands :: [PluginCommand IdeState]
pluginCommands = [PluginId -> PluginCommand IdeState
CL.evalCommand PluginId
plId]
        , pluginRules :: Rules ()
pluginRules = Recorder (WithPriority Log) -> Rules ()
rules (forall a b.
(a -> b) -> Recorder (WithPriority b) -> Recorder (WithPriority a)
cmapWithPrio Log -> Log
LogEvalRules Recorder (WithPriority Log)
recorder)
        , pluginConfigDescriptor :: ConfigDescriptor
pluginConfigDescriptor = ConfigDescriptor
defaultConfigDescriptor
                                   { configCustomConfig :: CustomConfig
configCustomConfig = forall (r :: [PropertyKey]). Properties r -> CustomConfig
mkCustomConfig Properties
  '[ 'PropertyKey "exception" 'TBoolean,
     'PropertyKey "diff" 'TBoolean]
properties
                                   }
        }