Skip to content
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

Wingman: Fix subsequent tactics #2479

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 9 additions & 1 deletion plugins/hls-tactics-plugin/src/Wingman/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Development.IDE.Core.PositionMapping (idDelta)
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Rules (usePropertyAction)
import Development.IDE.Core.Service (runAction)
import Development.IDE.Core.Shake (IdeState (..), uses, define, use, addPersistentRule)
import Development.IDE.Core.Shake (IdeState (..), uses, define, use, addPersistentRule, getShakeExtras, recordDirtyKeys)
import qualified Development.IDE.Core.Shake as IDE
import Development.IDE.Core.UseStale
import Development.IDE.GHC.Compat hiding (empty)
Expand Down Expand Up @@ -64,6 +64,7 @@ import Wingman.Judgements.Theta
import Wingman.Range
import Wingman.StaticPlugin (pattern WingmanMetaprogram, pattern MetaprogramSyntax)
import Wingman.Types
import Control.Concurrent.STM.Stats (atomically)


tacticDesc :: T.Text -> T.Text
Expand Down Expand Up @@ -595,6 +596,13 @@ wingmanRules plId = do

action $ do
files <- getFilesOfInterestUntracked
extras <- getShakeExtras
void
$ liftIO
$ join
$ atomically
$ recordDirtyKeys extras WriteDiagnostics
$ Map.keys files
void $ uses WriteDiagnostics $ Map.keys files


Expand Down
6 changes: 6 additions & 0 deletions plugins/hls-tactics-plugin/test/ProviderSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ spec = do
"T2" 8 8
[ (not, Intros, "")
]

goldenTestMany "SubsequentTactics"
[ InvokeTactic Intros "" 4 5
, InvokeTactic Destruct "du" 4 8
, InvokeTactic Auto "" 4 15
]
60 changes: 35 additions & 25 deletions plugins/hls-tactics-plugin/test/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE RecordWildCards #-}

module Utils where

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

data InvokeTactic = InvokeTactic
{ it_command :: TacticCommand
, it_argument :: Text
, it_line :: Int
, it_col :: Int
}

invokeTactic :: TextDocumentIdentifier -> InvokeTactic -> Session ()
invokeTactic doc InvokeTactic{..} = do
-- wait for the entire build to finish, so that Tactics code actions that
-- use stale data will get uptodate stuff
void waitForDiagnostics
void $ waitForTypecheck doc
actions <- getCodeActions doc $ pointRange it_line it_col
case find ((== Just (tacticTitle it_command it_argument)) . codeActionTitle) actions of
Just (InR CodeAction {_command = Just c}) -> do
executeCommand c
void $ skipManyTill anyMessage $ message SWorkspaceApplyEdit
_ -> error $ show actions


mkGoldenTest
:: (Text -> Text -> Assertion)
-> TacticCommand
-> Text
-> Int
-> Int
-> [InvokeTactic]
-> FilePath
-> SpecWith ()
mkGoldenTest eq tc occ line col input =
mkGoldenTest eq invocations input =
it (input <> " (golden)") $ do
resetGlobalHoleRef
runSessionForTactics $ do
doc <- openDoc (input <.> "hs") "haskell"
-- wait for diagnostics to start coming
void waitForDiagnostics
-- wait for the entire build to finish, so that Tactics code actions that
-- use stale data will get uptodate stuff
void $ waitForTypecheck doc
actions <- getCodeActions doc $ pointRange line col
case find ((== Just (tacticTitle tc occ)) . codeActionTitle) actions of
Just (InR CodeAction {_command = Just c}) -> do
executeCommand c
_resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit)
edited <- documentContents doc
let expected_name = input <.> "expected" <.> "hs"
-- Write golden tests if they don't already exist
liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do
T.writeFile expected_name edited
expected <- liftIO $ T.readFile expected_name
liftIO $ edited `eq` expected
_ -> error $ show actions
traverse_ (invokeTactic doc) invocations
edited <- documentContents doc
let expected_name = input <.> "expected" <.> "hs"
-- Write golden tests if they don't already exist
liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do
T.writeFile expected_name edited
expected <- liftIO $ T.readFile expected_name
liftIO $ edited `eq` expected

mkCodeLensTest
:: FilePath
Expand Down Expand Up @@ -197,10 +204,13 @@ mkShowMessageTest tc occ line col input ufm =


goldenTest :: TacticCommand -> Text -> Int -> Int -> FilePath -> SpecWith ()
goldenTest = mkGoldenTest shouldBe
goldenTest tc occ line col = mkGoldenTest shouldBe [InvokeTactic tc occ line col]

goldenTestMany :: FilePath -> [InvokeTactic] -> SpecWith ()
goldenTestMany = flip $ mkGoldenTest shouldBe

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


shouldBeIgnoringSpaces :: Text -> Text -> Assertion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data Dummy a = Dummy a

f :: Dummy Int -> Int
f (Dummy n) = n

5 changes: 5 additions & 0 deletions plugins/hls-tactics-plugin/test/golden/SubsequentTactics.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data Dummy a = Dummy a

f :: Dummy Int -> Int
f = _