|
| 1 | +{-# LANGUAGE DataKinds #-} |
| 2 | +{-# LANGUAGE DisambiguateRecordFields #-} |
| 3 | +{-# LANGUAGE GADTs #-} |
| 4 | +{-# LANGUAGE LambdaCase #-} |
| 5 | +{-# LANGUAGE NamedFieldPuns #-} |
| 6 | +{-# LANGUAGE TypeApplications #-} |
| 7 | +{-# LANGUAGE ViewPatterns #-} |
| 8 | + |
1 | 9 | module Definition (tests) where
|
2 | 10 |
|
3 | 11 | import Control.Lens
|
| 12 | +import Data.Aeson (Result (Success), fromJSON) |
| 13 | +import Data.Bool (bool) |
4 | 14 | import Data.List (isSuffixOf)
|
5 |
| -import Language.LSP.Protocol.Lens |
| 15 | +import Data.Proxy (Proxy (Proxy)) |
| 16 | +import qualified Data.Text as T |
| 17 | +import Language.LSP.Protocol.Lens (uri) |
6 | 18 | import System.Directory
|
| 19 | +import System.Exit (ExitCode(ExitSuccess)) |
7 | 20 | import System.FilePath (splitDirectories)
|
| 21 | +import System.Process (readCreateProcessWithExitCode, shell) |
8 | 22 | import Test.Hls
|
9 | 23 | import Test.Hls.Command
|
10 | 24 |
|
@@ -43,26 +57,57 @@ symbolTests = testGroup "gotoDefinition on symbols"
|
43 | 57 | -- gotoDefinition where the definition is in an external
|
44 | 58 | -- dependency.
|
45 | 59 | , testCase "gotoDefinition in dependency" $ runSession hlsCommand fullCaps "test/testdata/definition" $ do
|
| 60 | + liftIO $ do |
| 61 | + (exitCode, _out, _err) <- readCreateProcessWithExitCode (shell "cabal build") "" |
| 62 | + exitCode @?= ExitSuccess |
46 | 63 | doc <- openDoc "Bar.hs" "haskell"
|
47 |
| - defs <- getDefinitions doc (Position 13 12) |
48 |
| - let expRange = Range (Position 513 0) (Position 513 4) |
| 64 | + _mHieFile <- fileDoneIndexing ["Data", "Aeson", "Types", "Internal.hie"] |
| 65 | + defs <- getDefinitions doc (Position 13 13) |
| 66 | + let expRange = Range (Position 370 13) (Position 370 16) |
49 | 67 | case defs of
|
50 | 68 | InL (Definition (InR [Location fp actualRange])) ->
|
51 | 69 | liftIO $ do
|
52 | 70 | let locationDirectories :: [String]
|
53 | 71 | locationDirectories =
|
54 | 72 | maybe [] splitDirectories $
|
55 | 73 | uriToFilePath fp
|
56 |
| - assertBool "empty not found in Data.Set.Internal" |
57 |
| - $ ["Data", "Set", "Internal.hs"] |
| 74 | + assertBool "empty not found in Data.Aeson.Types.Internal" |
| 75 | + $ ["Data", "Aeson", "Types", "Internal.hs"] |
58 | 76 | `isSuffixOf` locationDirectories
|
59 | 77 | actualRange @?= expRange
|
60 | 78 | wrongLocation ->
|
61 | 79 | liftIO $
|
62 |
| - assertFailure $ "Wrong location for Set.empty: " |
| 80 | + assertFailure $ "Wrong location for Null: " |
63 | 81 | ++ show wrongLocation
|
64 | 82 | ]
|
65 | 83 |
|
| 84 | +fileDoneIndexing :: [String] -> Session (Maybe FilePath) |
| 85 | +fileDoneIndexing fpSuffix = |
| 86 | + skipManyTill anyMessage (indexedFile <|> doneIndexing) |
| 87 | + where |
| 88 | + indexedFile :: Session (Maybe FilePath) |
| 89 | + indexedFile = do |
| 90 | + NotMess TNotificationMessage{_params} <- |
| 91 | + customNotification (Proxy @"ghcide/reference/ready") |
| 92 | + case fromJSON _params of |
| 93 | + Success fp -> do |
| 94 | + let fpDirs :: [String] |
| 95 | + fpDirs = splitDirectories fp |
| 96 | + bool empty (pure (Just fp)) $ |
| 97 | + fpSuffix `isSuffixOf` fpDirs |
| 98 | + other -> error $ "Failed to parse ghcide/reference/ready file: " <> show other |
| 99 | + doneIndexing :: Session (Maybe FilePath) |
| 100 | + doneIndexing = satisfyMaybe $ \case |
| 101 | + FromServerMess SMethod_Progress (TNotificationMessage _ _ (ProgressParams t (preview _workDoneProgressEnd -> Just params))) -> |
| 102 | + case params of |
| 103 | + (WorkDoneProgressEnd _ m) -> |
| 104 | + case m of |
| 105 | + Just message -> bool Nothing (Just Nothing) $ |
| 106 | + "Finished indexing" `T.isPrefixOf` message |
| 107 | + _ -> Nothing |
| 108 | + _ -> Nothing |
| 109 | + _ -> Nothing |
| 110 | + |
66 | 111 | -- -----------------------------------
|
67 | 112 |
|
68 | 113 | moduleTests :: TestTree
|
|
0 commit comments