@@ -12,42 +12,93 @@
1212-- Type definitions for psc-ide
1313-----------------------------------------------------------------------------
1414
15−{-# LANGUAGE OverloadedStrings #-}
1615{-# LANGUAGE DeriveFoldable #-}
16+{-# LANGUAGE OverloadedStrings #-}
17+{-# LANGUAGE TemplateHaskell #-}
1718
1819module Language.PureScript.Ide.Types where
1920
2021import Protolude
2122
2223import Control.Concurrent.STM
24+import Control.Lens.TH
2325import Data.Aeson
24−import qualified Data.Map.Lazy as M
25−import qualified Language.PureScript.Errors.JSON as P
26−import qualified Language.PureScript as P
26+import qualified Data.Map.Lazy as M
27+import qualified Language.PureScript as P
28+import qualified Language.PureScript.Errors.JSON as P
2729import Language.PureScript.Ide.Conversions
2830
2931type ModuleIdent = Text
3032
3133data IdeDeclaration
32− = IdeValue P.Ident P.Type
33− | IdeType (P.ProperName 'P.TypeName) P.Kind
34− | IdeTypeSynonym (P.ProperName 'P.TypeName) P.Type
35− | IdeDataConstructor (P.ProperName 'P.ConstructorName) (P.ProperName 'P.TypeName) P.Type
36− | IdeTypeClass (P.ProperName 'P.ClassName)
37− | IdeValueOperator (P.OpName 'P.ValueOpName) (P.Qualified (Either P.Ident (P.ProperName 'P.ConstructorName))) P.Precedence P.Associativity (Maybe P.Type)
38− | IdeTypeOperator (P.OpName 'P.TypeOpName) (P.Qualified (P.ProperName 'P.TypeName)) P.Precedence P.Associativity (Maybe P.Kind)
34+ = IdeDeclValue IdeValue
35+ | IdeDeclType IdeType
36+ | IdeDeclTypeSynonym IdeSynonym
37+ | IdeDeclDataConstructor IdeDataConstructor
38+ | IdeDeclTypeClass (P.ProperName 'P.ClassName)
39+ | IdeDeclValueOperator IdeValueOperator
40+ | IdeDeclTypeOperator IdeTypeOperator
3941 deriving (Show, Eq, Ord)
4042
41−data IdeDeclarationAnn = IdeDeclarationAnn Annotation IdeDeclaration
42− deriving (Show, Eq, Ord)
43+data IdeValue = IdeValue
44+ { _ideValueIdent :: P.Ident
45+ , _ideValueType :: P.Type
46+ } deriving (Show, Eq, Ord)
47+
48+data IdeType = IdeType
49+ { _ideTypeName :: P.ProperName 'P.TypeName
50+ , _ideTypeKind :: P.Kind
51+ } deriving (Show, Eq, Ord)
52+
53+data IdeSynonym = IdeSynonym
54+ { _ideSynonymName :: P.ProperName 'P.TypeName
55+ , _ideSynonymType :: P.Type
56+ } deriving (Show, Eq, Ord)
57+
58+data IdeDataConstructor = IdeDataConstructor
59+ { _ideDtorName :: P.ProperName 'P.ConstructorName
60+ , _ideDtorTypeName :: P.ProperName 'P.TypeName
61+ , _ideDtorType :: P.Type
62+ } deriving (Show, Eq, Ord)
63+
64+data IdeValueOperator = IdeValueOperator
65+ { _ideValueOpName :: P.OpName 'P.ValueOpName
66+ , _ideValueOpAlias :: P.Qualified (Either P.Ident (P.ProperName 'P.ConstructorName))
67+ , _ideValueOpPrecedence :: P.Precedence
68+ , _ideValueOpAssociativity :: P.Associativity
69+ , _ideValueOpType :: Maybe P.Type
70+ } deriving (Show, Eq, Ord)
71+
72+data IdeTypeOperator = IdeTypeOperator
73+ { _ideTypeOpName :: P.OpName 'P.TypeOpName
74+ , _ideTypeOpAlias :: P.Qualified (P.ProperName 'P.TypeName)
75+ , _ideTypeOpPrecedence :: P.Precedence
76+ , _ideTypeOpAssociativity :: P.Associativity
77+ , _ideTypeOpKind :: Maybe P.Kind
78+ } deriving (Show, Eq, Ord)
79+
80+makePrisms ''IdeDeclaration
81+makeLenses ''IdeValue
82+makeLenses ''IdeType
83+makeLenses ''IdeSynonym
84+makeLenses ''IdeDataConstructor
85+makeLenses ''IdeValueOperator
86+makeLenses ''IdeTypeOperator
87+
88+data IdeDeclarationAnn = IdeDeclarationAnn
89+ { _idaAnnotation :: Annotation
90+ , _idaDeclaration :: IdeDeclaration
91+ } deriving (Show, Eq, Ord)
4392
4493data Annotation
4594 = Annotation
46− { annLocation :: Maybe P.SourceSpan
47− , annExportedFrom :: Maybe P.ModuleName
95+ { annLocation :: Maybe P.SourceSpan
96+ , annExportedFrom :: Maybe P.ModuleName
4897 , annTypeAnnotation :: Maybe P.Type
4998 } deriving (Show, Eq, Ord)
5099
100+makeLenses ''IdeDeclarationAnn
101+
51102emptyAnn :: Annotation
52103emptyAnn = Annotation Nothing Nothing Nothing
53104
@@ -103,7 +154,7 @@ data Stage2 = Stage2
103154 }
104155
105156data Stage3 = Stage3
106− { s3Declarations :: M.Map P.ModuleName [IdeDeclarationAnn]
157+ { s3Declarations :: M.Map P.ModuleName [IdeDeclarationAnn]
107158 , s3CachedRebuild :: Maybe (P.ModuleName, P.ExternsFile)
108159 }
109160
@@ -112,11 +163,11 @@ newtype Match a = Match (P.ModuleName, a)
112163
113164-- | A completion as it gets sent to the editors
114165data Completion = Completion
115− { complModule :: Text
116− , complIdentifier :: Text
117− , complType :: Text
118− , complExpandedType :: Text
119− , complLocation :: Maybe P.SourceSpan
166+ { complModule :: Text
167+ , complIdentifier :: Text
168+ , complType :: Text
169+ , complExpandedType :: Text
170+ , complLocation :: Maybe P.SourceSpan
120171 , complDocumentation :: Maybe Text
121172 } deriving (Show, Eq)
122173