Skip to content

Commit 2beb1e4

Browse files
authored
Merge branch 'master' into import-without-parent
2 parents a00f7f7 + aa7e9a3 commit 2beb1e4

File tree

7 files changed

+92
-45
lines changed

7 files changed

+92
-45
lines changed

.github/workflows/bench.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
ghc: ['8.10.2', '8.8.4', '8.6.5']
12-
os: [ubuntu-latest, macOS-latest]
12+
os: [ubuntu-latest]
1313

1414
steps:
1515
- uses: actions/checkout@v2
1616
- run: git fetch origin master # check the master branch for benchmarking
17-
- uses: actions/setup-haskell@v1
17+
- uses: haskell/actions/setup@v1
1818
with:
1919
ghc-version: ${{ matrix.ghc }}
2020
cabal-version: '3.2'
@@ -26,7 +26,11 @@ jobs:
2626
path: |
2727
~/.cabal/packages
2828
~/.cabal/store
29-
key: ${{ runner.os }}-${{ matrix.ghc }}-cabal-bench
29+
key: ${{ runner.os }}-${{ matrix.ghc }}-bench-${{ hashFiles('cabal.project') }}
30+
restore-keys: |
31+
${{ runner.os }}-${{ matrix.ghc }}-build-${{ hashFiles('cabal.project') }}
32+
${{ runner.os }}-${{ matrix.ghc }}-bench-
33+
${{ runner.os }}-${{ matrix.ghc }}
3034
3135
- run: cabal update
3236

.github/workflows/build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- uses: actions/checkout@v2
3636
with:
3737
submodules: true
38-
- uses: actions/setup-haskell@v1
38+
- uses: haskell/actions/setup@v1
3939
with:
4040
ghc-version: ${{ matrix.ghc }}
4141
cabal-version: '3.2'
@@ -174,4 +174,3 @@ jobs:
174174
asset_path: bin/haskell-language-server.tar.gz
175175
asset_name: haskell-language-server-${{ matrix.os }}-${{ github.event.release.tag_name }}.tar.gz
176176
asset_content_type: application/gzip
177-

.github/workflows/nix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
ghc: ['default', 'ghc8102', 'ghc884', 'ghc865']
11+
ghc: ['default']
1212
os: [ubuntu-latest, macOS-latest]
1313

1414
steps:

.github/workflows/test.yml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ jobs:
55
test:
66
runs-on: ${{ matrix.os }}
77
strategy:
8-
fail-fast: false
8+
fail-fast: true
99
matrix:
1010
ghc: ["8.10.2", "8.10.1", "8.8.4", "8.8.3", "8.8.2", "8.6.5", "8.6.4"]
11-
os: [ubuntu-latest, macOS-latest, windows-latest]
12-
ghc-lib: [false]
11+
os: [ubuntu-latest, windows-latest]
1312
exclude:
1413
- os: windows-latest
1514
ghc: "8.10.2" # broken due to https://gitlab.haskell.org/ghc/ghc/-/issues/18550
@@ -19,25 +18,23 @@ jobs:
1918
ghc: "8.8.3" # fails due to segfault
2019
- os: windows-latest
2120
ghc: "8.8.2" # fails due to error with Cabal
22-
include:
2321
- os: windows-latest
2422
ghc: "8.6.4" # times out after 300m
23+
include:
2524
- os: windows-latest
2625
ghc: "8.10.2.2" # only available for windows and choco
27-
# one ghc-lib build
28-
- os: ubuntu-latest
29-
ghc: '8.10.1'
30-
ghc-lib: true
3126

3227
steps:
28+
# Cancel queued workflows from earlier commits in this branch
29+
- uses: fkirc/skip-duplicate-actions@master
30+
3331
- uses: actions/checkout@v2
3432
with:
3533
submodules: true
36-
- uses: actions/setup-haskell@v1
34+
- uses: haskell/actions/setup@v1
3735
with:
3836
ghc-version: ${{ matrix.ghc }}
3937
cabal-version: "3.2"
40-
enable-stack: true
4138

