File tree 2 files changed +27
-1
lines changed
src/Development/IDE/Plugin/CodeAction 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -529,12 +529,16 @@ addCommaInImportList :: Monad m =>
529
529
-> m [LocatedAn AnnListItem a ]
530
530
addCommaInImportList lies x = do
531
531
let hasSibling = not (null lies)
532
+ (EpAnn _ lastItem _) = let (L item _) = last lies in ann (item)
533
+ isTrailingCommaAnn (AddCommaAnn _) = True
534
+ isTrailingCommaAnn _ = False
535
+ lastItemHasTrailingComma = any isTrailingCommaAnn (lann_trailing lastItem)
532
536
-- Add the space before the comma
533
537
x <- pure $ setEntryDP x (SameLine $ if hasSibling then 1 else 0 )
534
538
535
539
-- Add the comma (if needed)
536
540
let
537
- fixLast = if hasSibling then first addComma else id
541
+ fixLast = if hasSibling && not lastItemHasTrailingComma then first addComma else id
538
542
lies' = over _last fixLast lies ++ [x]
539
543
540
544
pure lies'
Original file line number Diff line number Diff line change @@ -1882,6 +1882,28 @@ extendImportTests = testGroup "extend import actions"
1882
1882
, " )"
1883
1883
, " main = print (stuffA, stuffB)"
1884
1884
])
1885
+ , testSession " extend multi line import with trailing comma" $ template
1886
+ [(" ModuleA.hs" , T. unlines
1887
+ [ " module ModuleA where"
1888
+ , " stuffA :: Double"
1889
+ , " stuffA = 0.00750"
1890
+ , " stuffB :: Integer"
1891
+ , " stuffB = 123"
1892
+ ])]
1893
+ (" ModuleB.hs" , T. unlines
1894
+ [ " module ModuleB where"
1895
+ , " import ModuleA (stuffB,"
1896
+ , " )"
1897
+ , " main = print (stuffA, stuffB)"
1898
+ ])
1899
+ (Range (Position 3 17 ) (Position 3 18 ))
1900
+ [" Add stuffA to the import list of ModuleA" ]
1901
+ (T. unlines
1902
+ [ " module ModuleB where"
1903
+ , " import ModuleA (stuffB, stuffA"
1904
+ , " )"
1905
+ , " main = print (stuffA, stuffB)"
1906
+ ])
1885
1907
, testSession " extend single line import with method within class" $ template
1886
1908
[(" ModuleA.hs" , T. unlines
1887
1909
[ " module ModuleA where"
You can’t perform that action at this time.
0 commit comments