@@ -20,7 +20,7 @@ module Experiments
20
20
, exampleToOptions
21
21
) where
22
22
import Control.Applicative.Combinators (skipManyTill )
23
- import Control.Exception.Safe
23
+ import Control.Exception.Safe ( IOException , handleAny , try )
24
24
import Control.Monad.Extra
25
25
import Control.Monad.IO.Class
26
26
import Data.Aeson (Value (Null ))
@@ -41,6 +41,7 @@ import System.FilePath ((</>), (<.>))
41
41
import System.Process
42
42
import System.Time.Extra
43
43
import Text.ParserCombinators.ReadP (readP_to_S )
44
+ import Development.Shake (cmd_ , CmdOption (Cwd , FileStdout ))
44
45
45
46
charEdit :: Position -> TextDocumentContentChangeEvent
46
47
charEdit p =
@@ -423,19 +424,24 @@ setup :: HasConfig => IO SetupResult
423
424
setup = do
424
425
-- when alreadyExists $ removeDirectoryRecursive examplesPath
425
426
benchDir <- case example ? config of
426
- UsePackage {.. } -> return examplePath
427
+ UsePackage {.. } -> do
428
+ let hieYamlPath = examplePath </> " hie.yaml"
429
+ alreadyExists <- doesFileExist hieYamlPath
430
+ unless alreadyExists $
431
+ cmd_ (Cwd examplePath) (FileStdout hieYamlPath) (" gen-hie" :: String )
432
+ return examplePath
427
433
GetPackage {.. } -> do
428
434
let path = examplesPath </> package
429
435
package = exampleName <> " -" <> showVersion exampleVersion
436
+ hieYamlPath = path </> " hie.yaml"
430
437
alreadySetup <- doesDirectoryExist path
431
438
unless alreadySetup $
432
439
case buildTool ? config of
433
440
Cabal -> do
434
441
let cabalVerbosity = " -v" ++ show (fromEnum (verbose ? config))
435
442
callCommandLogging $ " cabal get " <> cabalVerbosity <> " " <> package <> " -d " <> examplesPath
436
- writeFile
437
- (path </> " hie.yaml" )
438
- (" cradle: {cabal: {component: " <> exampleName <> " }}" )
443
+ let hieYamlPath = path </> " hie.yaml"
444
+ cmd_ (Cwd path) (FileStdout hieYamlPath) (" gen-hie" :: String )
439
445
-- Need this in case there is a parent cabal.project somewhere
440
446
writeFile
441
447
(path </> " cabal.project" )
@@ -464,9 +470,7 @@ setup = do
464
470
]
465
471
)
466
472
467
- writeFile
468
- (path </> " hie.yaml" )
469
- (" cradle: {stack: {component: " <> show (exampleName <> " :lib" ) <> " }}" )
473
+ cmd_ (Cwd path) (FileStdout hieYamlPath) (" gen-hie" :: String ) [" --stack" :: String ]
470
474
return path
471
475
472
476
whenJust (shakeProfiling ? config) $ createDirectoryIfMissing True
@@ -498,22 +502,21 @@ setupDocumentContents config =
498
502
499
503
-- Find an identifier defined in another file in this project
500
504
symbols <- getDocumentSymbols doc
501
- case symbols of
502
- Left [DocumentSymbol {_children = Just (List symbols)}] -> do
503
- let endOfImports = case symbols of
504
- DocumentSymbol {_kind = SkModule , _name = " imports" , _range } : _ ->
505
- Position (succ $ _line $ _end _range) 4
506
- DocumentSymbol {_range} : _ -> _start _range
507
- [] -> error " Module has no symbols"
508
- contents <- documentContents doc
509
-
510
- identifierP <- searchSymbol doc contents endOfImports
511
-
512
- return $ DocumentPositions {.. }
513
- other ->
514
- error $ " symbols: " <> show other
515
-
516
-
505
+ let endOfImports = case symbols of
506
+ Left symbols | Just x <- findEndOfImports symbols -> x
507
+ _ -> error $ " symbols: " <> show symbols
508
+ contents <- documentContents doc
509
+ identifierP <- searchSymbol doc contents endOfImports
510
+ return $ DocumentPositions {.. }
511
+
512
+ findEndOfImports :: [DocumentSymbol ] -> Maybe Position
513
+ findEndOfImports (DocumentSymbol {_kind = SkModule , _name = " imports" , _range} : _) =
514
+ Just $ Position (succ $ _line $ _end _range) 4
515
+ findEndOfImports [DocumentSymbol {_kind = SkFile , _children = Just (List cc)}] =
516
+ findEndOfImports cc
517
+ findEndOfImports (DocumentSymbol {_range} : _) =
518
+ Just $ _start _range
519
+ findEndOfImports _ = Nothing
517
520
518
521
--------------------------------------------------------------------------------------------
519
522
0 commit comments