4239
- run: ./fmt.sh
4340
name: "HLint via ./fmt.sh"
@@ -47,10 +44,12 @@ jobs:
4744
env:
4845
cache-name: cache-cabal
4946
with:
50-
path: ~/.cabal/
51-
key: ${{ runner.os }}-${{ matrix.ghc }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
47+
path: |
48+
~/.cabal/packages
49+
~/.cabal/store
50+
key: ${{ runner.os }}-${{ matrix.ghc }}-build-${{ hashFiles('cabal.project') }}
5251
restore-keys: |
53-
${{ runner.os }}-${{ matrix.ghc }}-build-${{ env.cache-name }}-
52+
${{ runner.os }}-${{ matrix.ghc }}-bench-$${ hashFiles('cabal.project') }}
5453
${{ runner.os }}-${{ matrix.ghc }}-build-
5554
${{ runner.os }}-${{ matrix.ghc }}
5655
@@ -72,13 +71,11 @@ jobs:
7271
run: cabal build || cabal build || cabal build
7372

7473
- name: Test ghcide
75-
if: ${{ !matrix.ghc-lib }}
7674
shell: bash
7775
# run the tests without parallelism to avoid running out of memory
7876
run: cabal test ghcide --test-options="-j1 --rerun-update" || cabal test ghcide --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test ghcide --test-options="-j1 --rerun"
7977

8078
- name: Test func-test suite
81-
if: ${{ !matrix.ghc-lib }}
8279
shell: bash
8380
env:
8481
HLS_TEST_EXE: hls
@@ -89,7 +86,6 @@ jobs:
8986
run: cabal test func-test --test-options="-j1 --rerun-update" || cabal test func-test --test-options="-j1 --rerun --rerun-update" || cabal test func-test --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test func-test --test-options="-j1 --rerun"
9087

9188
- name: Test wrapper-test suite
92-
if: ${{ !matrix.ghc-lib }}
9389
shell: bash
9490
env:
9591
HLS_TEST_EXE: hls

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
329329
let res = (map (renderCradleError ncfp) err, Nothing)
330330
modifyVar_ fileToFlags $ \var -> do
331331
pure $ Map.insertWith HM.union hieYaml (HM.singleton ncfp (res, dep_info)) var
332-
return (res,[])
332+
return (res, maybe [] pure hieYaml ++ concatMap cradleErrorDependencies err)
333333

334334
-- This caches the mapping from hie.yaml + Mod.hs -> [String]
335335
-- Returns the Ghc session and the cradle dependencies
@@ -360,7 +360,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
360360
getOptions file = do
361361
hieYaml <- cradleLoc file
362362
sessionOpts (hieYaml, file) `catch` \e ->
363-
return (([renderPackageSetupException file e], Nothing),[])
363+
return (([renderPackageSetupException file e], Nothing), maybe [] pure hieYaml)
364364

365365
returnWithVersion $ \file -> do
366366
opts <- liftIO $ join $ mask_ $ modifyVar runningCradle $ \as -> do

ghcide/test/exe/Main.hs

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
module Main (main) where
1212

1313
import Control.Applicative.Combinators
14-
import Control.Exception (catch)
14+
import Control.Exception (bracket_, catch)
1515
import qualified Control.Lens as Lens
1616
import Control.Monad
1717
import Control.Monad.IO.Class (liftIO)
@@ -41,7 +41,7 @@ import Language.Haskell.LSP.Types.Capabilities
4141
import qualified Language.Haskell.LSP.Types.Lens as Lsp (diagnostics, params, message)
4242
import Language.Haskell.LSP.VFS (applyChange)
4343
import Network.URI
44-
import System.Environment.Blank (getEnv, setEnv)
44+
import System.Environment.Blank (unsetEnv, getEnv, setEnv)
4545
import System.FilePath
4646
import System.IO.Extra hiding (withTempDir)
4747
import qualified System.IO.Extra
@@ -58,8 +58,10 @@ import Test.Tasty.HUnit
5858
import Test.Tasty.QuickCheck
5959
import System.Time.Extra
6060
import Development.IDE.Plugin.CodeAction (typeSignatureCommandId, blockCommandId, matchRegExMultipleImports)
61-
import Development.IDE.Plugin.Test (WaitForIdeRuleResult(..), TestRequest(WaitForIdeRule, BlockSeconds,GetInterfaceFilesDir))
61+
import Development.IDE.Plugin.Test (WaitForIdeRuleResult(..), TestRequest(BlockSeconds,GetInterfaceFilesDir))
6262
import Control.Monad.Extra (whenJust)
63+
import qualified Language.Haskell.LSP.Types.Lens as L
64+
import Control.Lens ((^.))
6365

6466
main :: IO ()
6567
main = do
@@ -630,11 +632,6 @@ cancellationTemplate (edit, undoEdit) mbKey = testCase (maybe "-" fst mbKey) $ r
630632
-- similar to run except it disables kick
631633
runTestNoKick s = withTempDir $ \dir -> runInDir' dir "." "." ["--test-no-kick"] s
632634

