-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Dependency where | ||
|
||
import Control.Concurrent.Async (AsyncCancelled (..)) | ||
|
||
asyncCancelled :: AsyncCancelled | ||
asyncCancelled = AsyncCancelled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: dependency | ||
version: 0.1.0.0 | ||
cabal-version: 2.0 | ||
build-type: Simple | ||
|
||
library | ||
exposed-modules: Dependency | ||
default-language: Haskell2010 | ||
build-depends: base | ||
, async == 2.2.4 | ||
ghc-options: -fwrite-ide-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cradle: | ||
cabal: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE ExplicitNamespaces #-} | ||
{-# LANGUAGE GADTs #-} | ||
module Dependency where | ||
|
||
import qualified Control.Applicative as Applicative | ||
import Control.Applicative.Combinators (skipManyTill) | ||
import Control.Monad.IO.Class (liftIO) | ||
import qualified Data.Aeson as A | ||
import Data.Bool (bool) | ||
import Data.List (isSuffixOf) | ||
import Data.Proxy (Proxy (..)) | ||
import Language.LSP.Protocol.Message (TCustomMessage (NotMess), | ||
TNotificationMessage (..)) | ||
import Language.LSP.Protocol.Types (Definition (..), | ||
Location (..), Position (..), | ||
Range (..), | ||
type (|?) (InL, InR), | ||
uriToFilePath) | ||
import Language.LSP.Test (Session, anyMessage, | ||
customNotification, | ||
getDefinitions, openDoc) | ||
import System.FilePath (splitDirectories, (<.>), | ||
(</>)) | ||
import Test.Tasty (TestTree, testGroup) | ||
import Test.Tasty.HUnit (assertBool, assertFailure, | ||
(@?=)) | ||
import TestUtils (testSessionWithExtraFiles) | ||
|
||
tests :: TestTree | ||
tests = | ||
testGroup "gotoDefinition for dependencies" | ||
[ dependencyTest | ||
] | ||
where | ||
dependencyTest :: TestTree | ||
dependencyTest = testSessionWithExtraFiles "dependency" "gotoDefinition in async" $ | ||
\dir -> do | ||
doc <- openDoc (dir </> "Dependency" <.> "hs") "haskell" | ||
_hieFile <- fileDoneIndexing ["Control", "Concurrent", "Async.hie"] | ||
defs <- getDefinitions doc (Position 5 20) | ||
let expRange = Range (Position 430 22) (Position 430 36) | ||
case defs of | ||
InL (Definition (InR [Location fp actualRange])) -> | ||
liftIO $ do | ||
let locationDirectories :: [String] | ||
locationDirectories = | ||
maybe [] splitDirectories $ | ||
uriToFilePath fp | ||
assertBool "AsyncCancelled found in a module that is not Control.Concurrent Async" | ||
$ ["Control", "Concurrent", "Async.hs"] | ||
`isSuffixOf` locationDirectories | ||
actualRange @?= expRange | ||
wrongLocation -> | ||
liftIO $ | ||
assertFailure $ "Wrong location for AsyncCancelled: " | ||
++ show wrongLocation | ||
fileDoneIndexing :: [String] -> Session FilePath | ||
fileDoneIndexing fpSuffix = | ||
skipManyTill anyMessage indexedFile | ||
where | ||
indexedFile :: Session FilePath | ||
indexedFile = do | ||
NotMess TNotificationMessage{_params} <- | ||
customNotification (Proxy @"ghcide/reference/ready") | ||
case A.fromJSON _params of | ||
A.Success fp -> do | ||
let fpDirs :: [String] | ||
fpDirs = splitDirectories fp | ||
bool Applicative.empty (pure fp) $ | ||
fpSuffix `isSuffixOf` fpDirs | ||
other -> error $ "Failed to parse ghcide/reference/ready file: " <> show other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters