@@ -33,21 +33,26 @@ type Type = Text
33data Fixity = Infix | Infixl | Infixr deriving(Show, Eq, Ord)
33data Fixity = Infix | Infixl | Infixr deriving(Show, Eq, Ord)
35data ExternDecl
35data ExternDecl
36+ -- | A function/value declaration
36− = FunctionDecl { functionName :: DeclIdent
37+ = FunctionDecl
37− , functionType :: Type
38+ DeclIdent -- The functions name
38− }
39+ Type -- The functions type
39− | FixityDeclaration Fixity
40+ | FixityDeclaration Fixity Int DeclIdent
40− Int
41+ -- | A Dependency onto another Module
41− DeclIdent
42+ | Dependency
42− | Dependency { dependencyModule :: ModuleIdent
43+ ModuleIdent -- name of the dependency
43− , dependencyNames :: [Text]
44+ [Text] -- explicit imports
44− , dependencyAlias :: Maybe Text
45+ (Maybe Text) -- An eventual qualifier
47+ -- | A module declaration
46− | ModuleDecl ModuleIdent
48+ | ModuleDecl
49+ ModuleIdent -- The modules name
47− [DeclIdent]
50+ [DeclIdent] -- The exported identifiers
51+ -- | A data/newtype declaration
48− | DataDecl DeclIdent
52+ | DataDecl DeclIdent -- The type name
49− Text
53+ Text -- The "type"
54+ -- | An exported module
50− | Export ModuleIdent
55+ | Export ModuleIdent -- The exported Modules name
51 deriving (Show,Eq,Ord)
56 deriving (Show,Eq,Ord)
53instance ToJSON ExternDecl where
58instance ToJSON ExternDecl where
@@ -63,22 +68,22 @@ instance ToJSON ExternDecl where
63type Module = (ModuleIdent, [ExternDecl])
68type Module = (ModuleIdent, [ExternDecl])
65data Configuration =
70data Configuration =
66− Configuration {
71+ Configuration
67− confOutputPath :: FilePath
72+ { confOutputPath :: FilePath
68 , confDebug :: Bool
73 , confDebug :: Bool
71data PscIdeEnvironment =
76data PscIdeEnvironment =
72− PscIdeEnvironment {
77+ PscIdeEnvironment
73− envStateVar :: TVar PscIdeState
78+ { envStateVar :: TVar PscIdeState
74 , envConfiguration :: Configuration
79 , envConfiguration :: Configuration
77type PscIde m = (Applicative m, MonadIO m, MonadReader PscIdeEnvironment m)
82type PscIde m = (Applicative m, MonadIO m, MonadReader PscIdeEnvironment m)
79data PscIdeState =
84data PscIdeState =
80− PscIdeState {
85+ PscIdeState
81− pscStateModules :: M.Map Text [ExternDecl]
86+ { pscStateModules :: M.Map Text [ExternDecl]
82 , externsFiles :: M.Map ModuleName ExternsFile
87 , externsFiles :: M.Map ModuleName ExternsFile
83 } deriving Show
88 } deriving Show
@@ -90,29 +95,32 @@ newtype Completion =
90 deriving (Show,Eq)
95 deriving (Show,Eq)
92data ModuleImport =
97data ModuleImport =
93− ModuleImport {
98+ ModuleImport
94− importModuleName :: ModuleIdent
99+ { importModuleName :: ModuleIdent
95 , importType :: D.ImportDeclarationType
100 , importType :: D.ImportDeclarationType
96 , importQualifier :: Maybe Text
101 , importQualifier :: Maybe Text
97 } deriving(Show)
102 } deriving(Show)
99instance Eq ModuleImport where
104instance Eq ModuleImport where
100− mi1 == mi2 = importModuleName mi1 == importModuleName mi2
106+ importModuleName mi1 == importModuleName mi2
101− && importQualifier mi1 == importQualifier mi2
107+ && importQualifier mi1 == importQualifier mi2
103instance ToJSON ModuleImport where
109instance ToJSON ModuleImport where
104 toJSON (ModuleImport mn D.Implicit qualifier) =
110 toJSON (ModuleImport mn D.Implicit qualifier) =
105− object $ ["module" .= mn
111+ object $ [ "module" .= mn
106− , "importType" .= ("implicit" :: Text)
112+ , "importType" .= ("implicit" :: Text)
107− ] ++ fmap (\x -> "qualifier" .= x) (maybeToList qualifier)
113+ ] ++ fmap (\x -> "qualifier" .= x) (maybeToList qualifier)
108 toJSON (ModuleImport mn (D.Explicit refs) _) =
114 toJSON (ModuleImport mn (D.Explicit refs) _) =
109− object ["module" .= mn
115+ object [ "module" .= mn
110 , "importType" .= ("explicit" :: Text)
116 , "importType" .= ("explicit" :: Text)
111− , "identifiers" .= (identifierFromDeclarationRef <$> refs)]
117+ , "identifiers" .= (identifierFromDeclarationRef <$> refs)
112 toJSON (ModuleImport mn (D.Hiding refs) _) =
119 toJSON (ModuleImport mn (D.Hiding refs) _) =
113− object ["module" .= mn
120+ object [ "module" .= mn
114 , "importType" .= ("hiding" :: Text)
121 , "importType" .= ("hiding" :: Text)
115− , "identifiers" .= (identifierFromDeclarationRef <$> refs)]
122+ , "identifiers" .= (identifierFromDeclarationRef <$> refs)
117identifierFromDeclarationRef :: D.DeclarationRef -> String
125identifierFromDeclarationRef :: D.DeclarationRef -> String
118identifierFromDeclarationRef (D.TypeRef name _) = N.runProperName name
126identifierFromDeclarationRef (D.TypeRef name _) = N.runProperName name
@@ -121,16 +129,16 @@ identifierFromDeclarationRef (D.TypeClassRef name) = N.runProperName name
121identifierFromDeclarationRef _ = ""
129identifierFromDeclarationRef _ = ""
123instance FromJSON Completion where
131instance FromJSON Completion where
124− parseJSON (Object o) = do
132+ parseJSON (Object o) = do
125− m <- o .: "module"
133+ m <- o .: "module"
126− d <- o .: "identifier"
134+ d <- o .: "identifier"
127− t <- o .: "type"
135+ t <- o .: "type"
128− return $ Completion (m, d, t)
136+ pure (Completion (m, d, t))
129− parseJSON _ = mzero
137+ parseJSON _ = mzero
131instance ToJSON Completion where
139instance ToJSON Completion where
132− toJSON (Completion (m,d,t)) =
140+ toJSON (Completion (m,d,t)) =
133− object ["module" .= m, "identifier" .= d, "type" .= t]
141+ object ["module" .= m, "identifier" .= d, "type" .= t]
135data Success =
143data Success =
136 CompletionResult [Completion]
144 CompletionResult [Completion]
@@ -161,23 +169,22 @@ data PursuitSearchType = Package | Identifier
162instance FromJSON PursuitSearchType where
170instance FromJSON PursuitSearchType where
163 parseJSON (String t) = case t of
171 parseJSON (String t) = case t of
164− "package" -> return Package
172+ "package" -> pure Package
165− "completion" -> return Identifier
173+ "completion" -> pure Identifier
166 _ -> mzero
174 _ -> mzero
167 parseJSON _ = mzero
175 parseJSON _ = mzero
169instance FromJSON PursuitQuery where
177instance FromJSON PursuitQuery where
170− parseJSON o = fmap PursuitQuery (parseJSON o)
178+ parseJSON o = PursuitQuery <$> (parseJSON o)
172−data PursuitResponse
180+data PursuitResponse =
181+ -- | A Pursuit Response for a module. Consists of the modules name and the
182+ -- package it belongs to
173− = ModuleResponse { moduleResponseName :: Text
183+ ModuleResponse ModuleIdent Text
174− , moduleResponsePackage :: Text}
184+ -- | A Pursuit Response for a declaration. Consist of the declarations type,
185+ -- module, name and package
175− | DeclarationResponse { declarationResponseType :: Text
186+ | DeclarationResponse Type ModuleIdent DeclIdent Text
176− , declarationResponseModule :: Text
177− , declarationResponseIdent :: Text
178− , declarationResponsePackage :: Text
180− deriving (Show,Eq)
187+ deriving (Show,Eq)
182instance FromJSON PursuitResponse where
189instance FromJSON PursuitResponse where
183 parseJSON (Object o) = do
190 parseJSON (Object o) = do
@@ -186,22 +193,12 @@ instance FromJSON PursuitResponse where
186 (type' :: String) <- info .: "type"
193 (type' :: String) <- info .: "type"
187 case type' of
194 case type' of
188 "module" -> do
195 "module" -> do
189− name <- info .: "module"
196+ name <- info .: "module"
191− ModuleResponse
197+ pure (ModuleResponse name package)
192− { moduleResponseName = name
193− , moduleResponsePackage = package
195 "declaration" -> do
198 "declaration" -> do
196− moduleName <- info .: "module"
199+ moduleName <- info .: "module"
197− Right (ident, declType) <- typeParse <$> o .: "text"
200+ Right (ident, declType) <- typeParse <$> o .: "text"
199− DeclarationResponse
201+ pure (DeclarationResponse declType moduleName ident package)
200− { declarationResponseType = declType
201− , declarationResponseModule = moduleName
202− , declarationResponseIdent = ident
203− , declarationResponsePackage = package
205 _ -> mzero
202 _ -> mzero
206 parseJSON _ = mzero
203 parseJSON _ = mzero
@@ -217,7 +214,7 @@ typeParse t = case parse parseType "" t of
217 _ <- string "::"
214 _ <- string "::"
219 type' <- many1 anyChar
216 type' <- many1 anyChar
220− return (unpack name, type')
217+ pure (unpack name, type')
222identifier :: Parser Text
219identifier :: Parser Text
223identifier = do
220identifier = do
@@ -227,14 +224,15 @@ identifier = do
227 between (char '(') (char ')') (many1 (noneOf ", )")) <|>
224 between (char '(') (char ')') (many1 (noneOf ", )")) <|>
228 many1 (noneOf ", )")
225 many1 (noneOf ", )")
230− return (pack ident)
227+ pure (pack ident)
232instance ToJSON PursuitResponse where
229instance ToJSON PursuitResponse where
233− toJSON ModuleResponse{..} =
230+ toJSON (ModuleResponse name package) =
234− object ["module" .= moduleResponseName, "package" .= moduleResponsePackage]
231+ object ["module" .= name, "package" .= package]
235− toJSON DeclarationResponse{..} =
232+ toJSON (DeclarationResponse module' ident type' package) =
237− [ "module" .= declarationResponseModule
234+ [ "module" .= module'
238− , "ident" .= declarationResponseIdent
235+ , "ident" .= ident
239− , "type" .= declarationResponseType
236+ , "type" .= type'
240− , "package" .= declarationResponsePackage]
237+ , "package" .= package