File tree 4 files changed +57
-2
lines changed
src/Development/IDE/Plugin 4 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -80,10 +80,13 @@ import Text.Regex.TDFA (mrAfter,
80
80
(=~) , (=~~) )
81
81
#if MIN_VERSION_ghc(9,2,0)
82
82
import GHC (AddEpAnn (AddEpAnn ),
83
+ Anchor (anchor_op ),
84
+ AnchorOperation (.. ),
83
85
AnnsModule (am_main ),
84
86
DeltaPos (.. ),
85
87
EpAnn (.. ),
86
88
EpaLocation (.. ),
89
+ LEpaComment ,
87
90
LocatedA )
88
91
89
92
import Control.Monad (msum )
@@ -1453,8 +1456,16 @@ findPositionAfterModuleName ps hsmodName' = do
1453
1456
1454
1457
epaLocationToLine :: EpaLocation -> Maybe Int
1455
1458
epaLocationToLine (EpaSpan sp) = Just . srcLocLine . realSrcSpanEnd $ sp
1456
- epaLocationToLine (EpaDelta (SameLine _) _) = Just 0
1457
- epaLocationToLine (EpaDelta (DifferentLine line _) _) = Just line
1459
+ epaLocationToLine (EpaDelta (SameLine _) priorComments) = Just $ sumCommentsOffset priorComments
1460
+ epaLocationToLine (EpaDelta (DifferentLine line _) priorComments) = Just (line + sumCommentsOffset priorComments)
1461
+
1462
+ sumCommentsOffset :: [LEpaComment ] -> Int
1463
+ sumCommentsOffset = sum . fmap (\ (L anchor _) -> anchorOpLine (anchor_op anchor))
1464
+
1465
+ anchorOpLine :: AnchorOperation -> Int
1466
+ anchorOpLine UnchangedAnchor = 0
1467
+ anchorOpLine (MovedAnchor (SameLine _)) = 0
1468
+ anchorOpLine (MovedAnchor (DifferentLine line _)) = line
1458
1469
#else
1459
1470
whereKeywordLineOffset = do
1460
1471
ann <- annsA ps M. !? mkAnnKey (astA ps)
Original file line number Diff line number Diff line change
1
+ module Asdf
2
+ (f
3
+ , where' )
4
+ -- hello
5
+ -- world
6
+
7
+ where
8
+ import Data.Int
9
+
10
+
11
+
12
+ f :: Int64 -> Int64
13
+ f = id'
14
+ where id' = id
15
+
16
+ g :: Int -> Int
17
+ g = id
18
+
19
+ where' :: Int -> Int
20
+ where' = id
Original file line number Diff line number Diff line change
1
+ module Asdf
2
+ (f
3
+ , where' )
4
+ -- hello
5
+ -- world
6
+
7
+ where
8
+
9
+
10
+
11
+ f :: Int64 -> Int64
12
+ f = id'
13
+ where id' = id
14
+
15
+ g :: Int -> Int
16
+ g = id
17
+
18
+ where' :: Int -> Int
19
+ where' = id
Original file line number Diff line number Diff line change @@ -912,6 +912,11 @@ insertImportTests = testGroup "insert import"
912
912
" WhereDeclLowerInFile.hs"
913
913
" WhereDeclLowerInFile.expected.hs"
914
914
" import Data.Int"
915
+ , checkImport
916
+ " module where keyword lower in file with comments before it"
917
+ " WhereDeclLowerInFileWithCommentsBeforeIt.hs"
918
+ " WhereDeclLowerInFileWithCommentsBeforeIt.expected.hs"
919
+ " import Data.Int"
915
920
, expectFailBecause
916
921
" 'findNextPragmaPosition' function doesn't account for case when shebang is not placed at top of file"
917
922
(checkImport
You can’t perform that action at this time.
0 commit comments