Skip to content

Commit

Permalink
Make sure that /diagnostics are returned in the correct order
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Jan 29, 2025
1 parent 87646c0 commit a88b411
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ReadHandle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ partialMessageStartsWithOneOf :: [ByteString] -> ByteString -> Bool
partialMessageStartsWithOneOf xs x = any ($ x) $ map partialMessageStartsWith xs

getResult :: Extract a -> ReadHandle -> (ByteString -> IO ()) -> IO (ByteString, [a])
getResult extract h echo = do
getResult extract h echo = fmap reverse <$> do
ref <- newIORef []

let
Expand Down
4 changes: 2 additions & 2 deletions src/Trigger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ trigger session hooks = runWriterT (runExceptT go) >>= \ case
go :: Trigger ()
go = do
runHook hooks.beforeReload
(output, (r, err)) <- Session.reload session
tell (output, err)
(output, (r, diagnostics)) <- Session.reload session
tell (output, diagnostics)
case r of
Failed -> do
echo $ withColor Red "RELOADING FAILED" <> "\n"
Expand Down
12 changes: 8 additions & 4 deletions test/ReadHandleSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,24 @@ spec = do
span :: Maybe Span
span = Just $ Span "Foo.hs" start start

err :: Diagnostic
err = (diagnostic Error) { span }
err1 :: Diagnostic
err1 = (diagnostic Error) { span }

err2 :: Diagnostic
err2 = err1 { code = Just 23 }

chunks :: [ByteString]
chunks = [
"foo\n"
, "bar\n"
, to_json err <> "\n"
, to_json err1 <> "\n"
, "baz\n"
, to_json err2 { code = Just 23 } <> "\n"
, marker
]
withRandomChunkSizes chunks $ \ h -> do
fmap mconcat . withSpy $ \ echo -> do
getResult extract h echo `shouldReturn` ("foo\nbar\nbaz\n", [err])
getResult extract h echo `shouldReturn` ("foo\nbar\nbaz\n", [err1, err2])
`shouldReturn` "foo\nbar\nbaz\n"

context "with a partial match" $ do
Expand Down

0 comments on commit a88b411

Please sign in to comment.