git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
lots of formatting.
d6a02caChristoph Hegemann
src/Language/PureScript/Ide/CaseSplit.hs−9
@@ -60,15 +60,6 @@ caseSplit q = do
60 let appliedCtors = map (\(n, ts) -> (n, map applyTypeVars ts)) ctors
60 let appliedCtors = map (\(n, ts) -> (n, map applyTypeVars ts)) ctors
61 pure appliedCtors
61 pure appliedCtors
62
62
63−{- ["EDType {
64− edTypeName = ProperName {runProperName = \"Either\"}
65− , edTypeKind = FunKind Star (FunKind Star Star)
66− , edTypeDeclarationKind =
67− DataType [(\"a\",Just Star),(\"b\",Just Star)]
68− [(ProperName {runProperName = \"Left\"},[TypeVar \"a\"])
69− ,(ProperName {runProperName = \"Right\"},[TypeVar \"b\"])]}"]
70−-}
71−
72findTypeDeclaration :: (PscIde m, MonadLogger m, MonadError PscIdeError m) =>
63findTypeDeclaration :: (PscIde m, MonadLogger m, MonadError PscIdeError m) =>
73 ProperName 'TypeName -> m ExternsDeclaration
64 ProperName 'TypeName -> m ExternsDeclaration
74findTypeDeclaration q = do
65findTypeDeclaration q = do
src/Language/PureScript/Ide/Completion.hs+4−4
@@ -24,12 +24,12 @@ getExactMatches search filters modules =
24
24
25completionsFromModules :: [Module] -> [Completion]
25completionsFromModules :: [Module] -> [Completion]
26completionsFromModules = foldMap completionFromModule
26completionsFromModules = foldMap completionFromModule
27− where
27+ where
28− completionFromModule :: Module -> [Completion]
28+ completionFromModule :: Module -> [Completion]
29− completionFromModule (moduleIdent, decls) = mapMaybe (completionFromDecl moduleIdent) decls
29+ completionFromModule (moduleIdent, decls) = mapMaybe (completionFromDecl moduleIdent) decls
30
30
31completionFromDecl :: ModuleIdent -> ExternDecl -> Maybe Completion
31completionFromDecl :: ModuleIdent -> ExternDecl -> Maybe Completion
32completionFromDecl mi (FunctionDecl name type') = Just (Completion (mi, name, type'))
32completionFromDecl mi (FunctionDecl name type') = Just (Completion (mi, name, type'))
33completionFromDecl mi (DataDecl name kind) = Just (Completion (mi, name, kind))
33completionFromDecl mi (DataDecl name kind) = Just (Completion (mi, name, kind))
34−completionFromDecl _ (ModuleDecl name _) = Just (Completion ("module", name, "module"))
34+completionFromDecl _ (ModuleDecl name _) = Just (Completion ("module", name, "module"))
35completionFromDecl _ _ = Nothing
35completionFromDecl _ _ = Nothing
src/Language/PureScript/Ide/Error.hs+11−12
@@ -21,21 +21,20 @@ data PscIdeError
21
21
22instance ToJSON PscIdeError where
22instance ToJSON PscIdeError where
23 toJSON err = object
23 toJSON err = object
24− [
25− "resultType" .= ("error" :: Text),
24+ [ "resultType" .= ("error" :: Text)
26− "result" .= textError err
25+ , "result" .= textError err
27− ]
26+ ]
28
27
29textError :: PscIdeError -> Text
28textError :: PscIdeError -> Text
30−textError (GeneralError msg) = pack msg
29+textError (GeneralError msg) = pack msg
31−textError (NotFound ident) = "Symbol '" <> ident <> "' not found."
30+textError (NotFound ident) = "Symbol '" <> ident <> "' not found."
32−textError (ModuleNotFound ident) = "Module '" <> ident <> "' not found."
31+textError (ModuleNotFound ident) = "Module '" <> ident <> "' not found."
33−textError (ModuleFileNotFound ident) = "Extern file for module " <> ident <>" could not be found"
32+textError (ModuleFileNotFound ident) = "Extern file for module " <> ident <>" could not be found"
34−textError (ParseError parseError msg) = pack $ msg <> ": " <> show (escape parseError)
33+textError (ParseError parseError msg) = pack $ msg <> ": " <> show (escape parseError)
35− where
34+ where
36 -- escape newlines and other special chars so we can send the error over the socket as a single line
35 -- escape newlines and other special chars so we can send the error over the socket as a single line
37− escape :: P.ParseError -> String
36+ escape :: P.ParseError -> String
38− escape = show
37+ escape = show
39
38
40-- | Specialized version of `first` from `Data.Bifunctors`
39-- | Specialized version of `first` from `Data.Bifunctors`
41first :: (a -> b) -> Either a r -> Either b r
40first :: (a -> b) -> Either a r -> Either b r
src/Language/PureScript/Ide/Matcher.hs+6−6
@@ -76,8 +76,8 @@ flexMatch pattern = mapMaybe (flexRate pattern)
76
76
77flexRate :: Text -> Completion -> Maybe ScoredCompletion
77flexRate :: Text -> Completion -> Maybe ScoredCompletion
78flexRate pattern c@(Completion (_,ident,_)) = do
78flexRate pattern c@(Completion (_,ident,_)) = do
79− score <- flexScore pattern ident
79+ score <- flexScore pattern ident
80− return (c, score)
80+ return (c, score)
81
81
82-- FlexMatching ala Sublime.
82-- FlexMatching ala Sublime.
83-- Borrowed from: http://cdewaka.com/2013/06/fuzzy-pattern-matching-in-haskell/
83-- Borrowed from: http://cdewaka.com/2013/06/fuzzy-pattern-matching-in-haskell/
@@ -88,13 +88,13 @@ flexRate pattern c@(Completion (_,ident,_)) = do
88flexScore :: Text -> DeclIdent -> Maybe Double
88flexScore :: Text -> DeclIdent -> Maybe Double
89flexScore "" _ = Nothing
89flexScore "" _ = Nothing
90flexScore pat str =
90flexScore pat str =
91− case TE.encodeUtf8 str =~ TE.encodeUtf8 pat' :: (Int, Int) of
91+ case TE.encodeUtf8 str =~ TE.encodeUtf8 pat' :: (Int, Int) of
92− (-1,0) -> Nothing
92+ (-1,0) -> Nothing
93− (start,len) -> Just $ calcScore start (start + len)
93+ (start,len) -> Just $ calcScore start (start + len)
94 where
94 where
95 Just (first,pattern) = T.uncons pat
95 Just (first,pattern) = T.uncons pat
96 -- This just interleaves the search string with .*
96 -- This just interleaves the search string with .*
97 -- abcd -> a.*b.*c.*d
97 -- abcd -> a.*b.*c.*d
98 pat' = first `T.cons` T.concatMap (T.snoc ".*") pattern
98 pat' = first `T.cons` T.concatMap (T.snoc ".*") pattern
99 calcScore start end =
99 calcScore start end =
100− 100.0 / fromIntegral ((1 + start) * (end - start + 1))
100+ 100.0 / fromIntegral ((1 + start) * (end - start + 1))
src/Language/PureScript/Ide/Pursuit.hs+11−11
@@ -10,9 +10,9 @@ import qualified Control.Exception as E
10import Data.Aeson
10import Data.Aeson
11import Data.ByteString (ByteString)
11import Data.ByteString (ByteString)
12import Data.ByteString.Lazy (fromStrict)
12import Data.ByteString.Lazy (fromStrict)
13−import Data.Foldable (toList)
13+import Data.Foldable (toList)
14+import Data.Maybe (mapMaybe)
14import Data.Monoid ((<>))
15import Data.Monoid ((<>))
15−import Data.Maybe (mapMaybe)
16import Data.String
16import Data.String
17import Data.Text (Text)
17import Data.Text (Text)
18import qualified Data.Text as T
18import qualified Data.Text as T
@@ -33,12 +33,12 @@ queryPursuit q = do
33 }
33 }
34 m <- newManager tlsManagerSettings
34 m <- newManager tlsManagerSettings
35 withHTTP req m $ \resp ->
35 withHTTP req m $ \resp ->
36− P.fold (\x a -> x <> a) "" id $ responseBody resp
36+ P.fold (<>) "" id $ responseBody resp
37
37
38
38
39handler :: HttpException -> IO [a]
39handler :: HttpException -> IO [a]
40−handler StatusCodeException{} = return []
40+handler StatusCodeException{} = pure []
41−handler _ = return []
41+handler _ = pure []
42
42
43searchPursuitForDeclarations :: Text -> IO [PursuitResponse]
43searchPursuitForDeclarations :: Text -> IO [PursuitResponse]
44searchPursuitForDeclarations query =
44searchPursuitForDeclarations query =
@@ -54,12 +54,12 @@ searchPursuitForDeclarations query =
54
54
55findPackagesForModuleIdent :: Text -> IO [PursuitResponse]
55findPackagesForModuleIdent :: Text -> IO [PursuitResponse]
56findPackagesForModuleIdent query =
56findPackagesForModuleIdent query =
57− (do r <- queryPursuit query
57+ (do r <- queryPursuit query
58− let results' = decode (fromStrict r) :: Maybe Array
58+ let results' = decode (fromStrict r) :: Maybe Array
59− case results' of
59+ case results' of
60− Nothing -> pure []
60+ Nothing -> pure []
61− Just results -> pure (mapMaybe isModuleResponse (map fromJSON (toList results)))) `E.catch`
61+ Just results -> pure (mapMaybe isModuleResponse (map fromJSON (toList results)))) `E.catch`
62− handler
62+ handler
63 where
63 where
64 isModuleResponse (Success a@ModuleResponse{}) = Just a
64 isModuleResponse (Success a@ModuleResponse{}) = Just a
65 isModuleResponse _ = Nothing
65 isModuleResponse _ = Nothing
src/Language/PureScript/Ide/Reexports.hs+21−19
@@ -15,10 +15,10 @@ import Language.PureScript.Ide.Types
15
15
16getReexports :: Module -> [ExternDecl]
16getReexports :: Module -> [ExternDecl]
17getReexports (mn, decls)= concatMap getExport decls
17getReexports (mn, decls)= concatMap getExport decls
18− where getExport d
18+ where getExport d
19− | (Export mn') <- d
19+ | (Export mn') <- d
20− , mn /= mn' = replaceExportWithAliases decls mn'
20+ , mn /= mn' = replaceExportWithAliases decls mn'
21− | otherwise = []
21+ | otherwise = []
22
22
23dependencyToExport :: ExternDecl -> ExternDecl
23dependencyToExport :: ExternDecl -> ExternDecl
24dependencyToExport (Dependency m _ _) = Export m
24dependencyToExport (Dependency m _ _) = Export m
@@ -51,23 +51,25 @@ removeExportDecls = fmap (filter (not . isExport))
51
51
52replaceReexports :: Module -> Map ModuleIdent [ExternDecl] -> Module
52replaceReexports :: Module -> Map ModuleIdent [ExternDecl] -> Module
53replaceReexports m db = result
53replaceReexports m db = result
54+ where
54− where reexports = getReexports m
55+ reexports = getReexports m
55− result = foldl go (removeExportDecls m) reexports
56+ result = foldl go (removeExportDecls m) reexports
56
57
57− go :: Module -> ExternDecl -> Module
58+ go :: Module -> ExternDecl -> Module
58− go m' re@(Export name) = replaceReexport re m' (getModule name)
59+ go m' re@(Export name) = replaceReexport re m' (getModule name)
59− go _ _ = error "partiality! woohoo"
60+ go _ _ = error "partiality! woohoo"
60
61
61− getModule :: ModuleIdent -> Module
62+ getModule :: ModuleIdent -> Module
62− getModule name = clean res
63+ getModule name = clean res
64+ where
63− where res = fromMaybe emptyModule $ (name , ) <$> Map.lookup name db
65+ res = fromMaybe emptyModule $ (name , ) <$> Map.lookup name db
64− -- we have to do this because keeping self exports in will result in
66+ -- we have to do this because keeping self exports in will result in
65− -- infinite loops
67+ -- infinite loops
66− clean (mn, decls) = (mn,) (filter (/= Export mn) decls)
68+ clean (mn, decls) = (mn,) (filter (/= Export mn) decls)
67
69
68resolveReexports :: Map ModuleIdent [ExternDecl] -> Module -> Module
70resolveReexports :: Map ModuleIdent [ExternDecl] -> Module -> Module
69−resolveReexports modules m = do
71+resolveReexports modules m =
70 let replaced = replaceReexports m modules
72 let replaced = replaceReexports m modules
71− if null . getReexports $ replaced
73+ in if null (getReexports replaced)
72− then replaced
74+ then replaced
73− else resolveReexports modules replaced
75+ else resolveReexports modules replaced
src/Language/PureScript/Ide/SourceFile.hs+37−36
@@ -52,18 +52,19 @@ getImportsForFile fp = do
52 module' <- parseModuleFromFile fp
52 module' <- parseModuleFromFile fp
53 let imports = getImports module'
53 let imports = getImports module'
54 pure (mkModuleImport . unwrapPositionedImport <$> imports)
54 pure (mkModuleImport . unwrapPositionedImport <$> imports)
55+ where
55− where mkModuleImport (D.ImportDeclaration mn importType' qualifier _) =
56+ mkModuleImport (D.ImportDeclaration mn importType' qualifier _) =
56− ModuleImport
57+ ModuleImport
57− (T.pack (N.runModuleName mn))
58+ (T.pack (N.runModuleName mn))
58− importType'
59+ importType'
59− (T.pack . N.runModuleName <$> qualifier)
60+ (T.pack . N.runModuleName <$> qualifier)
60− mkModuleImport _ = error "Shouldn't have gotten anything but Imports here"
61+ mkModuleImport _ = error "Shouldn't have gotten anything but Imports here"
61− unwrapPositionedImport (D.ImportDeclaration mn importType' qualifier b) =
62+ unwrapPositionedImport (D.ImportDeclaration mn importType' qualifier b) =
62− D.ImportDeclaration mn (unwrapImportType importType') qualifier b
63+ D.ImportDeclaration mn (unwrapImportType importType') qualifier b
63− unwrapPositionedImport x = x
64+ unwrapPositionedImport x = x
64− unwrapImportType (D.Explicit decls) = D.Explicit (map unwrapPositionedRef decls)
65+ unwrapImportType (D.Explicit decls) = D.Explicit (map unwrapPositionedRef decls)
65− unwrapImportType (D.Hiding decls) = D.Hiding (map unwrapPositionedRef decls)
66+ unwrapImportType (D.Hiding decls) = D.Hiding (map unwrapPositionedRef decls)
66− unwrapImportType D.Implicit = D.Implicit
67+ unwrapImportType D.Implicit = D.Implicit
67
68
68getPositionedImports :: D.Module -> [D.Declaration]
69getPositionedImports :: D.Module -> [D.Declaration]
69getPositionedImports (D.Module _ _ _ declarations _) =
70getPositionedImports (D.Module _ _ _ declarations _) =
@@ -73,34 +74,34 @@ getPositionedImports (D.Module _ _ _ declarations _) =
73 isImport _ = Nothing
74 isImport _ = Nothing
74
75
75getDeclPosition :: D.Module -> String -> Maybe SP.SourceSpan
76getDeclPosition :: D.Module -> String -> Maybe SP.SourceSpan
76−getDeclPosition m ident =
77− let decls = getDeclarations m
78− in getFirst (foldMap (match ident) decls)
77+getDeclPosition m ident = getFirst (foldMap (match ident) decls)
78+ where
79+ decls = getDeclarations m
79− where match q (D.PositionedDeclaration ss _ decl) = First (if go q decl
80+ match q (D.PositionedDeclaration ss _ decl) = First (if go q decl
80− then Just ss
81+ then Just ss
81− else Nothing)
82+ else Nothing)
82− match _ _ = First Nothing
83+ match _ _ = First Nothing
83
84
84− go q (D.DataDeclaration _ name _ constructors) =
85+ go q (D.DataDeclaration _ name _ constructors) =
85− properEqual name q || any (\(x,_) -> properEqual x q) constructors
86+ properEqual name q || any (\(x,_) -> properEqual x q) constructors
86− go q (D.DataBindingGroupDeclaration decls) = any (go q) decls
87+ go q (D.DataBindingGroupDeclaration decls') = any (go q) decls'
87− go q (D.TypeSynonymDeclaration name _ _) = properEqual name q
88+ go q (D.TypeSynonymDeclaration name _ _) = properEqual name q
88− go q (D.TypeDeclaration ident' _) = identEqual ident' q
89+ go q (D.TypeDeclaration ident' _) = identEqual ident' q
89− go q (D.ValueDeclaration ident' _ _ _) = identEqual ident' q
90+ go q (D.ValueDeclaration ident' _ _ _) = identEqual ident' q
90− go q (D.ExternDeclaration ident' _) = identEqual ident' q
91+ go q (D.ExternDeclaration ident' _) = identEqual ident' q
91− go q (D.ExternDataDeclaration name _) = properEqual name q
92+ go q (D.ExternDataDeclaration name _) = properEqual name q
92− go q (D.TypeClassDeclaration name _ _ members) =
93+ go q (D.TypeClassDeclaration name _ _ members) =
93− properEqual name q || any (go q . unwrapPositioned) members
94+ properEqual name q || any (go q . unwrapPositioned) members
94− go q (D.TypeInstanceDeclaration ident' _ _ _ _) =
95+ go q (D.TypeInstanceDeclaration ident' _ _ _ _) =
95− identEqual ident' q
96+ identEqual ident' q
96− go _ _ = False
97+ go _ _ = False
97
98
98− properEqual x q = N.runProperName x == q
99+ properEqual x q = N.runProperName x == q
99− identEqual x q = N.runIdent x == q
100+ identEqual x q = N.runIdent x == q
100
101
101goToDefinition :: String -> FilePath -> IO (Maybe SP.SourceSpan)
102goToDefinition :: String -> FilePath -> IO (Maybe SP.SourceSpan)
102goToDefinition q fp = do
103goToDefinition q fp = do
103 m <- runExceptT (parseModuleFromFile fp)
104 m <- runExceptT (parseModuleFromFile fp)
104 case m of
105 case m of
105− Right module' -> return $ getDeclPosition module' q
106+ Right module' -> pure (getDeclPosition module' q)
106− Left _ -> return Nothing
107+ Left _ -> pure Nothing
src/Language/PureScript/Ide/State.hs+3−3
@@ -73,8 +73,8 @@ insertModule externsFile = do
73
73
74insertModule' :: TVar PscIdeState -> ExternsFile -> STM ()
74insertModule' :: TVar PscIdeState -> ExternsFile -> STM ()
75insertModule' st ef = do
75insertModule' st ef = do
76− modifyTVar (st) $ \x ->
76+ modifyTVar st $ \x ->
77 x { externsFiles = M.insert (efModuleName ef) ef (externsFiles x)
77 x { externsFiles = M.insert (efModuleName ef) ef (externsFiles x)
78− , pscStateModules = let (mn, decls ) = convertExterns ef
78+ , pscStateModules = let (mn, decls) = convertExterns ef
79− in M.insert mn decls (pscStateModules x)
79+ in M.insert mn decls (pscStateModules x)
80 }
80 }
src/Language/PureScript/Ide/Types.hs+75−77
@@ -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)
34
34
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
45− }
46+
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)
52
57
53instance ToJSON ExternDecl where
58instance ToJSON ExternDecl where
@@ -63,22 +68,22 @@ instance ToJSON ExternDecl where
63type Module = (ModuleIdent, [ExternDecl])
68type Module = (ModuleIdent, [ExternDecl])
64
69
65data Configuration =
70data Configuration =
66− Configuration {
71+ Configuration
67− confOutputPath :: FilePath
72+ { confOutputPath :: FilePath
68 , confDebug :: Bool
73 , confDebug :: Bool
69 }
74 }
70
75
71data PscIdeEnvironment =
76data PscIdeEnvironment =
72− PscIdeEnvironment {
77+ PscIdeEnvironment
73− envStateVar :: TVar PscIdeState
78+ { envStateVar :: TVar PscIdeState
74 , envConfiguration :: Configuration
79 , envConfiguration :: Configuration
75 }
80 }
76
81
77type PscIde m = (Applicative m, MonadIO m, MonadReader PscIdeEnvironment m)
82type PscIde m = (Applicative m, MonadIO m, MonadReader PscIdeEnvironment m)
78
83
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
84
89
@@ -90,29 +95,32 @@ newtype Completion =
90 deriving (Show,Eq)
95 deriving (Show,Eq)
91
96
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)
98
103
99instance Eq ModuleImport where
104instance Eq ModuleImport where
105+ mi1 == mi2 =
100− mi1 == mi2 = importModuleName mi1 == importModuleName mi2
106+ importModuleName mi1 == importModuleName mi2
101− && importQualifier mi1 == importQualifier mi2
107+ && importQualifier mi1 == importQualifier mi2
102
108
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)
118+ ]
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)
123+ ]
116
124
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 _ = ""
122
130
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
130
138
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]
134
142
135data Success =
143data Success =
136 CompletionResult [Completion]
144 CompletionResult [Completion]
@@ -161,23 +169,22 @@ data PursuitSearchType = Package | Identifier
161
169
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
168
176
169instance FromJSON PursuitQuery where
177instance FromJSON PursuitQuery where
170− parseJSON o = fmap PursuitQuery (parseJSON o)
178+ parseJSON o = PursuitQuery <$> (parseJSON o)
171−
179+
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
179− }
180− deriving (Show,Eq)
187+ deriving (Show,Eq)
181
188
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"
190− return
191− ModuleResponse
197+ pure (ModuleResponse name package)
192− { moduleResponseName = name
193− , moduleResponsePackage = package
194− }
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"
198− return
199− DeclarationResponse
201+ pure (DeclarationResponse declType moduleName ident package)
200− { declarationResponseType = declType
201− , declarationResponseModule = moduleName
202− , declarationResponseIdent = ident
203− , declarationResponsePackage = package
204− }
205 _ -> mzero
202 _ -> mzero
206 parseJSON _ = mzero
203 parseJSON _ = mzero
207
204
@@ -217,7 +214,7 @@ typeParse t = case parse parseType "" t of
217 _ <- string "::"
214 _ <- string "::"
218 spaces
215 spaces
219 type' <- many1 anyChar
216 type' <- many1 anyChar
220− return (unpack name, type')
217+ pure (unpack name, type')
221
218
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 ", )")
229 spaces
226 spaces
230− return (pack ident)
227+ pure (pack ident)
231
228
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) =
236 object
233 object
237− [ "module" .= declarationResponseModule
234+ [ "module" .= module'
238− , "ident" .= declarationResponseIdent
235+ , "ident" .= ident
239− , "type" .= declarationResponseType
236+ , "type" .= type'
240− , "package" .= declarationResponsePackage]
237+ , "package" .= package
238+ ]