X-Git-Url: http://git.lukelau.me/?p=opengl.git;a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest%2FReplay.hs;h=0be0c54d3736d4e90d920271af8125a4107f327b;hp=7def859a2e9bda826d40d10602bad9f6a9897afc;hb=d25de2bf28d472df5d1d3e050090d243247dab1b;hpb=1c305ff677a2b78abe767f1bdfc345f1580dba52 diff --git a/src/Language/Haskell/LSP/Test/Replay.hs b/src/Language/Haskell/LSP/Test/Replay.hs index 7def859..0be0c54 100644 --- a/src/Language/Haskell/LSP/Test/Replay.hs +++ b/src/Language/Haskell/LSP/Test/Replay.hs @@ -11,7 +11,6 @@ import Control.Exception import Control.Monad.IO.Class import qualified Data.ByteString.Lazy.Char8 as B import qualified Data.Text as T -import Data.UUID import Language.Haskell.LSP.Capture import Language.Haskell.LSP.Messages import Language.Haskell.LSP.Types hiding (error) @@ -22,7 +21,6 @@ import Control.Lens hiding (List) import Control.Monad import System.IO import System.FilePath -import System.Random import Language.Haskell.LSP.Test import Language.Haskell.LSP.Test.Files import Language.Haskell.LSP.Test.Decoding @@ -46,7 +44,7 @@ replaySession serverExe sessionDir = do withServer serverExe $ \serverIn serverOut pid -> do - events <- swapUUIDs pid <$> swapFiles sessionDir unswappedEvents + events <- swapCommands pid <$> swapFiles sessionDir unswappedEvents let clientEvents = filter isClientMsg events serverEvents = filter isServerMsg events @@ -199,18 +197,26 @@ shouldSkip (NotShowMessage _) = True shouldSkip (ReqShowMessage _) = True shouldSkip _ = False --- | Swaps out the expected UUIDs to match the current process ID -swapUUIDs :: Int -> [Event] -> [Event] -swapUUIDs _ [] = [] -swapUUIDs pid (FromServer t (RspInitialize rsp):xs) = FromServer t (RspInitialize swapped):swapUUIDs pid xs +-- | Swaps out any commands uniqued with process IDs to match the specified process ID +swapCommands :: Int -> [Event] -> [Event] +swapCommands _ [] = [] + +swapCommands pid (FromClient t (ReqExecuteCommand req):xs) = FromClient t (ReqExecuteCommand swapped):swapCommands pid xs + where swapped = params . command .~ newCmd $ req + newCmd = swapPid pid (req ^. params . command) + +swapCommands pid (FromServer t (RspInitialize rsp):xs) = FromServer t (RspInitialize swapped):swapCommands pid xs where swapped = case newCommands of Just cmds -> result . _Just . capabilities . executeCommandProvider . _Just . commands .~ cmds $ rsp Nothing -> rsp oldCommands = rsp ^? result . _Just . capabilities . executeCommandProvider . _Just . commands - newCommands = fmap (fmap swap) oldCommands - swap cmd - | isUuid cmd = T.append uuid $ T.dropWhile (/= ':') cmd - | otherwise = cmd - uuid = toText $ fst $ random $ mkStdGen pid - isUuid = isJust . fromText . T.takeWhile (/= ':') -swapUUIDs pid (x:xs) = x:swapUUIDs pid xs \ No newline at end of file + newCommands = fmap (fmap (swapPid pid)) oldCommands + +swapCommands pid (x:xs) = x:swapCommands pid xs + +hasPid :: T.Text -> Bool +hasPid = (>= 2) . T.length . T.filter (':' ==) +swapPid :: Int -> T.Text -> T.Text +swapPid pid t + | hasPid t = T.append (T.pack $ show pid) $ T.dropWhile (/= ':') t + | otherwise = t \ No newline at end of file