Skip to content

Commit f0b7360

Browse files
committed
Add check for indexing message
1 parent a562811 commit f0b7360

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

haskell-language-server.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ test-suite func-test
568568
, containers
569569
, unordered-containers
570570
, row-types
571+
, process
571572

572573
hs-source-dirs: test/functional test/utils
573574

test/functional/Definition.hs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DisambiguateRecordFields #-}
3+
{-# LANGUAGE GADTs #-}
4+
{-# LANGUAGE LambdaCase #-}
5+
{-# LANGUAGE NamedFieldPuns #-}
6+
{-# LANGUAGE TypeApplications #-}
7+
{-# LANGUAGE ViewPatterns #-}
8+
19
module Definition (tests) where
210

311
import Control.Lens
12+
import Data.Aeson (Result (Success), fromJSON)
13+
import Data.Bool (bool)
414
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)
618
import System.Directory
19+
import System.Exit (ExitCode(ExitSuccess))
720
import System.FilePath (splitDirectories)
21+
import System.Process (readCreateProcessWithExitCode, shell)
822
import Test.Hls
923
import Test.Hls.Command
1024

@@ -43,26 +57,57 @@ symbolTests = testGroup "gotoDefinition on symbols"
4357
-- gotoDefinition where the definition is in an external
4458
-- dependency.
4559
, 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
4663
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)
4967
case defs of
5068
InL (Definition (InR [Location fp actualRange])) ->
5169
liftIO $ do
5270
let locationDirectories :: [String]
5371
locationDirectories =
5472
maybe [] splitDirectories $
5573
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"]
5876
`isSuffixOf` locationDirectories
5977
actualRange @?= expRange
6078
wrongLocation ->
6179
liftIO $
62-
assertFailure $ "Wrong location for Set.empty: "
80+
assertFailure $ "Wrong location for Null: "
6381
++ show wrongLocation
6482
]
6583

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+
66111
-- -----------------------------------
67112

68113
moduleTests :: TestTree

test/testdata/definition/Bar.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Bar where
22

3-
import Data.Set (Set, empty)
3+
import Data.Aeson (Value(Null))
44

55
a = 42
66

@@ -10,5 +10,5 @@ a = 42
1010
-- the number of lines in Foo.hs.
1111
b = 43
1212

13-
emptySet :: Set Integer
14-
emptySet = empty
13+
nullValue :: Value
14+
nullValue = Null
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
packages: .
22
source-repository-package
33
type:git
4-
location: https://github.com/haskell/containers.git
5-
tag: cde5e58b12e744ca4742db71443bee6584dfd1e9
4+
location: https://github.com/haskell/aeson.git
5+
tag: fc5f5bb067613a273de358f09760b635d6f78c82

test/testdata/definition/definitions.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ library
88
other-modules: Bar
99
default-language: Haskell2010
1010
build-depends: base
11-
, containers
11+
, aeson
1212
ghc-options: -fwrite-ide-info

0 commit comments

Comments
 (0)