1
1
2
- {-# LANGUAGE GADTs #-}
3
- {-# LANGUAGE OverloadedLabels #-}
2
+ {-# LANGUAGE GADTs #-}
4
3
5
4
module DiagnosticTests (tests ) where
6
5
@@ -9,7 +8,6 @@ import qualified Control.Lens as Lens
9
8
import Control.Monad
10
9
import Control.Monad.IO.Class (liftIO )
11
10
import Data.List.Extra
12
- import Data.Row
13
11
import qualified Data.Text as T
14
12
import Development.IDE.GHC.Compat (GhcVersion (.. ), ghcVersion )
15
13
import Development.IDE.GHC.Util
@@ -46,28 +44,34 @@ tests = testGroup "diagnostics"
46
44
let content = T. unlines [ " module Testing wher" ]
47
45
doc <- createDoc " Testing.hs" " haskell" content
48
46
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
+ }
52
52
changeDoc doc [change]
53
53
expectDiagnostics [(" Testing.hs" , [] )]
54
54
, testSessionWait " introduce syntax error" $ do
55
55
let content = T. unlines [ " module Testing where" ]
56
56
doc <- createDoc " Testing.hs" " haskell" content
57
57
void $ skipManyTill anyMessage (message SMethod_WindowWorkDoneProgressCreate )
58
58
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
+ }
62
64
changeDoc doc [change]
63
65
expectDiagnostics [(" Testing.hs" , [(DiagnosticSeverity_Error , (0 , 15 ), " parse error" )])]
64
66
, testSessionWait " update syntax error" $ do
65
67
let content = T. unlines [ " module Testing(missing) where" ]
66
68
doc <- createDoc " Testing.hs" " haskell" content
67
69
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
+ }
71
75
changeDoc doc [change]
72
76
expectDiagnostics [(" Testing.hs" , [(DiagnosticSeverity_Error , (0 , 15 ), " Not in scope: 'lissing'" )])]
73
77
, testSessionWait " variable not in scope" $ do
@@ -143,9 +147,11 @@ tests = testGroup "diagnostics"
143
147
, " import ModuleA"
144
148
]
145
149
_ <- 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
+ }
149
155
changeDoc docA [change]
150
156
expectDiagnostics [(" ModuleB.hs" , [(DiagnosticSeverity_Error , (1 , 0 ), " Could not find module" )])]
151
157
, testSessionWait " add missing module" $ do
@@ -397,7 +403,7 @@ tests = testGroup "diagnostics"
397
403
-- Check that if we put a lower-case drive in for A.A
398
404
-- the diagnostics for A.B will also be lower-case.
399
405
liftIO $ fileUri @?= uriB
400
- let msg :: T. Text = ( head diags) ^. L. message
406
+ let msg :: T. Text = head diags ^. L. message
401
407
liftIO $ unless (" redundant" `T.isInfixOf` msg) $
402
408
assertFailure (" Expected redundant import but got " <> T. unpack msg)
403
409
closeDoc a
@@ -463,15 +469,15 @@ tests = testGroup "diagnostics"
463
469
[(" P.hs" , [(DiagnosticSeverity_Warning ,(4 ,0 ), " Top-level binding" )])] -- So that we know P has been loaded
464
470
465
471
-- 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 $
467
473
T. unlines [" module B where" , " y :: Bool" , " y = undefined" ]]
468
474
expectDiagnostics
469
475
[(" A.hs" , [(DiagnosticSeverity_Error , (5 , 4 ), " Couldn't match expected type 'Int' with actual type 'Bool'" )])
470
476
]
471
477
472
478
-- Open A and edit to fix the type error
473
479
adoc <- createDoc aPath " haskell" aSource
474
- changeDoc adoc [TextDocumentContentChangeEvent . InR . (.==) # text $
480
+ changeDoc adoc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $
475
481
T. unlines [" module A where" , " import B" , " x :: Bool" , " x = y" ]]
476
482
477
483
expectDiagnostics
@@ -489,10 +495,10 @@ tests = testGroup "diagnostics"
489
495
doc <- createDoc " Foo.hs" " haskell" fooContent
490
496
expectDiagnostics [(" Foo.hs" , [(DiagnosticSeverity_Error , (1 ,7 ), " Could not find module 'MissingModule'" )])]
491
497
492
- changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) # text $ " module Foo() where" ]
498
+ changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ " module Foo() where" ]
493
499
expectDiagnostics []
494
500
495
- changeDoc doc [TextDocumentContentChangeEvent . InR . (.==) # text $ T. unlines
501
+ changeDoc doc [TextDocumentContentChangeEvent . InR . TextDocumentContentChangeWholeDocument $ T. unlines
496
502
[ " module Foo() where" , " import MissingModule" ] ]
497
503
expectDiagnostics [(" Foo.hs" , [(DiagnosticSeverity_Error , (1 ,7 ), " Could not find module 'MissingModule'" )])]
498
504
@@ -504,12 +510,18 @@ tests = testGroup "diagnostics"
504
510
]
505
511
where
506
512
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
+ )
513
525
editHeader = editPair 0 0
514
526
editImport = editPair 2 10
515
527
editBody = editPair 3 10
0 commit comments