git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #2324 from nwolverson/pursuit-json-update

[psc-ide] Update pursuit JSON parsing

commitd41994a26b89170610fb62e39c50a9269e4ac5b7 authorPhil Freeman <paf31@cantab.net> dateThu 22 Sep 2016, 21:17 (10 years ago) parent0ad1005820b12b
1 file changed+9−32
src/Language/PureScript/Ide/Types.hs+9−32
src/Language/PureScript/Ide/Types.hs+9−32
@@ -25,8 +25,6 @@ import Data.Map.Lazy as M
2525import qualified Language.PureScript.Errors.JSON as P
2626import qualified Language.PureScript as P
2727import Language.PureScript.Ide.Conversions
28−import Text.Parsec as Parsec
29−import Text.Parsec.Text
3028
3129type ModuleIdent = Text
3230
@@ -209,9 +207,9 @@ data PursuitResponse =
209207 -- | A Pursuit Response for a module. Consists of the modules name and the
210208 -- package it belongs to
211209 ModuleResponse ModuleIdent Text
212− -- | A Pursuit Response for a declaration. Consist of the declarations type,
213− -- module, name and package
214− | DeclarationResponse Text ModuleIdent Text Text
210+ -- | A Pursuit Response for a declaration. Consist of the declaration's
211+ -- module, name, package, type summary text
212+ | DeclarationResponse Text ModuleIdent Text (Maybe Text) Text
215213 deriving (Show,Eq)
216214
217215instance FromJSON PursuitResponse where
@@ -225,42 +223,21 @@ instance FromJSON PursuitResponse where
225223 pure (ModuleResponse name package)
226224 "declaration" -> do
227225 moduleName <- info .: "module"
228− Right (ident, declType) <- typeParse <$> o .: "text"
229− pure (DeclarationResponse declType moduleName ident package)
226+ ident <- info .: "title"
227+ (text :: Text) <- o .: "text"
228+ typ <- info .:? "typeText"
229+ pure (DeclarationResponse moduleName ident package typ text)
230230 _ -> mzero
231231 parseJSON _ = mzero
232232
233−
234−typeParse :: Text -> Either Text (Text, Text)
235−typeParse t = case parse parseType "" t of
236− Right (x,y) -> Right (x, y)
237− Left err -> Left (show err)
238− where
239− parseType :: Parser (Text, Text)
240− parseType = do
241− name <- identifier
242− _ <- string "::"
243− spaces
244− type' <- many1 anyChar
245− pure (name, toS type')
246−
247− identifier :: Parser Text
248− identifier = do
249− spaces
250− ident <-
251− -- necessary for being able to parse the following ((++), concat)
252− between (char '(') (char ')') (many1 (noneOf ", )")) Parsec.<|>
253− many1 (noneOf ", )")
254− spaces
255− pure (toS ident)
256−
257233instance ToJSON PursuitResponse where
258234 toJSON (ModuleResponse name package) =
259235 object ["module" .= name, "package" .= package]
260− toJSON (DeclarationResponse module' ident type' package) =
236+ toJSON (DeclarationResponse module' ident package type' text) =
261237 object
262238 [ "module" .= module'
263239 , "ident" .= ident
264240 , "type" .= type'
265241 , "package" .= package
242+ , "text" .= text
266243 ]