Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 30908ee

Browse files
authored
Merge pull request #1291 from alanz/stack-2.1.1
Stack 2.1.1
2 parents e300e64 + 837983e commit 30908ee

File tree

21 files changed

+170
-49
lines changed

21 files changed

+170
-49
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,7 @@ test-results/
6969
.vscode
7070

7171
# shake build information
72-
_build/
72+
_build/
73+
74+
# stack 2.1 stack.yaml lock files
75+
stack*.yaml.lock

haskell-ide-engine.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ library
9595
, transformers
9696
, unordered-containers
9797
, vector
98+
, versions
9899
, yaml >= 0.8.31
99100
ghc-options: -Wall -Wredundant-constraints
100101
if flag(pedantic)

src/Haskell/Ide/Engine/Plugin/Base.hs

+23-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Data.Maybe
1515
import Data.Semigroup
1616
#endif
1717
import qualified Data.Text as T
18+
import qualified Data.Versions as V
1819
import Development.GitRev (gitCommitCount)
1920
import Distribution.System (buildArch)
2021
import Distribution.Text (display)
@@ -126,14 +127,34 @@ getProjectGhcVersion = do
126127
then tryCommand "ghc --numeric-version"
127128
else return "No System GHC found"
128129

129-
tryCommand cmd =
130-
init <$> readCreateProcess (shell cmd) ""
130+
131+
tryCommand :: String -> IO String
132+
tryCommand cmd =
133+
init <$> readCreateProcess (shell cmd) ""
131134

132135
hieGhcVersion :: String
133136
hieGhcVersion = VERSION_ghc
134137

135138
-- ---------------------------------------------------------------------
136139

140+
getStackVersion :: IO (Maybe V.Version)
141+
getStackVersion = do
142+
isStackInstalled <- isJust <$> findExecutable "stack"
143+
if isStackInstalled
144+
then do
145+
versionStr <- tryCommand "stack --numeric-version"
146+
case V.version (T.pack versionStr) of
147+
Left _err -> return Nothing
148+
Right v -> return (Just v)
149+
else return Nothing
150+
151+
stack193Version :: V.Version
152+
stack193Version = case V.version "1.9.3" of
153+
Left err -> error $ "stack193Version:err=" ++ show err
154+
Right v -> v
155+
156+
-- ---------------------------------------------------------------------
157+
137158
checkCabalInstall :: IO Bool
138159
checkCabalInstall = isJust <$> findExecutable "cabal"
139160

src/Haskell/Ide/Engine/Plugin/Liquid.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ generateDiagnosics cb uri file = do
156156

157157
-- ---------------------------------------------------------------------
158158

159-
-- Find and run the liquid haskell executable
159+
-- | Find and run the liquid haskell executable
160160
runLiquidHaskell :: FilePath -> IO (Maybe (ExitCode,[String]))
161161
runLiquidHaskell fp = do
162162
mexe <- findExecutable "liquid"
@@ -168,13 +168,14 @@ runLiquidHaskell fp = do
168168
let cmd = lh ++ " --json \"" ++ fp ++ "\""
169169
dir = takeDirectory fp
170170
cp = (shell cmd) { cwd = Just dir }
171-
logm $ "runLiquidHaskell:cmd=[" ++ cmd ++ "]"
171+
-- logm $ "runLiquidHaskell:cmd=[" ++ cmd ++ "]"
172172
mpp <- lookupEnv "GHC_PACKAGE_PATH"
173+
-- logm $ "runLiquidHaskell:mpp=[" ++ show mpp ++ "]"
173174
(ec,o,e) <- bracket
174175
(unsetEnv "GHC_PACKAGE_PATH")
175176
(\_ -> mapM_ (setEnv "GHC_PACKAGE_PATH") mpp)
176177
(\_ -> readCreateProcessWithExitCode cp "")
177-
logm $ "runLiquidHaskell:v=" ++ show (ec,o,e)
178+
-- logm $ "runLiquidHaskell:v=" ++ show (ec,o,e)
178179
return $ Just (ec,[o,e])
179180