633-
waitForAction key TextDocumentIdentifier{_uri} = do
634-
waitId <- sendRequest (CustomClientMethod "test") (WaitForIdeRule key _uri)
635-
ResponseMessage{_result} <- skipManyTill anyMessage $ responseForId waitId
636-
return _result
637-
638635
typeCheck doc = do
639636
Right WaitForIdeRuleResult {..} <- waitForAction "TypeCheck" doc
640637
liftIO $ assertBool "The file should typecheck" ideResultSuccess
@@ -3442,7 +3439,7 @@ cradleTests :: TestTree
34423439
cradleTests = testGroup "cradle"
34433440
[testGroup "dependencies" [sessionDepsArePickedUp]
34443441
,testGroup "ignore-fatal" [ignoreFatalWarning]
3445-
,testGroup "loading" [loadCradleOnlyonce]
3442+
,testGroup "loading" [loadCradleOnlyonce, retryFailedCradle]
34463443
,testGroup "multi" [simpleMultiTest, simpleMultiTest2]
34473444
,testGroup "sub-directory" [simpleSubDirectoryTest]
34483445
]
@@ -3469,6 +3466,43 @@ loadCradleOnlyonce = testGroup "load cradle only once"
34693466
msgs <- manyTill (skipManyTill anyMessage cradleLoadedMessage) (skipManyTill anyMessage (message @PublishDiagnosticsNotification))
34703467
liftIO $ length msgs @?= 0
34713468

3469+
retryFailedCradle :: TestTree
3470+
retryFailedCradle = testSession' "retry failed" $ \dir -> do
3471+
-- The false cradle always fails
3472+
let hieContents = "cradle: {bios: {shell: \"false\"}}"
3473+
hiePath = dir </> "hie.yaml"
3474+
liftIO $ writeFile hiePath hieContents
3475+
hieDoc <- createDoc hiePath "yaml" $ T.pack hieContents
3476+
let aPath = dir </> "A.hs"
3477+
doc <- createDoc aPath "haskell" "main = return ()"
3478+
Right WaitForIdeRuleResult {..} <- waitForAction "TypeCheck" doc
3479+
liftIO $ "Test assumption failed: cradle should error out" `assertBool` not ideResultSuccess
3480+
3481+
-- Fix the cradle and typecheck again
3482+
let validCradle = "cradle: {bios: {shell: \"echo A.hs\"}}"
3483+
liftIO $ writeFileUTF8 hiePath $ T.unpack validCradle
3484+
changeDoc
3485+
hieDoc
3486+
[ TextDocumentContentChangeEvent
3487+
{ _range = Nothing,
3488+
_rangeLength = Nothing,
3489+
_text = validCradle
3490+
}
3491+
]
3492+
3493+
-- Force a session restart by making an edit, just to dirty the typecheck node
3494+
changeDoc
3495+
doc
3496+
[ TextDocumentContentChangeEvent
3497+
{ _range = Just Range {_start = Position 0 0, _end = Position 0 0},
3498+
_rangeLength = Nothing,
3499+
_text = "\n"
3500+
}
3501+
]
3502+
3503+
Right WaitForIdeRuleResult {..} <- waitForAction "TypeCheck" doc
3504+
liftIO $ "No joy after fixing the cradle" `assertBool` ideResultSuccess
3505+
34723506

34733507
dependentFileTest :: TestTree
34743508
dependentFileTest = testGroup "addDependentFile"
@@ -3533,17 +3567,19 @@ simpleSubDirectoryTest =
35333567
expectNoMoreDiagnostics 0.5
35343568

35353569
simpleMultiTest :: TestTree
3536-
simpleMultiTest = testCase "simple-multi-test" $ runWithExtraFiles "multi" $ \dir -> do
3570+
simpleMultiTest = testCase "simple-multi-test" $ withLongTimeout $ runWithExtraFiles "multi" $ \dir -> do
35373571
let aPath = dir </> "a/A.hs"
35383572
bPath = dir </> "b/B.hs"
35393573
aSource <- liftIO $ readFileUtf8 aPath
3540-
(TextDocumentIdentifier adoc) <- createDoc aPath "haskell" aSource
3541-
expectNoMoreDiagnostics 0.5
3574+
adoc <- createDoc aPath "haskell" aSource
3575+
Right WaitForIdeRuleResult {..} <- waitForAction "TypeCheck" adoc
3576+
liftIO $ assertBool "A should typecheck" ideResultSuccess
35423577
bSource <- liftIO $ readFileUtf8 bPath
35433578
bdoc <- createDoc bPath "haskell" bSource
3544-
expectNoMoreDiagnostics 0.5
3579+
Right WaitForIdeRuleResult {..} <- waitForAction "TypeCheck" bdoc
3580+
liftIO $ assertBool "B should typecheck" ideResultSuccess
35453581
locs <- getDefinitions bdoc (Position 2 7)
3546-
let fooL = mkL adoc 2 0 2 3
3582+
let fooL = mkL (adoc ^. L.uri) 2 0 2 3
35473583
checkDefs locs (pure [fooL])
35483584
expectNoMoreDiagnostics 0.5
35493585

