Skip to content

Disable check project in the ghcide test suite #2397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ executable ghcide-bench
base,
bytestring,
containers,
data-default,
directory,
extra,
filepath,
Expand Down
9 changes: 8 additions & 1 deletion ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,14 @@ instance IsIdeGlobal GlobalIdeOptions
getIdeOptions :: Action IdeOptions
getIdeOptions = do
GlobalIdeOptions x <- getIdeGlobalAction
return x
env <- lspEnv <$> getShakeExtras
case env of
Nothing -> return x
Just env -> do
config <- liftIO $ LSP.runLspT env HLS.getClientConfig
return x{optCheckProject = pure $ checkProject config,
optCheckParents = pure $ checkParents config
}

getIdeOptionsIO :: ShakeExtras -> IO IdeOptions
getIdeOptionsIO ide = do
Expand Down
20 changes: 10 additions & 10 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import Development.IDE.Test (Cursor,
getInterfaceFilesDir,
waitForAction,
getStoredKeys,
waitForTypecheck, waitForGC)
waitForTypecheck, waitForGC, configureCheckProject)
import Development.IDE.Test.Runfiles
import qualified Development.IDE.Types.Diagnostics as Diagnostics
import Development.IDE.Types.Location
Expand Down Expand Up @@ -427,10 +427,7 @@ diagnosticTests = testGroup "diagnostics"
liftIO $ writeFile (path </> "hie.yaml") cradle
_ <- createDoc "ModuleD.hs" "haskell" contentD
expectDiagnostics
[ ( "ModuleA.hs"
, [(DsError, (1, 7), "Cyclic module dependency between ModuleA, ModuleB")]
)
, ( "ModuleB.hs"
[ ( "ModuleB.hs"
, [(DsError, (1, 7), "Cyclic module dependency between ModuleA, ModuleB")]
)
]
Expand Down Expand Up @@ -1603,10 +1600,7 @@ extendImportTests = testGroup "extend import actions"
codeActionTitle CodeAction{_title=x} = x

template setUpModules moduleUnderTest range expectedTitles expectedContentB = do
sendNotification SWorkspaceDidChangeConfiguration
(DidChangeConfigurationParams $ toJSON
def{checkProject = overrideCheckProject})

configureCheckProject overrideCheckProject

mapM_ (\x -> createDoc (fst x) "haskell" (snd x)) setUpModules
docB <- createDoc (fst moduleUnderTest) "haskell" (snd moduleUnderTest)
Expand Down Expand Up @@ -1783,6 +1777,7 @@ suggestImportTests = testGroup "suggest import actions"
test = test' False
wantWait = test' True True
test' waitForCheckProject wanted imps def other newImp = testSessionWithExtraFiles "hover" (T.unpack def) $ \dir -> do
configureCheckProject waitForCheckProject
let before = T.unlines $ "module A where" : ["import " <> x | x <- imps] ++ def : other
after = T.unlines $ "module A where" : ["import " <> x | x <- imps] ++ [newImp] ++ def : other
cradle = "cradle: {direct: {arguments: [-hide-all-packages, -package, base, -package, text, -package-env, -, A, Bar, Foo, B]}}"
Expand Down Expand Up @@ -5325,6 +5320,7 @@ ifaceTHTest = testCase "iface-th-test" $ runWithExtraFiles "TH" $ \dir -> do

ifaceErrorTest :: TestTree
ifaceErrorTest = testCase "iface-error-test-1" $ runWithExtraFiles "recomp" $ \dir -> do
configureCheckProject True
let bPath = dir </> "B.hs"
pPath = dir </> "P.hs"

Expand Down Expand Up @@ -5689,6 +5685,8 @@ getReferences' (file, l, c) includeDeclaration = do

referenceTestSession :: String -> FilePath -> [FilePath] -> (FilePath -> Session ()) -> TestTree
referenceTestSession name thisDoc docs' f = testSessionWithExtraFiles "references" name $ \dir -> do
-- needed to build whole project indexing
configureCheckProject True
let docs = map (dir </>) $ delete thisDoc $ nubOrd docs'
-- Initial Index
docid <- openDoc thisDoc "haskell"
Expand Down Expand Up @@ -5819,7 +5817,9 @@ runInDir' dir startExeIn startSessionIn extraOptions s = do
-- Only sets HOME if it wasn't already set.
setEnv "HOME" "/homeless-shelter" False
conf <- getConfigFromEnv
runSessionWithConfig conf cmd lspTestCaps projDir s
runSessionWithConfig conf cmd lspTestCaps projDir $ do
configureCheckProject False
s

getConfigFromEnv :: IO SessionConfig
getConfigFromEnv = do
Expand Down
12 changes: 10 additions & 2 deletions ghcide/test/src/Development/IDE/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ module Development.IDE.Test
, getStoredKeys
, waitForCustomMessage
, waitForGC
,getBuildKeysBuilt,getBuildKeysVisited,getBuildKeysChanged,getBuildEdgesCount) where
,getBuildKeysBuilt,getBuildKeysVisited,getBuildKeysChanged,getBuildEdgesCount,configureCheckProject) where

import Control.Applicative.Combinators
import Control.Lens hiding (List)
import Control.Monad
import Control.Monad.IO.Class
import Data.Aeson (toJSON)
import qualified Data.Aeson as A
import Data.Bifunctor (second)
import Data.Default
import qualified Data.Map.Strict as Map
import Data.Maybe (fromJust)
import Data.Text (Text)
Expand All @@ -45,7 +47,7 @@ import Development.IDE.Plugin.Test (TestRequest (..),
WaitForIdeRuleResult,
ideResultSuccess)
import Development.IDE.Test.Diagnostic
import Ide.Plugin.Config (CheckParents)
import Ide.Plugin.Config (CheckParents, checkProject)
import Language.LSP.Test hiding (message)
import qualified Language.LSP.Test as LspTest
import Language.LSP.Types hiding
Expand Down Expand Up @@ -246,3 +248,9 @@ waitForGC = waitForCustomMessage "ghcide/GC" $ \v ->
case A.fromJSON v of
A.Success x -> Just x
_ -> Nothing

configureCheckProject :: Bool -> Session ()
configureCheckProject overrideCheckProject =
sendNotification SWorkspaceDidChangeConfiguration
(DidChangeConfigurationParams $ toJSON
def{checkProject = overrideCheckProject})