180181
-- ---------------------------------------------------------------------

test/functional/FunctionalCodeActionsSpec.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ spec = describe "code actions" $ do
293293

294294
contents <- getDocumentEdit . TextDocumentIdentifier =<< getDocUri "package.yaml"
295295
liftIO $
296-
T.lines contents !! 21 `shouldSatisfy` T.isSuffixOf "zlib"
296+
T.lines contents !! 23 `shouldSatisfy` T.isSuffixOf "zlib"
297297

298298
-- -----------------------------------
299299

test/testdata/addPackageTest/hybrid-exe/package.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ description: Please see the README on GitHub at <https://github.com/gith
2121

2222
library:
2323
source-dirs: src
24+
dependencies:
25+
- base
2426

2527
executables:
2628
asdf-exe:
@@ -31,4 +33,5 @@ executables:
3133
- -rtsopts
3234
- -with-rtsopts=-N
3335
dependencies:
34-
- asdf
36+
- base
37+
- asdf

test/testdata/wrapper/8.2.1/Setup.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Initial cabal1.cabal generated by cabal init. For further
2+
-- documentation, see http://haskell.org/cabal/users-guide/
3+
4+
name: cabal1
5+
version: 0.1.0.0
6+
-- synopsis:
7+
-- description:
8+
license: PublicDomain
9+
-- license-file: LICENSE
10+
author: Alan Zimmerman
11+
maintainer: [email protected]
12+
-- copyright:
13+
-- category:
14+
build-type: Simple
15+
-- extra-source-files:
16+
-- cabal-helper for cabal 2.2/GHC 8.4 needs a cabal version >= 2
17+
cabal-version: >=2.0
18+
19+
executable cabal1
20+
main-is: main.hs
21+
-- other-modules:
22+
-- other-extensions:
23+
build-depends: base >=4.6 && <5
24+
hs-source-dirs: src
25+
default-language: Haskell2010
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Foo.Bar where
2+
3+
baz = 6
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- | Testing that HaRe can find source files from a cabal file
2+
3+
import qualified Foo.Bar as B
4+
5+
main = putStrLn "foo"
6+
7+
baz = 3 + B.baz
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Initial cabal1.cabal generated by cabal init. For further
2+
-- documentation, see http://haskell.org/cabal/users-guide/
3+
4+
name: cabal1
5+
version: 0.1.0.0
6+
-- synopsis:
7+
-- description:
8+
license: PublicDomain
9+
-- license-file: LICENSE
10+
author: Alan Zimmerman
11+
maintainer: [email protected]
12+
-- copyright:
13+
-- category:
14+
build-type: Simple
15+
-- extra-source-files:
16+
-- cabal-helper for cabal 2.2/GHC 8.4 needs a cabal version >= 2
17+
cabal-version: >=2.0
18+
19+
executable cabal1
20+
main-is: main.hs
21+
-- other-modules:
22+
-- other-extensions:
23+
build-depends: base >=4.6 && <5
24+
hs-source-dirs: src
25+
default-language: Haskell2010
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Foo.Bar where
2+
3+
baz = 6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- | Testing that HaRe can find source files from a cabal file
2+
3+
import qualified Foo.Bar as B
4+
5+
main = putStrLn "foo"
6+
7+
baz = 3 + B.baz

