Skip to content

Commit b16107e

Browse files
isovectormichaelpj
authored andcommitted
Add subsequent tactic test
1 parent 988f6ee commit b16107e

File tree

5 files changed

+60
-26
lines changed

5 files changed

+60
-26
lines changed

plugins/hls-tactics-plugin/src/Wingman/LanguageServer.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Development.IDE.Core.PositionMapping (idDelta)
3030
import Development.IDE.Core.RuleTypes
3131
import Development.IDE.Core.Rules (usePropertyAction)
3232
import Development.IDE.Core.Service (runAction)
33-
import Development.IDE.Core.Shake (IdeState (..), uses, define, use, addPersistentRule)
33+
import Development.IDE.Core.Shake (IdeState (..), uses, define, use, addPersistentRule, getShakeExtras, recordDirtyKeys)
3434
import qualified Development.IDE.Core.Shake as IDE
3535
import Development.IDE.Core.UseStale
3636
import Development.IDE.GHC.Compat hiding (empty)
@@ -63,6 +63,7 @@ import Wingman.Judgements.Theta
6363
import Wingman.Range
6464
import Wingman.StaticPlugin (pattern WingmanMetaprogram, pattern MetaprogramSyntax)
6565
import Wingman.Types
66+
import Control.Concurrent.STM.Stats (atomically)
6667

6768

6869
tacticDesc :: T.Text -> T.Text
@@ -594,6 +595,13 @@ wingmanRules plId = do
594595

595596
action $ do
596597
files <- getFilesOfInterestUntracked
598+
extras <- getShakeExtras
599+
void
600+
$ liftIO
601+
$ join
602+
$ atomically
603+
$ recordDirtyKeys extras WriteDiagnostics
604+
$ Map.keys files
597605
void $ uses WriteDiagnostics $ Map.keys files
598606

599607

plugins/hls-tactics-plugin/test/ProviderSpec.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ spec = do
2020
"T2" 8 8
2121
[ (not, Intros, "")
2222
]
23+
24+
goldenTestMany "SubsequentTactics"
25+
[ InvokeTactic Intros "" 4 5
26+
, InvokeTactic Destruct "du" 4 8
27+
, InvokeTactic Auto "" 4 15
28+
]

plugins/hls-tactics-plugin/test/Utils.hs

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE ScopedTypeVariables #-}
55
{-# LANGUAGE TypeOperators #-}
66
{-# LANGUAGE ViewPatterns #-}
7+
{-# LANGUAGE RecordWildCards #-}
78

89
module Utils where
910

@@ -96,39 +97,45 @@ mkTest name fp line col ts = it name $ do
9697
liftIO $
9798
(title `elem` titles) `shouldSatisfy` f
9899

100+
data InvokeTactic = InvokeTactic
101+
{ it_command :: TacticCommand
102+
, it_argument :: Text
103+
, it_line :: Int
104+
, it_col :: Int
105+
}
106+
107+
invokeTactic :: TextDocumentIdentifier -> InvokeTactic -> Session ()
108+
invokeTactic doc InvokeTactic{..} = do
109+
-- wait for the entire build to finish, so that Tactics code actions that
110+
-- use stale data will get uptodate stuff
111+
void waitForDiagnostics
112+
void $ waitForTypecheck doc
113+
actions <- getCodeActions doc $ pointRange it_line it_col
114+
case find ((== Just (tacticTitle it_command it_argument)) . codeActionTitle) actions of
115+
Just (InR CodeAction {_command = Just c}) -> do
116+
executeCommand c
117+
void $ skipManyTill anyMessage $ message SWorkspaceApplyEdit
118+
_ -> error $ show actions
99119

100120

101121
mkGoldenTest
102122
:: (Text -> Text -> Assertion)
103-
-> TacticCommand
104-
-> Text
105-
-> Int
106-
-> Int
123+
-> [InvokeTactic]
107124
-> FilePath
108125
-> SpecWith ()
109-
mkGoldenTest eq tc occ line col input =
126+
mkGoldenTest eq invocations input =
110127
it (input <> " (golden)") $ do
111128
resetGlobalHoleRef
112129
runSessionForTactics $ do
113130
doc <- openDoc (input <.> "hs") "haskell"
114-
-- wait for diagnostics to start coming
115-
void waitForDiagnostics
116-
-- wait for the entire build to finish, so that Tactics code actions that
117-
-- use stale data will get uptodate stuff
118-
void $ waitForTypecheck doc
119-
actions <- getCodeActions doc $ pointRange line col
120-
case find ((== Just (tacticTitle tc occ)) . codeActionTitle) actions of
121-
Just (InR CodeAction {_command = Just c}) -> do
122-
executeCommand c
123-
_resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit)
124-
edited <- documentContents doc
125-
let expected_name = input <.> "expected" <.> "hs"
126-
-- Write golden tests if they don't already exist
127-
liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do
128-
T.writeFile expected_name edited
129-
expected <- liftIO $ T.readFile expected_name
130-
liftIO $ edited `eq` expected
131-
_ -> error $ show actions
131+
traverse_ (invokeTactic doc) invocations
132+
edited <- documentContents doc
133+
let expected_name = input <.> "expected" <.> "hs"
134+
-- Write golden tests if they don't already exist
135+
liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do
136+
T.writeFile expected_name edited
137+
expected <- liftIO $ T.readFile expected_name
138+
liftIO $ edited `eq` expected
132139

133140
mkCodeLensTest
134141
:: FilePath
@@ -197,10 +204,13 @@ mkShowMessageTest tc occ line col input ufm =
197204

198205

199206
goldenTest :: TacticCommand -> Text -> Int -> Int -> FilePath -> SpecWith ()
200-
goldenTest = mkGoldenTest shouldBe
207+
goldenTest tc occ line col = mkGoldenTest shouldBe [InvokeTactic tc occ line col]
208+
209+
goldenTestMany :: FilePath -> [InvokeTactic] -> SpecWith ()
210+
goldenTestMany = flip $ mkGoldenTest shouldBe
201211

202212
goldenTestNoWhitespace :: TacticCommand -> Text -> Int -> Int -> FilePath -> SpecWith ()
203-
goldenTestNoWhitespace = mkGoldenTest shouldBeIgnoringSpaces
213+
goldenTestNoWhitespace tc occ line col = mkGoldenTest shouldBeIgnoringSpaces [InvokeTactic tc occ line col]
204214

205215

206216
shouldBeIgnoringSpaces :: Text -> Text -> Assertion
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
data Dummy a = Dummy a
2+
3+
f :: Dummy Int -> Int
4+
f (Dummy n) = n
5+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
data Dummy a = Dummy a
2+
3+
f :: Dummy Int -> Int
4+
f = _
5+

0 commit comments

Comments
 (0)