X-Git-Url: http://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest%2FScript.hs;h=ce4466429c853aafe7e292d5b3a13d53d0b873e0;hb=ae334dce13ab47fd20b976a17b1f296e082c7531;hp=f9721b0e0298407a58f743b2cb330d8e3ab74b2b;hpb=92f1ae3d69a580eee74755a38a647e27c4f164ff;p=lsp-test.git diff --git a/src/Language/Haskell/LSP/Test/Script.hs b/src/Language/Haskell/LSP/Test/Script.hs index f9721b0..ce44664 100644 --- a/src/Language/Haskell/LSP/Test/Script.hs +++ b/src/Language/Haskell/LSP/Test/Script.hs @@ -1,25 +1,12 @@ -module Main where +module Language.Haskell.LSP.Test.Script where import Control.Applicative ( (<|>), some ) import Control.Monad -import Data.Aeson import Data.Char import qualified Data.Text as T import qualified Data.HashMap.Lazy as HM -import Data.Maybe import Data.Scientific import Text.ParserCombinators.ReadP -import System.Environment -import System.FilePath -import System.Directory -import Language.Haskell.LSP.Test (openDoc, sendRequest', sendNotification, sendResponse) -import Language.Haskell.LSP.Test.Session -import Language.Haskell.LSP.Test.Machine -import Language.Haskell.LSP.Test.Parsing (toJSONMsg) -import Language.Haskell.LSP.Messages -import Language.Haskell.LSP.TH.MessageFuncs -import qualified Language.Haskell.LSP.Types as LSP -import Debug.Trace data Block = Block String Wait [Action] deriving Show @@ -175,51 +162,3 @@ parseScript str = skipSpaces eof return blocks \ No newline at end of file - -main = do - fileName <- head <$> getArgs - blocks <- parseScript <$> readFile fileName - print blocks - rootDir <- getCurrentDirectory - runBlocks rootDir blocks - - -runBlocks :: FilePath -> [Block] -> IO () -runBlocks rootDir blocks = runMachine rootDir (map convertBlock blocks) >>= putStrLn - where - convertBlock :: Block -> (String, FromServerMessage -> Bool, [Session ()]) - convertBlock (Block name w actions) = (name, mkWait w, map mkAction actions) - - mkWait :: Wait -> FromServerMessage -> Bool - mkWait WaitAny _ = True - mkWait (WaitPred preds) x = all (`mkPred` x) preds - - mkPred :: Predicate -> (FromServerMessage -> Bool) - mkPred (Predicate accessor comparison) msg = - let (Object obj) = toJSONMsg msg in comp (access obj accessor) comparison - - comp (Just (String str)) (EqualsString expected) = str == T.pack expected - comp (Just (Number num)) (EqualsNumber expected) = num == expected - comp _ _ = False - - access :: Object -> Accessor -> Maybe Value - access obj (AccessorTerm prop) = traceShowId $ HM.lookup (T.pack prop) obj - access obj (Accessor prop next) = - case HM.lookup (T.pack prop) obj of - Just (Object nextObj) -> access nextObj next - _ -> Nothing - - mkAction :: Action -> Session () - - mkAction (OpenDoc fp fileType) = void $ openDoc fp fileType - - mkAction (Request identifier methodStr ps) = void $ sendRequest' (strToMethod methodStr) (paramToValue ps) - mkAction (Reply methodStr ps) = undefined -- TODO - mkAction (Notify methodStr ps) = void $ sendNotification (strToMethod methodStr) (paramToValue ps) - - strToMethod str = case fromJSON (String $ T.pack str) of - Success x -> x - Error _ -> error $ str ++ " is not a valid method" - paramToValue (ParamString str) = String str - paramToValue (ParamUri uri) = toJSON $ LSP.filePathToUri (rootDir uri) - paramToValue (ParamObject obj) = Object (HM.map paramToValue obj)