test/unit/GhcModPluginSpec.hs

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import qualified Data.Map as Map
99
-- import Data.Monoid
1010
#endif
1111
import qualified Data.Set as S
12-
-- import qualified Data.Text as T
12+
import qualified Data.Text as T
1313
import Haskell.Ide.Engine.Ghc
1414
import Haskell.Ide.Engine.MonadTypes
1515
import Haskell.Ide.Engine.Plugin.GhcMod
@@ -44,8 +44,14 @@ ghcmodSpec =
4444
fp <- makeAbsolute "./FileWithWarning.hs"
4545
let act = setTypecheckedModule arg
4646
arg = filePathToUri fp
47+
IdeResultOk (_,env) <- runSingle testPlugins act
48+
case env of
49+
[] -> return ()
50+
[s] -> T.unpack s `shouldStartWith` "Loaded package environment from"
51+
ss -> fail $ "got:" ++ show ss
52+
let
4753
res = IdeResultOk $
48-
(Map.singleton arg (S.singleton diag), [])
54+
(Map.singleton arg (S.singleton diag), env)
4955
diag = Diagnostic (Range (toPos (4,7))
5056
(toPos (4,8)))
5157
(Just DsError)

test/unit/LiquidSpec.hs

+14-11
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ module LiquidSpec where
44

55
import Data.Aeson
66
import qualified Data.ByteString.Lazy as BS
7-
import Data.List
87
import qualified Data.Text as T
98
import qualified Data.Text.IO as T
109
import Data.Monoid ((<>))
1110
import Data.Maybe (isJust)
1211
import Haskell.Ide.Engine.MonadTypes
1312
import Haskell.Ide.Engine.Plugin.Liquid
1413
import System.Directory
15-
import System.Exit
1614
import System.FilePath
1715
import Test.Hspec
1816

@@ -25,18 +23,23 @@ spec = do
2523
cwd <- runIO getCurrentDirectory
2624

2725
-- ---------------------------------
26+
2827
it "finds liquid haskell exe in $PATH" $ findExecutable "liquid" >>= (`shouldSatisfy` isJust)
2928

3029
-- ---------------------------------
31-
-- This produces some products in /test/testdata/liquid/.liquid/ that is used in subsequent test
32-
it "runs the liquid haskell exe" $ do
33-
let
34-
fp = cwd </> "test/testdata/liquid/Evens.hs"
35-
-- fp = "/home/alanz/tmp/haskell-proc-play/Evens.hs"
36-
-- uri = filePathToUri fp
37-
Just (ef, (msg:_)) <- runLiquidHaskell fp
38-
msg `shouldSatisfy` isPrefixOf "RESULT\n[{\"start\":{\"line\":9,\"column\":1},\"stop\":{\"line\":9,\"column\":8},\"message\":\"Error: Liquid Type Mismatch\\n Inferred type\\n VV : {v : Int | v == (7 : int)}\\n \\n not a subtype of Required type\\n VV : {VV : Int | VV mod 2 == 0}\\n"
39-
ef `shouldBe` ExitFailure 1
30+
31+
-- AZ: this test has been moved to func-tests, stack > 2.1 sets
32+
-- its own package environment, we can't run it from here.
33+
34+
-- -- This produces some products in /test/testdata/liquid/.liquid/ that is used in subsequent test
35+
-- it "runs the liquid haskell exe" $ do
36+
-- let
37+
-- fp = cwd </> "test/testdata/liquid/Evens.hs"
38+
-- -- fp = "/home/alanz/tmp/haskell-proc-play/Evens.hs"
39+
-- -- uri = filePathToUri fp
40+
-- Just (ef, (msg:_)) <- runLiquidHaskell fp
41+
-- msg `shouldSatisfy` isPrefixOf "RESULT\n[{\"start\":{\"line\":9,\"column\":1},\"stop\":{\"line\":9,\"column\":8},\"message\":\"Error: Liquid Type Mismatch\\n Inferred type\\n VV : {v : Int | v == (7 : int)}\\n \\n not a subtype of Required type\\n VV : {VV : Int | VV mod 2 == 0}\\n"
42+
-- ef `shouldBe` ExitFailure 1
4043

4144
-- ---------------------------------
4245
it "gets annot file paths" $ do

test/unit/PackagePluginSpec.hs