@@ -3909,6 +3945,9 @@ run' s = withTempDir $ \dir -> runInDir dir (s dir)
39093945
runInDir :: FilePath -> Session a -> IO a
39103946
runInDir dir = runInDir' dir "." "." []
39113947

3948+
withLongTimeout :: IO a -> IO a
3949+
withLongTimeout = bracket_ (setEnv "LSP_TIMEOUT" "120" True) (unsetEnv "LSP_TIMEOUT")
3950+
39123951
-- | Takes a directory as well as relative paths to where we should launch the executable as well as the session root.
39133952
runInDir' :: FilePath -> FilePath -> FilePath -> [String] -> Session a -> IO a
39143953
runInDir' dir startExeIn startSessionIn extraOptions s = do
@@ -3929,19 +3968,19 @@ runInDir' dir startExeIn startSessionIn extraOptions s = do
39293968
setEnv "HOME" "/homeless-shelter" False
39303969
let lspTestCaps = fullCaps { _window = Just $ WindowClientCapabilities $ Just True }
39313970
logColor <- fromMaybe True <$> checkEnv "LSP_TEST_LOG_COLOR"
3971+
timeoutOverride <- fmap read <$> getEnv "LSP_TIMEOUT"
3972+
let conf = defaultConfig{messageTimeout = fromMaybe (messageTimeout defaultConfig) timeoutOverride}
3973+
-- uncomment this or set LSP_TEST_LOG_STDERR=1 to see all logging
3974+
-- { logStdErr = True }
3975+
-- uncomment this or set LSP_TEST_LOG_MESSAGES=1 to see all messages
3976+
-- { logMessages = True }
39323977
runSessionWithConfig conf{logColor} cmd lspTestCaps projDir s
39333978
where
39343979
checkEnv :: String -> IO (Maybe Bool)
39353980
checkEnv s = fmap convertVal <$> getEnv s
39363981
convertVal "0" = False
39373982
convertVal _ = True
39383983

3939-
conf = defaultConfig
3940-
-- uncomment this or set LSP_TEST_LOG_STDERR=1 to see all logging
3941-
-- { logStdErr = True }
3942-
-- uncomment this or set LSP_TEST_LOG_MESSAGES=1 to see all messages
3943-
-- { logMessages = True }
3944-
39453984
openTestDataDoc :: FilePath -> Session TextDocumentIdentifier
39463985
openTestDataDoc path = do
39473986
source <- liftIO $ readFileUtf8 $ "test/data" </> path

ghcide/test/src/Development/IDE/Test.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ module Development.IDE.Test
1515
, checkDiagnosticsForDoc
1616
, canonicalizeUri
1717
, standardizeQuotes
18-
,flushMessages) where
18+
, flushMessages
19+
, waitForAction
20+
) where
1921

2022
import Control.Applicative.Combinators
2123
import Control.Lens hiding (List)
@@ -32,6 +34,7 @@ import System.Time.Extra
3234
import Test.Tasty.HUnit
3335
import System.Directory (canonicalizePath)
3436
import Data.Maybe (fromJust)
37+
import Development.IDE.Plugin.Test (WaitForIdeRuleResult, TestRequest(WaitForIdeRule))
3538

3639

3740
-- | (0-based line number, 0-based column number)
@@ -180,3 +183,9 @@ standardizeQuotes msg = let
180183
repl '`' = '\''
181184
repl c = c
182185
in T.map repl msg
186+
187+
waitForAction :: String -> TextDocumentIdentifier -> Session (Either ResponseError WaitForIdeRuleResult)
188+
waitForAction key TextDocumentIdentifier{_uri} = do
189+
waitId <- sendRequest (CustomClientMethod "test") (WaitForIdeRule key _uri)
190+
ResponseMessage{_result} <- skipManyTill anyMessage $ responseForId waitId
191+
return _result

0 commit comments

Comments
 (0)