Skip to content

Commit ab6c0ec

Browse files
committed
Clean up splice plugin
1 parent d5c4c4e commit ab6c0ec

21 files changed

+82
-113
lines changed

plugins/hls-splice-plugin/hls-splice-plugin.cabal

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ category: Development
1919
build-type: Simple
2020
extra-source-files:
2121
LICENSE
22-
test/testdata/*.error
23-
test/testdata/*.expected
2422
test/testdata/*.hs
2523
test/testdata/*.yaml
2624

@@ -33,14 +31,14 @@ library
3331
hs-source-dirs: src
3432
build-depends:
3533
, aeson
36-
, base >=4.12 && <5
34+
, base >=4.12 && <5
3735
, containers
3836
, dlist
3937
, extra
4038
, foldl
4139
, ghc
4240
, ghc-exactprint
43-
, ghcide >=1.2 && <1.4
41+
, ghcide >=1.2 && <1.4
4442
, hls-plugin-api ^>=1.1
4543
, lens
4644
, lsp
@@ -64,9 +62,7 @@ test-suite tests
6462
ghc-options: -threaded -rtsopts -with-rtsopts=-N
6563
build-depends:
6664
, base
67-
, directory
68-
, extra
6965
, filepath
7066
, hls-splice-plugin
71-
, hls-test-utils ^>= 1.0
67+
, hls-test-utils ^>=1.0
7268
, text
Lines changed: 79 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,109 @@
1-
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE DataKinds #-}
31
{-# LANGUAGE DuplicateRecordFields #-}
2+
{-# LANGUAGE NamedFieldPuns #-}
43
{-# LANGUAGE OverloadedStrings #-}
5-
{-# LANGUAGE ScopedTypeVariables #-}
64
{-# LANGUAGE TypeOperators #-}
75
{-# LANGUAGE ViewPatterns #-}
86

9-
module Main (main) where
7+
module Main
8+
( main
9+
) where
1010

11-
import Control.Monad
11+
import Control.Monad (void)
1212
import Data.List (find)
1313
import Data.Text (Text)
1414
import qualified Data.Text as T
1515
import qualified Data.Text.IO as T
1616
import qualified Ide.Plugin.Splice as Splice
1717
import Ide.Plugin.Splice.Types
18-
import System.Directory
1918
import System.FilePath
20-
import System.Time.Extra (sleep)
2119
import Test.Hls
2220

2321
main :: IO ()
2422
main = defaultTestRunner tests
2523

26-
plugin :: PluginDescriptor IdeState
27-
plugin = Splice.descriptor "splice"
24+
splicePlugin :: PluginDescriptor IdeState
25+
splicePlugin = Splice.descriptor "splice"
2826

2927
tests :: TestTree
30-
tests =
31-
testGroup
32-
"splice"
33-
[ goldenTest "TSimpleExp.hs" Inplace 6 15
34-
, goldenTest "TSimpleExp.hs" Inplace 6 24
35-
, goldenTest "TTypeAppExp.hs" Inplace 7 5
36-
, goldenTest "TErrorExp.hs" Inplace 6 15
37-
, goldenTest "TErrorExp.hs" Inplace 6 51
38-
, goldenTest "TQQExp.hs" Inplace 6 17
39-
, goldenTest "TQQExp.hs" Inplace 6 25
40-
, goldenTest "TQQExpError.hs" Inplace 6 13
41-
, goldenTest "TQQExpError.hs" Inplace 6 22
42-
, testGroup "Pattern Splices"
43-
[ goldenTest "TSimplePat.hs" Inplace 6 3
44-
, goldenTest "TSimplePat.hs" Inplace 6 22
45-
, goldenTest "TSimplePat.hs" Inplace 6 3
46-
, goldenTest "TSimplePat.hs" Inplace 6 22
47-
, goldenTest "TErrorPat.hs" Inplace 6 3
48-
, goldenTest "TErrorPat.hs" Inplace 6 18
49-
, goldenTest "TQQPat.hs" Inplace 6 3
50-
, goldenTest "TQQPat.hs" Inplace 6 11
51-
, goldenTest "TQQPatError.hs" Inplace 6 3
52-
, goldenTest "TQQPatError.hs" Inplace 6 11
53-
]
54-
, goldenTest "TSimpleType.hs" Inplace 5 12
55-
, goldenTest "TSimpleType.hs" Inplace 5 22
56-
, goldenTest "TTypeTypeError.hs" Inplace 7 12
57-
, goldenTest "TTypeTypeError.hs" Inplace 7 52
58-
, goldenTest "TQQType.hs" Inplace 8 19
59-
, goldenTest "TQQType.hs" Inplace 8 28
60-
, goldenTest "TQQTypeTypeError.hs" Inplace 8 19
61-
, goldenTest "TQQTypeTypeError.hs" Inplace 8 28
62-
, goldenTest "TSimpleDecl.hs" Inplace 8 1
63-
, goldenTest "TQQDecl.hs" Inplace 5 1
64-
, goldenTestWithEdit "TTypeKindError.hs" Inplace 7 9
65-
, goldenTestWithEdit "TDeclKindError.hs" Inplace 8 1
66-
]
28+
tests = testGroup "splice"
29+
[ goldenTest "TSimpleExp" Inplace 6 15
30+
, goldenTest "TSimpleExp" Inplace 6 24
31+
, goldenTest "TTypeAppExp" Inplace 7 5
32+
, goldenTest "TErrorExp" Inplace 6 15
33+
, goldenTest "TErrorExp" Inplace 6 51
34+
, goldenTest "TQQExp" Inplace 6 17
35+
, goldenTest "TQQExp" Inplace 6 25
36+
, goldenTest "TQQExpError" Inplace 6 13
37+
, goldenTest "TQQExpError" Inplace 6 22
38+
, testGroup "Pattern Splices"
39+
[ goldenTest "TSimplePat" Inplace 6 3
40+
, goldenTest "TSimplePat" Inplace 6 22
41+
, goldenTest "TSimplePat" Inplace 6 3
42+
, goldenTest "TSimplePat" Inplace 6 22
43+
, goldenTest "TErrorPat" Inplace 6 3
44+
, goldenTest "TErrorPat" Inplace 6 18
45+
, goldenTest "TQQPat" Inplace 6 3
46+
, goldenTest "TQQPat" Inplace 6 11
47+
, goldenTest "TQQPatError" Inplace 6 3
48+
, goldenTest "TQQPatError" Inplace 6 11
49+
]
50+
, goldenTest "TSimpleType" Inplace 5 12
51+
, goldenTest "TSimpleType" Inplace 5 22
52+
, goldenTest "TTypeTypeError" Inplace 7 12
53+
, goldenTest "TTypeTypeError" Inplace 7 52
54+
, goldenTest "TQQType" Inplace 8 19
55+
, goldenTest "TQQType" Inplace 8 28
56+
, goldenTest "TQQTypeTypeError" Inplace 8 19
57+
, goldenTest "TQQTypeTypeError" Inplace 8 28
58+
, goldenTest "TSimpleDecl" Inplace 8 1
59+
, goldenTest "TQQDecl" Inplace 5 1
60+
, goldenTestWithEdit "TTypeKindError" Inplace 7 9
61+
, goldenTestWithEdit "TDeclKindError" Inplace 8 1
62+
]
6763

6864
goldenTest :: FilePath -> ExpandStyle -> Int -> Int -> TestTree
69-
goldenTest input tc line col =
70-
testCase (input <> " (golden)") $ do
71-
runSessionWithServer plugin spliceTestPath $ do
72-
doc <- openDoc input "haskell"
73-
_ <- waitForDiagnostics
74-
actions <- getCodeActions doc $ pointRange line col
75-
case find ((== Just (toExpandCmdTitle tc)) . codeActionTitle) actions of
76-
Just (InR CodeAction {_command = Just c}) -> do
77-
executeCommand c
78-
_resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit)
79-
edited <- documentContents doc
80-
let expected_name = input <.> "expected"
81-
-- Write golden tests if they don't already exist
82-
liftIO $
83-
(doesFileExist expected_name >>=) $
84-
flip unless $ do
85-
T.writeFile expected_name edited
86-
expected <- liftIO $ T.readFile expected_name
87-
liftIO $ edited @?= expected
88-
_ -> liftIO $ assertFailure "No CodeAction detected"
65+
goldenTest fp tc line col =
66+
goldenWithHaskellDoc splicePlugin (fp <> " (golden)") testDataDir fp "expected" "hs" $ \doc -> do
67+
_ <- waitForDiagnostics
68+
actions <- getCodeActions doc $ pointRange line col
69+
case find ((== Just (toExpandCmdTitle tc)) . codeActionTitle) actions of
70+
Just (InR CodeAction {_command = Just c}) -> do
71+
executeCommand c
72+
void $ skipManyTill anyMessage (message SWorkspaceApplyEdit)
73+
_ -> liftIO $ assertFailure "No CodeAction detected"
8974

9075
goldenTestWithEdit :: FilePath -> ExpandStyle -> Int -> Int -> TestTree
91-
goldenTestWithEdit input tc line col =
92-
testCase (input <> " (golden)") $ do
93-
runSessionWithServer plugin spliceTestPath $ do
94-
doc <- openDoc input "haskell"
95-
orig <- documentContents doc
96-
let lns = T.lines orig
97-
theRange =
98-
Range
99-
{ _start = Position 0 0
100-
, _end = Position (length lns + 1) 1
101-
}
102-
waitForProgressDone -- cradle
103-
waitForProgressDone
104-
alt <- liftIO $ T.readFile (input <.> "error")
105-
void $ applyEdit doc $ TextEdit theRange alt
106-
changeDoc doc [TextDocumentContentChangeEvent (Just theRange) Nothing alt]
107-
void waitForDiagnostics
108-
actions <- getCodeActions doc $ pointRange line col
109-
case find ((== Just (toExpandCmdTitle tc)) . codeActionTitle) actions of
110-
Just (InR CodeAction {_command = Just c}) -> do
111-
executeCommand c
112-
_resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit)
113-
edited <- documentContents doc
114-
let expected_name = input <.> "expected"
115-
-- Write golden tests if they don't already exist
116-
liftIO $
117-
(doesFileExist expected_name >>=) $
118-
flip unless $ do
119-
T.writeFile expected_name edited
120-
expected <- liftIO $ T.readFile expected_name
121-
liftIO $ edited @?= expected
122-
_ -> liftIO $ assertFailure "No CodeAction detected"
76+
goldenTestWithEdit fp tc line col =
77+
goldenWithHaskellDoc splicePlugin (fp <> " (golden)") testDataDir fp "expected" "hs" $ \doc -> do
78+
orig <- documentContents doc
79+
let
80+
lns = T.lines orig
81+
theRange =
82+
Range
83+
{ _start = Position 0 0
84+
, _end = Position (length lns + 1) 1
85+
}
86+
waitForProgressDone -- cradle
87+
waitForProgressDone
88+
alt <- liftIO $ T.readFile (fp <.> "error.hs")
89+
void $ applyEdit doc $ TextEdit theRange alt
90+
changeDoc doc [TextDocumentContentChangeEvent (Just theRange) Nothing alt]
91+
void waitForDiagnostics
92+
actions <- getCodeActions doc $ pointRange line col
93+
case find ((== Just (toExpandCmdTitle tc)) . codeActionTitle) actions of
94+
Just (InR CodeAction {_command = Just c}) -> do
95+
executeCommand c
96+
void $ skipManyTill anyMessage (message SWorkspaceApplyEdit)
97+
_ -> liftIO $ assertFailure "No CodeAction detected"
12398

124-
spliceTestPath :: FilePath
125-
spliceTestPath = "test" </> "testdata"
99+
testDataDir :: FilePath
100+
testDataDir = "test" </> "testdata"
126101

127102
pointRange :: Int -> Int -> Range
128-
pointRange
129-
(subtract 1 -> line)
130-
(subtract 1 -> col) =
131-
Range (Position line col) (Position line $ col + 1)
103+
pointRange (subtract 1 -> line) (subtract 1 -> col) =
104+
Range (Position line col) (Position line $ col + 1)
132105

133106
-- | Get the title of a code action.
134107
codeActionTitle :: (Command |? CodeAction) -> Maybe Text
135-
codeActionTitle InL{} = Nothing
136-
codeActionTitle (InR(CodeAction title _ _ _ _ _ _ _)) = Just title
108+
codeActionTitle InL {} = Nothing
109+
codeActionTitle (InR CodeAction {_title}) = Just _title

0 commit comments

Comments
 (0)