+30-27
Original file line numberDiff line numberDiff line change
@@ -251,33 +251,36 @@ packageSpec = do
251251
res = IdeResultOk
252252
$ WorkspaceEdit (Just $ H.singleton uri textEdits) Nothing
253253
textEdits = List
254-
[ TextEdit (Range (Position 0 0) (Position 34 0)) $ T.concat
255-
[ "library:\n"
256-
, " source-dirs: src\n"
257-
, "copyright: 2018 Author name here\n"
258-
, "maintainer: [email protected]\n"
259-
, "name: asdf\n"
260-
, "version: 0.1.0.0\n"
261-
, "extra-source-files:\n"
262-
, "- README.md\n"
263-
, "- ChangeLog.md\n"
264-
, "author: Author name here\n"
265-
, "github: githubuser/asdf\n"
266-
, "license: BSD3\n"
267-
, "executables:\n"
268-
, " asdf-exe:\n"
269-
, " source-dirs: app\n"
270-
, " main: Main.hs\n"
271-
, " ghc-options:\n"
272-
, " - -threaded\n"
273-
, " - -rtsopts\n"
274-
, " - -with-rtsopts=-N\n"
275-
, " dependencies:\n"
276-
, " - zlib\n"
277-
, " - asdf\n"
278-
, "description: Please see the README on GitHub at <https://github.com/githubuser/asdf#readme>\n"
279-
]
280-
]
254+
[ TextEdit (Range (Position 0 0) (Position 37 0)) $ T.concat
255+
[ "library:\n"
256+
, " source-dirs: src\n"
257+
, " dependencies:\n"
258+
, " - base\n"
259+
, "copyright: 2018 Author name here\n"
260+
, "maintainer: [email protected]\n"
261+
, "name: asdf\n"
262+
, "version: 0.1.0.0\n"
263+
, "extra-source-files:\n"
264+
, "- README.md\n"
265+
, "- ChangeLog.md\n"
266+
, "author: Author name here\n"
267+
, "github: githubuser/asdf\n"
268+
, "license: BSD3\n"
269+
, "executables:\n"
270+
, " asdf-exe:\n"
271+
, " source-dirs: app\n"
272+
, " main: Main.hs\n"
273+
, " ghc-options:\n"
274+
, " - -threaded\n"
275+
, " - -rtsopts\n"
276+
, " - -with-rtsopts=-N\n"
277+
, " dependencies:\n"
278+
, " - zlib\n"
279+
, " - base\n"
280+
, " - asdf\n"
281+
, "description: Please see the README on GitHub at <https://github.com/githubuser/asdf#readme>\n"
282+
]
283+
]
281284
testCommand testPlugins act "package" "add" args res
282285
it "Add package to package.yaml in hpack project with generated cabal to library component"
283286
$ withCurrentDirectory (testdata </> "hybrid-lib")

test/utils/TestUtils.hs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module TestUtils
55
, withFileLogging
66
, setupStackFiles
77
, testCommand
8+
, runSingle
89
, runSingleReq
910
, makeRequest
1011
, runIGM
@@ -60,6 +61,9 @@ testCommand testPlugins act plugin cmd arg res = do
6061
newApiRes `shouldBe` res
6162
fmap fromDynJSON oldApiRes `shouldBe` fmap Just res
6263

64+
runSingle :: IdePlugins -> IdeGhcM (IdeResult b) -> IO (IdeResult b)
65+
runSingle testPlugins act = runIGM testPlugins act
66+
6367
runSingleReq :: ToJSON a
6468
=> IdePlugins -> PluginId -> CommandName -> a -> IO (IdeResult DynamicJSON)
6569
runSingleReq testPlugins plugin com arg = runIGM testPlugins (makeRequest plugin com arg)

test/wrapper/HieWrapper.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ main = hspec $
1818
withCurrentDirectory "test/testdata/wrapper/ghc" $ do
1919
ghcDisplayVer <- readCreateProcess (shell "ghc --version") ""
2020
ghcVer <- getProjectGhcVersion
21-
init ghcDisplayVer `shouldEndWith` ghcVer
21+
init ghcDisplayVer `shouldEndWith` ghcVer

0 commit comments

Comments
 (0)