{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Ide.Plugin.Cabal.Completion.Types where
import Control.DeepSeq (NFData)
import Data.Hashable
import qualified Data.Text as T
import Data.Typeable
import Development.IDE as D
import GHC.Generics
import qualified Ide.Plugin.Cabal.Parse as Parse
data Log
= LogFileSplitError Position
|
LogUnknownKeyWordInContextError KeyWordName
|
LogUnknownStanzaNameInContextError StanzaName
| LogFilePathCompleterIOError FilePath IOError
| LogUseWithStaleFastNoResult
| LogMapLookUpOfKnownKeyFailed T.Text
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
LogFileSplitError Position
pos -> Doc ann
"An error occured when trying to separate the lines of the cabal file at position:" forall ann. Doc ann -> Doc ann -> Doc ann
<+> forall a ann. Show a => a -> Doc ann
viaShow Position
pos
LogUnknownKeyWordInContextError Text
kw ->
Doc ann
"Lookup of key word failed for:" forall ann. Doc ann -> Doc ann -> Doc ann
<+> forall a ann. Show a => a -> Doc ann
viaShow Text
kw
LogUnknownStanzaNameInContextError Text
sn ->
Doc ann
"Lookup of stanza name failed for:" forall ann. Doc ann -> Doc ann -> Doc ann
<+> forall a ann. Show a => a -> Doc ann
viaShow Text
sn
LogFilePathCompleterIOError String
fp IOError
ioErr ->
Doc ann
"When trying to complete the file path:" forall ann. Doc ann -> Doc ann -> Doc ann
<+> forall a ann. Show a => a -> Doc ann
viaShow String
fp forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"the following unexpected IO error occured" forall ann. Doc ann -> Doc ann -> Doc ann
<+> forall a ann. Show a => a -> Doc ann
viaShow IOError
ioErr
Log
LogUseWithStaleFastNoResult -> Doc ann
"Package description couldn't be read"
LogMapLookUpOfKnownKeyFailed Text
key -> Doc ann
"Lookup of key in map failed even though it should exist" forall ann. Doc ann -> Doc ann -> Doc ann
<+> forall a ann. Show a => a -> Doc ann
viaShow Text
key
type instance RuleResult ParseCabal = Parse.GenericPackageDescription
data ParseCabal = ParseCabal
deriving (ParseCabal -> ParseCabal -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ParseCabal -> ParseCabal -> Bool
$c/= :: ParseCabal -> ParseCabal -> Bool
== :: ParseCabal -> ParseCabal -> Bool
$c== :: ParseCabal -> ParseCabal -> Bool
Eq, Int -> ParseCabal -> ShowS
[ParseCabal] -> ShowS
ParseCabal -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ParseCabal] -> ShowS
$cshowList :: [ParseCabal] -> ShowS
show :: ParseCabal -> String
$cshow :: ParseCabal -> String
showsPrec :: Int -> ParseCabal -> ShowS
$cshowsPrec :: Int -> ParseCabal -> ShowS
Show, Typeable, forall x. Rep ParseCabal x -> ParseCabal
forall x. ParseCabal -> Rep ParseCabal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ParseCabal x -> ParseCabal
$cfrom :: forall x. ParseCabal -> Rep ParseCabal x
Generic)
instance Hashable ParseCabal
instance NFData ParseCabal
type Context = (StanzaContext, FieldContext)
data StanzaContext
=
TopLevel
|
Stanza StanzaType (Maybe StanzaName)
deriving (StanzaContext -> StanzaContext -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StanzaContext -> StanzaContext -> Bool
$c/= :: StanzaContext -> StanzaContext -> Bool
== :: StanzaContext -> StanzaContext -> Bool
$c== :: StanzaContext -> StanzaContext -> Bool
Eq, Int -> StanzaContext -> ShowS
[StanzaContext] -> ShowS
StanzaContext -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StanzaContext] -> ShowS
$cshowList :: [StanzaContext] -> ShowS
show :: StanzaContext -> String
$cshow :: StanzaContext -> String
showsPrec :: Int -> StanzaContext -> ShowS
$cshowsPrec :: Int -> StanzaContext -> ShowS
Show, ReadPrec [StanzaContext]
ReadPrec StanzaContext
Int -> ReadS StanzaContext
ReadS [StanzaContext]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StanzaContext]
$creadListPrec :: ReadPrec [StanzaContext]
readPrec :: ReadPrec StanzaContext
$creadPrec :: ReadPrec StanzaContext
readList :: ReadS [StanzaContext]
$creadList :: ReadS [StanzaContext]
readsPrec :: Int -> ReadS StanzaContext
$creadsPrec :: Int -> ReadS StanzaContext
Read)
data FieldContext
=
KeyWord KeyWordName
|
None
deriving (FieldContext -> FieldContext -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FieldContext -> FieldContext -> Bool
$c/= :: FieldContext -> FieldContext -> Bool
== :: FieldContext -> FieldContext -> Bool
$c== :: FieldContext -> FieldContext -> Bool
Eq, Int -> FieldContext -> ShowS
[FieldContext] -> ShowS
FieldContext -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FieldContext] -> ShowS
$cshowList :: [FieldContext] -> ShowS
show :: FieldContext -> String
$cshow :: FieldContext -> String
showsPrec :: Int -> FieldContext -> ShowS
$cshowsPrec :: Int -> FieldContext -> ShowS
Show, ReadPrec [FieldContext]
ReadPrec FieldContext
Int -> ReadS FieldContext
ReadS [FieldContext]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FieldContext]
$creadListPrec :: ReadPrec [FieldContext]
readPrec :: ReadPrec FieldContext
$creadPrec :: ReadPrec FieldContext
readList :: ReadS [FieldContext]
$creadList :: ReadS [FieldContext]
readsPrec :: Int -> ReadS FieldContext
$creadsPrec :: Int -> ReadS FieldContext
Read)
type KeyWordName = T.Text
type StanzaName = T.Text
type StanzaType = T.Text
data CabalPrefixInfo = CabalPrefixInfo
{
CabalPrefixInfo -> Text
completionPrefix :: T.Text,
CabalPrefixInfo -> Maybe Apostrophe
isStringNotation :: Maybe Apostrophe,
CabalPrefixInfo -> Position
completionCursorPosition :: Position,
CabalPrefixInfo -> Range
completionRange :: Range,
CabalPrefixInfo -> String
completionWorkingDir :: FilePath,
CabalPrefixInfo -> Text
completionFileName :: T.Text
}
deriving (CabalPrefixInfo -> CabalPrefixInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CabalPrefixInfo -> CabalPrefixInfo -> Bool
$c/= :: CabalPrefixInfo -> CabalPrefixInfo -> Bool
== :: CabalPrefixInfo -> CabalPrefixInfo -> Bool
$c== :: CabalPrefixInfo -> CabalPrefixInfo -> Bool
Eq, Int -> CabalPrefixInfo -> ShowS
[CabalPrefixInfo] -> ShowS
CabalPrefixInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CabalPrefixInfo] -> ShowS
$cshowList :: [CabalPrefixInfo] -> ShowS
show :: CabalPrefixInfo -> String
$cshow :: CabalPrefixInfo -> String
showsPrec :: Int -> CabalPrefixInfo -> ShowS
$cshowsPrec :: Int -> CabalPrefixInfo -> ShowS
Show)
data Apostrophe = Surrounded | LeftSide
deriving (Apostrophe -> Apostrophe -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Apostrophe -> Apostrophe -> Bool
$c/= :: Apostrophe -> Apostrophe -> Bool
== :: Apostrophe -> Apostrophe -> Bool
$c== :: Apostrophe -> Apostrophe -> Bool
Eq, Eq Apostrophe
Apostrophe -> Apostrophe -> Bool
Apostrophe -> Apostrophe -> Ordering
Apostrophe -> Apostrophe -> Apostrophe
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Apostrophe -> Apostrophe -> Apostrophe
$cmin :: Apostrophe -> Apostrophe -> Apostrophe
max :: Apostrophe -> Apostrophe -> Apostrophe
$cmax :: Apostrophe -> Apostrophe -> Apostrophe
>= :: Apostrophe -> Apostrophe -> Bool
$c>= :: Apostrophe -> Apostrophe -> Bool
> :: Apostrophe -> Apostrophe -> Bool
$c> :: Apostrophe -> Apostrophe -> Bool
<= :: Apostrophe -> Apostrophe -> Bool
$c<= :: Apostrophe -> Apostrophe -> Bool
< :: Apostrophe -> Apostrophe -> Bool
$c< :: Apostrophe -> Apostrophe -> Bool
compare :: Apostrophe -> Apostrophe -> Ordering
$ccompare :: Apostrophe -> Apostrophe -> Ordering
Ord, Int -> Apostrophe -> ShowS
[Apostrophe] -> ShowS
Apostrophe -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Apostrophe] -> ShowS
$cshowList :: [Apostrophe] -> ShowS
show :: Apostrophe -> String
$cshow :: Apostrophe -> String
showsPrec :: Int -> Apostrophe -> ShowS
$cshowsPrec :: Int -> Apostrophe -> ShowS
Show)
applyStringNotation :: Maybe Apostrophe -> T.Text -> T.Text
applyStringNotation :: Maybe Apostrophe -> Text -> Text
applyStringNotation (Just Apostrophe
Surrounded) Text
compl = Text
compl
applyStringNotation (Just Apostrophe
LeftSide) Text
compl = Text
compl forall a. Semigroup a => a -> a -> a
<> Text
"\""
applyStringNotation Maybe Apostrophe
Nothing Text
compl
| Just Char
_ <- (Char -> Bool) -> Text -> Maybe Char
T.find (forall a. Eq a => a -> a -> Bool
== Char
' ') Text
compl = Text
"\"" forall a. Semigroup a => a -> a -> a
<> Text
compl forall a. Semigroup a => a -> a -> a
<> Text
"\""
| Bool
otherwise = Text
compl