11
2- {-# LANGUAGE GADTs #-}
3- {-# LANGUAGE OverloadedLabels #-}
2+ {-# LANGUAGE GADTs #-}
43
54module DiagnosticTests (tests ) where
65
@@ -9,7 +8,6 @@ import qualified Control.Lens as Lens
98import Control.Monad
109import Control.Monad.IO.Class (liftIO )
1110import Data.List.Extra
12- import Data.Row
1311import qualified Data.Text as T
1412import Development.IDE.GHC.Compat (GhcVersion (.. ), ghcVersion )
1513import Development.IDE.GHC.Util
@@ -46,28 +44,34 @@ tests = testGroup "diagnostics"
4644 let content = T. unlines [ " module Testing wher" ]
4745 doc <- createDoc " Testing.hs" " haskell" content
4846 expectDiagnostics [(" Testing.hs" , [(DiagnosticSeverity_Error , (0 , 15 ), " parse error" )])]
49- let change = TextDocumentContentChangeEvent $ InL $ # range .== Range (Position 0 15 ) (Position 0 19 )
50- .+ # rangeLength .== Nothing
51- .+ # text .== " where"
47+ let change = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
48+ { _range = Range (Position 0 15 ) (Position 0 19 )
49+ , _rangeLength = Nothing
50+ , _text = " where"
51+ }
5252 changeDoc doc [change]
5353 expectDiagnostics [(" Testing.hs" , [] )]
5454 , testSessionWait " introduce syntax error" $ do
5555 let content = T. unlines [ " module Testing where" ]
5656 doc <- createDoc " Testing.hs" " haskell" content
5757 void $ skipManyTill anyMessage (message SMethod_WindowWorkDoneProgressCreate )
5858 waitForProgressBegin
59- let change = TextDocumentContentChangeEvent $ InL $ # range .== Range (Position 0 15 ) (Position 0 18 )
60- .+ # rangeLength .== Nothing
61- .+ # text .== " wher"
59+ let change = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
60+ { _range = Range (Position 0 15 ) (Position 0 18 )
61+ , _rangeLength = Nothing
62+ , _text = " wher"
63+ }
6264 changeDoc doc [change]
6365 expectDiagnostics [(" Testing.hs" , [(DiagnosticSeverity_Error , (0 , 15 ), " parse error" )])]
6466 , testSessionWait " update syntax error" $ do
6567 let content = T. unlines [ " module Testing(missing) where" ]
6668 doc <- createDoc " Testing.hs" " haskell" content
6769 expectDiagnostics [(" Testing.hs" , [(DiagnosticSeverity_Error , (0 , 15 ), " Not in scope: 'missing'" )])]
68- let change = TextDocumentContentChangeEvent $ InL $ # range .== Range (Position 0 15 ) (Position 0 16 )
69- .+ # rangeLength .== Nothing
70- .+ # text .== " l"
70+ let change = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
71+ { _range = Range (Position 0 15 ) (Position 0 16 )
72+ , _rangeLength = Nothing
73+ , _text = " l"
74+ }
7175 changeDoc doc [change]
7276 expectDiagnostics [(" Testing.hs" , [(DiagnosticSeverity_Error , (0 , 15 ), " Not in scope: 'lissing'" )])]
7377 , testSessionWait " variable not in scope" $ do
@@ -143,9 +147,11 @@ tests = testGroup "diagnostics"
143147 , " import ModuleA"
144148 ]
145149 _ <- createDoc " ModuleB.hs" " haskell" contentB
146- let change = TextDocumentContentChangeEvent $ InL $ # range .== Range (Position 0 0 ) (Position 0 20 )
147- .+ # rangeLength .== Nothing
148- .+ # text .== " "
150+ let change = TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
151+ { _range = Range (Position 0 0 ) (Position 0 20 )
152+ , _rangeLength = Nothing
153+ , _text = " "
154+ }
149155 changeDoc docA [change]
150156 expectDiagnostics [(" ModuleB.hs" , [(DiagnosticSeverity_Error , (1 , 0 ), " Could not find module" )])]
151157 , testSessionWait " add missing module" $ do
@@ -397,7 +403,7 @@ tests = testGroup "diagnostics"
397403 -- Check that if we put a lower-case drive in for A.A
398404 -- the diagnostics for A.B will also be lower-case.
399405 liftIO $ fileUri @?= uriB
400- let msg :: T. Text = ( head diags) ^. L. message
406+ let msg :: T. Text = head diags ^. L. message
401407 liftIO $ unless (" redundant" `T.isInfixOf` msg) $
402408 assertFailure (" Expected redundant import but got " <> T. unpack msg)
403409 closeDoc a
@@ -463,15 +469,15 @@ tests = testGroup "diagnostics"
463469 [(" P.hs" , [(DiagnosticSeverity_Warning ,(4 ,0 ), " Top-level binding" )])] -- So that we know P has been loaded
464470
465471 -- Change y from Int to B which introduces a type error in A (imported from P)
466- changeDoc bdoc [TextDocumentContentChangeEvent . InR . (.==) # text $
472+ changeDoc bdoc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $
467473 T. unlines [" module B where" , " y :: Bool" , " y = undefined" ]]
468474 expectDiagnostics
469475 [(" A.hs" , [(DiagnosticSeverity_Error , (5 , 4 ), " Couldn't match expected type 'Int' with actual type 'Bool'" )])
470476 ]
471477
472478 -- Open A and edit to fix the type error
473479 adoc <- createDoc aPath " haskell" aSource
474- changeDoc adoc [TextDocumentContentChangeEvent . InR . (.==) # text $
480+ changeDoc adoc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $
475481 T. unlines [" module A where" , " import B" , " x :: Bool" , " x = y" ]]
476482
477483 expectDiagnostics
@@ -489,10 +495,10 @@ tests = testGroup "diagnostics"
489495 doc <- createDoc " Foo.hs" " haskell" fooContent
490496 expectDiagnostics [(" Foo.hs" , [(DiagnosticSeverity_Error , (1 ,7 ), " Could not find module 'MissingModule'" )])]
491497
492- changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) # text $ " module Foo() where" ]
498+ changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ " module Foo() where" ]
493499 expectDiagnostics []
494500
495- changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) # text $ T. unlines
501+ changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ T. unlines
496502 [ " module Foo() where" , " import MissingModule" ] ]
497503 expectDiagnostics [(" Foo.hs" , [(DiagnosticSeverity_Error , (1 ,7 ), " Could not find module 'MissingModule'" )])]
498504
@@ -504,12 +510,18 @@ tests = testGroup "diagnostics"
504510 ]
505511 where
506512 editPair x y = let p = Position x y ; p' = Position x (y+ 2 ) in
507- (TextDocumentContentChangeEvent $ InL $ # range .== Range p p
508- .+ # rangeLength .== Nothing
509- .+ # text .== " fd"
510- ,TextDocumentContentChangeEvent $ InL $ # range .== Range p p'
511- .+ # rangeLength .== Nothing
512- .+ # text .== " " )
513+ (TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
514+ { _range = Range p p
515+ , _rangeLength = Nothing
516+ , _text = " fd"
517+ }
518+
519+ ,TextDocumentContentChangeEvent $ InL TextDocumentContentChangePartial
520+ { _range = Range p' p'
521+ , _rangeLength = Nothing
522+ , _text = " "
523+ }
524+ )
513525 editHeader = editPair 0 0
514526 editImport = editPair 2 10
515527 editBody = editPair 3 10
0 commit comments