@@ -33,21 +33,26 @@ type Type = Text
3333data Fixity = Infix | Infixl | Infixr deriving(Show, Eq, Ord)
3434
3535data ExternDecl
36− = FunctionDecl { functionName :: DeclIdent
37− , functionType :: Type
38− }
39− | FixityDeclaration Fixity
40− Int
41− DeclIdent
42− | Dependency { dependencyModule :: ModuleIdent
43− , dependencyNames :: [Text]
44− , dependencyAlias :: Maybe Text
45− }
46− | ModuleDecl ModuleIdent
47− [DeclIdent]
48− | DataDecl DeclIdent
49− Text
50− | Export ModuleIdent
36+ -- | A function/value declaration
37+ = FunctionDecl
38+ DeclIdent -- The functions name
39+ Type -- The functions type
40+ | FixityDeclaration Fixity Int DeclIdent
41+ -- | A Dependency onto another Module
42+ | Dependency
43+ ModuleIdent -- name of the dependency
44+ [Text] -- explicit imports
45+ (Maybe Text) -- An eventual qualifier
46+
47+ -- | A module declaration
48+ | ModuleDecl
49+ ModuleIdent -- The modules name
50+ [DeclIdent] -- The exported identifiers
51+ -- | A data/newtype declaration
52+ | DataDecl DeclIdent -- The type name
53+ Text -- The "type"
54+ -- | An exported module
55+ | Export ModuleIdent -- The exported Modules name
5156 deriving (Show,Eq,Ord)
5257
5358instance ToJSON ExternDecl where
@@ -63,22 +68,22 @@ instance ToJSON ExternDecl where
6368type Module = (ModuleIdent, [ExternDecl])
6469
6570data Configuration =
66− Configuration {
67− confOutputPath :: FilePath
71+ Configuration
72+ { confOutputPath :: FilePath
6873 , confDebug :: Bool
6974 }
7075
7176data PscIdeEnvironment =
72− PscIdeEnvironment {
73− envStateVar :: TVar PscIdeState
77+ PscIdeEnvironment
78+ { envStateVar :: TVar PscIdeState
7479 , envConfiguration :: Configuration
7580 }
7681
7782type PscIde m = (Applicative m, MonadIO m, MonadReader PscIdeEnvironment m)
7883
7984data PscIdeState =
80− PscIdeState {
81− pscStateModules :: M.Map Text [ExternDecl]
85+ PscIdeState
86+ { pscStateModules :: M.Map Text [ExternDecl]
8287 , externsFiles :: M.Map ModuleName ExternsFile
8388 } deriving Show
8489
@@ -90,29 +95,32 @@ newtype Completion =
9095 deriving (Show,Eq)
9196
9297data ModuleImport =
93− ModuleImport {
94− importModuleName :: ModuleIdent
98+ ModuleImport
99+ { importModuleName :: ModuleIdent
95100 , importType :: D.ImportDeclarationType
96101 , importQualifier :: Maybe Text
97102 } deriving(Show)
98103
99104instance Eq ModuleImport where
100− mi1 == mi2 = importModuleName mi1 == importModuleName mi2
101− && importQualifier mi1 == importQualifier mi2
105+ mi1 == mi2 =
106+ importModuleName mi1 == importModuleName mi2
107+ && importQualifier mi1 == importQualifier mi2
102108
103109instance ToJSON ModuleImport where
104110 toJSON (ModuleImport mn D.Implicit qualifier) =
105− object $ ["module" .= mn
106− , "importType" .= ("implicit" :: Text)
107− ] ++ fmap (\x -> "qualifier" .= x) (maybeToList qualifier)
111+ object $ [ "module" .= mn
112+ , "importType" .= ("implicit" :: Text)
113+ ] ++ fmap (\x -> "qualifier" .= x) (maybeToList qualifier)
108114 toJSON (ModuleImport mn (D.Explicit refs) _) =
109− object ["module" .= mn
115+ object [ "module" .= mn
110116 , "importType" .= ("explicit" :: Text)
111− , "identifiers" .= (identifierFromDeclarationRef <$> refs)]
117+ , "identifiers" .= (identifierFromDeclarationRef <$> refs)
118+ ]
112119 toJSON (ModuleImport mn (D.Hiding refs) _) =
113− object ["module" .= mn
120+ object [ "module" .= mn
114121 , "importType" .= ("hiding" :: Text)
115− , "identifiers" .= (identifierFromDeclarationRef <$> refs)]
122+ , "identifiers" .= (identifierFromDeclarationRef <$> refs)
123+ ]
116124
117125identifierFromDeclarationRef :: D.DeclarationRef -> String
118126identifierFromDeclarationRef (D.TypeRef name _) = N.runProperName name
@@ -121,16 +129,16 @@ identifierFromDeclarationRef (D.TypeClassRef name) = N.runProperName name
121129identifierFromDeclarationRef _ = ""
122130
123131instance FromJSON Completion where
124− parseJSON (Object o) = do
125− m <- o .: "module"
126− d <- o .: "identifier"
127− t <- o .: "type"
128− return $ Completion (m, d, t)
129− parseJSON _ = mzero
132+ parseJSON (Object o) = do
133+ m <- o .: "module"
134+ d <- o .: "identifier"
135+ t <- o .: "type"
136+ pure (Completion (m, d, t))
137+ parseJSON _ = mzero
130138
131139instance ToJSON Completion where
132− toJSON (Completion (m,d,t)) =
133− object ["module" .= m, "identifier" .= d, "type" .= t]
140+ toJSON (Completion (m,d,t)) =
141+ object ["module" .= m, "identifier" .= d, "type" .= t]
134142
135143data Success =
136144 CompletionResult [Completion]
@@ -161,23 +169,22 @@ data PursuitSearchType = Package | Identifier
161169
162170instance FromJSON PursuitSearchType where
163171 parseJSON (String t) = case t of
164− "package" -> return Package
165− "completion" -> return Identifier
172+ "package" -> pure Package
173+ "completion" -> pure Identifier
166174 _ -> mzero
167175 parseJSON _ = mzero
168176
169177instance FromJSON PursuitQuery where
170− parseJSON o = fmap PursuitQuery (parseJSON o)
171−
172−data PursuitResponse
173− = ModuleResponse { moduleResponseName :: Text
174− , moduleResponsePackage :: Text}
175− | DeclarationResponse { declarationResponseType :: Text
176− , declarationResponseModule :: Text
177− , declarationResponseIdent :: Text
178− , declarationResponsePackage :: Text
179− }
180− deriving (Show,Eq)
178+ parseJSON o = PursuitQuery <$> (parseJSON o)
179+
180+data PursuitResponse =
181+ -- | A Pursuit Response for a module. Consists of the modules name and the
182+ -- package it belongs to
183+ ModuleResponse ModuleIdent Text
184+ -- | A Pursuit Response for a declaration. Consist of the declarations type,
185+ -- module, name and package
186+ | DeclarationResponse Type ModuleIdent DeclIdent Text
187+ deriving (Show,Eq)
181188
182189instance FromJSON PursuitResponse where
183190 parseJSON (Object o) = do
@@ -186,22 +193,12 @@ instance FromJSON PursuitResponse where
186193 (type' :: String) <- info .: "type"
187194 case type' of
188195 "module" -> do
189− name <- info .: "module"
190− return
191− ModuleResponse
192− { moduleResponseName = name
193− , moduleResponsePackage = package
194− }
196+ name <- info .: "module"
197+ pure (ModuleResponse name package)
195198 "declaration" -> do
196− moduleName <- info .: "module"
197− Right (ident, declType) <- typeParse <$> o .: "text"
198− return
199− DeclarationResponse
200− { declarationResponseType = declType
201− , declarationResponseModule = moduleName
202− , declarationResponseIdent = ident
203− , declarationResponsePackage = package
204− }
199+ moduleName <- info .: "module"
200+ Right (ident, declType) <- typeParse <$> o .: "text"
201+ pure (DeclarationResponse declType moduleName ident package)
205202 _ -> mzero
206203 parseJSON _ = mzero
207204
@@ -217,7 +214,7 @@ typeParse t = case parse parseType "" t of
217214 _ <- string "::"
218215 spaces
219216 type' <- many1 anyChar
220− return (unpack name, type')
217+ pure (unpack name, type')
221218
222219identifier :: Parser Text
223220identifier = do
@@ -227,14 +224,15 @@ identifier = do
227224 between (char '(') (char ')') (many1 (noneOf ", )")) <|>
228225 many1 (noneOf ", )")
229226 spaces
230− return (pack ident)
227+ pure (pack ident)
231228
232229instance ToJSON PursuitResponse where
233− toJSON ModuleResponse{..} =
234− object ["module" .= moduleResponseName, "package" .= moduleResponsePackage]
235− toJSON DeclarationResponse{..} =
230+ toJSON (ModuleResponse name package) =
231+ object ["module" .= name, "package" .= package]
232+ toJSON (DeclarationResponse module' ident type' package) =
236233 object
237− [ "module" .= declarationResponseModule
238− , "ident" .= declarationResponseIdent
239− , "type" .= declarationResponseType
240− , "package" .= declarationResponsePackage]
234+ [ "module" .= module'
235+ , "ident" .= ident
236+ , "type" .= type'
237+ , "package" .= package
238+ ]