Skip to content

Commit eda57f5

Browse files
committed
backwards compat.
1 parent 138bfb2 commit eda57f5

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

ghcide/bench/lib/Experiments.hs

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Control.Exception.Safe (IOException, handleAny, try)
2626
import Control.Monad.Extra
2727
import Control.Monad.IO.Class
2828
import Data.Aeson (Value (Null), toJSON)
29+
import Data.Either (fromRight)
2930
import Data.List
3031
import Data.Maybe
3132
import qualified Data.Text as T
@@ -496,10 +497,10 @@ runBench runSess b = handleAny (\e -> print e >> return badRun)
496497
(userWaits, delayedWork) = fromMaybe (0,0) result
497498

498499
rulesTotal <- length <$> getStoredKeys
499-
rulesBuilt <- length <$> getBuildKeysBuilt
500-
rulesChanged <- length <$> getBuildKeysChanged
501-
rulesVisited <- length <$> getBuildKeysVisited
502-
edgesTotal <- getBuildEdgesCount
500+
rulesBuilt <- either (const 0) length <$> getBuildKeysBuilt
501+
rulesChanged <- either (const 0) length <$> getBuildKeysChanged
502+
rulesVisited <- either (const 0) length <$> getBuildKeysVisited
503+
edgesTotal <- fromRight 0 <$> getBuildEdgesCount
503504

504505
return BenchRun {..}
505506

ghcide/test/src/Development/IDE/Test.hs

+19-11
Original file line numberDiff line numberDiff line change
@@ -181,32 +181,40 @@ canonicalizeUri uri = filePathToUri <$> canonicalizePath (fromJust (uriToFilePat
181181
diagnostic :: Session (NotificationMessage TextDocumentPublishDiagnostics)
182182
diagnostic = LspTest.message STextDocumentPublishDiagnostics
183183

184-
callTestPlugin :: (A.FromJSON b) => TestRequest -> Session b
185-
callTestPlugin cmd = do
184+
tryCallTestPlugin :: (A.FromJSON b) => TestRequest -> Session (Either ResponseError b)
185+
tryCallTestPlugin cmd = do
186186
let cm = SCustomMethod "test"
187187
waitId <- sendRequest cm (A.toJSON cmd)
188188
ResponseMessage{_result} <- skipManyTill anyMessage $ responseForId cm waitId
189189
return $ case _result of
190190
Left (ResponseError t err _) -> error $ show t <> ": " <> T.unpack err
191191
Right json -> case A.fromJSON json of
192-
A.Success a -> a
192+
A.Success a -> Right a
193193
A.Error e -> error e
194194

195+
callTestPlugin :: (A.FromJSON b) => TestRequest -> Session b
196+
callTestPlugin cmd = do
197+
res <- tryCallTestPlugin cmd
198+
case res of
199+
Left (ResponseError t err _) -> error $ show t <> ": " <> T.unpack err
200+
Right a -> pure a
201+
202+
195203
waitForAction :: String -> TextDocumentIdentifier -> Session WaitForIdeRuleResult
196204
waitForAction key TextDocumentIdentifier{_uri} =
197205
callTestPlugin (WaitForIdeRule key _uri)
198206

199-
getBuildKeysBuilt :: Session [T.Text]
200-
getBuildKeysBuilt = callTestPlugin GetBuildKeysBuilt
207+
getBuildKeysBuilt :: Session (Either ResponseError [T.Text])
208+
getBuildKeysBuilt = tryCallTestPlugin GetBuildKeysBuilt
201209

202-
getBuildKeysVisited :: Session [T.Text]
203-
getBuildKeysVisited = callTestPlugin GetBuildKeysVisited
210+
getBuildKeysVisited :: Session (Either ResponseError [T.Text])
211+
getBuildKeysVisited = tryCallTestPlugin GetBuildKeysVisited
204212

205-
getBuildKeysChanged :: Session [T.Text]
206-
getBuildKeysChanged = callTestPlugin GetBuildKeysChanged
213+
getBuildKeysChanged :: Session (Either ResponseError [T.Text])
214+
getBuildKeysChanged = tryCallTestPlugin GetBuildKeysChanged
207215

208-
getBuildEdgesCount :: Session Int
209-
getBuildEdgesCount = callTestPlugin GetBuildEdgesCount
216+
getBuildEdgesCount :: Session (Either ResponseError Int)
217+
getBuildEdgesCount = tryCallTestPlugin GetBuildEdgesCount
210218

211219
getInterfaceFilesDir :: TextDocumentIdentifier -> Session FilePath
212220
getInterfaceFilesDir TextDocumentIdentifier{_uri} = callTestPlugin (GetInterfaceFilesDir _uri)

0 commit comments

Comments
 (0)