77-- 'ClsInst' twice (once via @ie_global@ from the EPS, once via
88-- @ie_local@ from 'hptInstancesBelow').
99--
10- -- The pollution enters through 'Development.IDE.Spans.Documentation.mkDocMap'.
11- -- Its 'Rules.GetDocMap' rule reads three inputs via independent
10+ -- The pollution entered through 'Development.IDE.Spans.Documentation.mkDocMap'.
11+ -- Its 'Rules.GetDocMap' rule read three inputs via independent
1212-- @useWithStale_@ calls: 'TypeCheck', 'GhcSessionDeps' and 'GetHieAst'.
1313-- These three can diverge: an edit that merely changes imports lets
1414-- 'GhcSessionDeps' re-evaluate (fresh, with a different HPT) while
2121-- evicts anything, so the pollution is permanent for the session.
2222module EpsPollutionTests (tests ) where
2323
24- import Config (runWithExtraFiles )
24+ import Config (Expect (ExpectHoverText ),
25+ runWithExtraFiles )
2526import Control.Lens ((^.) )
26- import Control.Monad.IO.Class ( liftIO )
27+ import Control.Monad ( void )
2728import qualified Data.Text as T
2829import Development.IDE.GHC.Util (readFileUtf8 )
29- import Development.IDE.Test ( waitForTypecheck )
30+ import Hover
3031import qualified Language.LSP.Protocol.Lens as L
3132import Language.LSP.Protocol.Types
3233import Language.LSP.Test
3334import System.FilePath
34- import Test.Hls (expectFailBecause ,
35- waitForDiagnosticsFrom )
36- import Test.Tasty
37- import Test.Tasty.HUnit
35+ import Test.Hls
3836
3937tests :: TestTree
4038tests = testGroup " eps-pollution"
41- [ expectFailBecause
42- " The EPS gets polluted with a home-module instance via GetDocMap's \
43- \inconsistent stale-value snapshot; the next successful typecheck \
44- \sees the instance twice."
45- staleHieProvokesOverlapping
39+ [ staleHieProvokesOverlapping
4640 ]
4741
4842-- The fixture at ghcide-test/data/multi-unit-eps-pollution/ sets up two
@@ -59,20 +53,22 @@ staleHieProvokesOverlapping =
5953 originalC <- liftIO $ readFileUtf8 cPath
6054 let brokenC = T. replace " import A\n " " " originalC
6155 cdoc <- openDoc cPath " haskell"
62- True <- waitForTypecheck cdoc
56+ void $ waitForTypecheck cdoc
6357 -- Hovering triggers the hover pipeline, which forces GetDocMap.
6458 -- While C is healthy this populates GetHieAst with a RefMap
6559 -- referencing A's names -- the stale value we rely on below.
66- _ <- getHover cdoc (hoverOnMyMethod originalC)
60+ hover <- getHover cdoc (hoverOnMyMethod originalC)
61+ checkHover hover [ExpectHoverText [" myMethod" , " MyClass" ]]
62+
6763 -- Break C's import of A. C fails to typecheck, but GhcSessionDeps
6864 -- re-evaluates successfully (it only needs the import list) with an
6965 -- HPT that no longer contains A. A further hover forces GetDocMap
7066 -- to run with the fresh GhcSessionDeps alongside the stale RefMap;
7167 -- loadSysInterface(A) then runs and pollutes the EPS.
7268 changeDoc cdoc [TextDocumentContentChangeEvent . InR .
7369 TextDocumentContentChangeWholeDocument $ brokenC]
74- _ <- getHover cdoc (hoverOnMyMethod brokenC)
75- _ <- waitForDiagnosticsFrom cdoc -- let the broken state settle
70+ void $ getHover cdoc (hoverOnMyMethod brokenC)
71+ void $ waitForDiagnosticsFrom cdoc -- let the broken state settle
7672 -- Repair C. The next typecheck legitimately has A in its HPT; with
7773 -- the polluted EPS it also has A's ClsInst in eps_inst_env, so
7874 -- instance resolution for 'myMethod x :: AType -> String' finds
0 commit comments