|
1 | 1 | {-# LANGUAGE OverloadedStrings #-}
|
2 | 2 | {-# LANGUAGE ScopedTypeVariables #-}
|
| 3 | +{-# LANGUAGE DuplicateRecordFields #-} |
3 | 4 |
|
4 | 5 | module Eval (
|
5 | 6 | tests,
|
6 | 7 | ) where
|
7 | 8 |
|
8 | 9 | import Control.Applicative.Combinators (
|
9 |
| - skipManyTill, |
| 10 | + skipManyTill |
10 | 11 | )
|
| 12 | +import Data.Function |
11 | 13 | import Control.Monad (when)
|
12 | 14 | import Control.Monad.IO.Class (MonadIO (liftIO))
|
13 | 15 | import qualified Data.Text as T
|
14 | 16 | import qualified Data.Text.IO as T
|
15 |
| -import Language.Haskell.LSP.Test ( |
16 |
| - Session, |
17 |
| - anyMessage, |
18 |
| - documentContents, |
19 |
| - executeCommand, |
20 |
| - fullCaps, |
21 |
| - getCodeLenses, |
22 |
| - message, |
23 |
| - openDoc, |
24 |
| - runSession, |
25 |
| - ) |
26 |
| -import Language.Haskell.LSP.Types ( |
27 |
| - ApplyWorkspaceEditRequest, |
28 |
| - CodeLens (CodeLens, _command, _range), |
29 |
| - Command (Command, _title), |
30 |
| - Position (..), |
31 |
| - Range (..), |
32 |
| - TextDocumentIdentifier, |
33 |
| - ) |
| 17 | +import Language.LSP.Test |
| 18 | +import Language.LSP.Types |
| 19 | +import Language.LSP.Types.Lens (command, title, range) |
| 20 | +import Control.Lens (view, _Just, preview) |
34 | 21 | import System.Directory (doesFileExist)
|
35 | 22 | import System.FilePath (
|
36 | 23 | (<.>),
|
@@ -58,27 +45,27 @@ tests =
|
58 | 45 | runSession hlsCommand fullCaps evalPath $ do
|
59 | 46 | doc <- openDoc "T1.hs" "haskell"
|
60 | 47 | lenses <- getEvalCodeLenses doc
|
61 |
| - liftIO $ map (fmap _title . _command) lenses @?= [Just "Evaluate..."] |
| 48 | + liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Evaluate..."] |
62 | 49 | , testCase "Produces Refresh code lenses" $
|
63 | 50 | runSession hlsCommand fullCaps evalPath $ do
|
64 | 51 | doc <- openDoc "T2.hs" "haskell"
|
65 | 52 | lenses <- getEvalCodeLenses doc
|
66 |
| - liftIO $ map (fmap _title . _command) lenses @?= [Just "Refresh..."] |
| 53 | + liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Refresh..."] |
67 | 54 | , testCase "Code lenses have ranges" $
|
68 | 55 | runSession hlsCommand fullCaps evalPath $ do
|
69 | 56 | doc <- openDoc "T1.hs" "haskell"
|
70 | 57 | lenses <- getEvalCodeLenses doc
|
71 |
| - liftIO $ map _range lenses @?= [Range (Position 4 0) (Position 5 0)] |
| 58 | + liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)] |
72 | 59 | , testCase "Multi-line expressions have a multi-line range" $ do
|
73 | 60 | runSession hlsCommand fullCaps evalPath $ do
|
74 | 61 | doc <- openDoc "T3.hs" "haskell"
|
75 | 62 | lenses <- getEvalCodeLenses doc
|
76 |
| - liftIO $ map _range lenses @?= [Range (Position 3 0) (Position 5 0)] |
| 63 | + liftIO $ map (view range) lenses @?= [Range (Position 3 0) (Position 5 0)] |
77 | 64 | , testCase "Executed expressions range covers only the expression" $ do
|
78 | 65 | runSession hlsCommand fullCaps evalPath $ do
|
79 | 66 | doc <- openDoc "T2.hs" "haskell"
|
80 | 67 | lenses <- getEvalCodeLenses doc
|
81 |
| - liftIO $ map _range lenses @?= [Range (Position 4 0) (Position 5 0)] |
| 68 | + liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)] |
82 | 69 | , testCase "Evaluation of expressions" $ goldenTest "T1.hs"
|
83 | 70 | , testCase "Reevaluation of expressions" $ goldenTest "T2.hs"
|
84 | 71 | , testCase "Evaluation of expressions w/ imports" $ goldenTest "T3.hs"
|
@@ -214,7 +201,7 @@ getCodeLensesBy f doc = filter f <$> getCodeLenses doc
|
214 | 201 | executeCmd :: Command -> Session ()
|
215 | 202 | executeCmd cmd = do
|
216 | 203 | executeCommand cmd
|
217 |
| - _resp :: ApplyWorkspaceEditRequest <- skipManyTill anyMessage message |
| 204 | + _resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit) |
218 | 205 | -- liftIO $ print _resp
|
219 | 206 | return ()
|
220 | 207 |
|
|
0 commit comments