File tree 2 files changed +29
-5
lines changed
plugins/hls-refactor-plugin
src/Development/IDE/Plugin 2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -1771,15 +1771,17 @@ extractDoesNotExportModuleName x
1771
1771
1772
1772
1773
1773
mkRenameEdit :: Maybe T. Text -> Range -> T. Text -> TextEdit
1774
- mkRenameEdit contents range name =
1775
- if maybeIsInfixFunction == Just True
1776
- then TextEdit range (" ` " <> name <> " ` " )
1777
- else TextEdit range name
1774
+ mkRenameEdit contents range name
1775
+ | maybeIsInfixFunction == Just True = TextEdit range ( " ` " <> name <> " ` " )
1776
+ | maybeIsTemplateFunction == Just True = TextEdit range (" ' " <> name)
1777
+ | otherwise = TextEdit range name
1778
1778
where
1779
1779
maybeIsInfixFunction = do
1780
1780
curr <- textInRange range <$> contents
1781
1781
pure $ " `" `T.isPrefixOf` curr && " `" `T.isSuffixOf` curr
1782
-
1782
+ maybeIsTemplateFunction = do
1783
+ curr <- textInRange range <$> contents
1784
+ pure $ " '" `T.isPrefixOf` curr
1783
1785
1784
1786
-- | Extract the type and surround it in parentheses except in obviously safe cases.
1785
1787
--
Original file line number Diff line number Diff line change @@ -609,6 +609,28 @@ renameActionTests = testGroup "rename actions"
609
609
, " foo x y = x `monus` y"
610
610
]
611
611
liftIO $ expectedContentAfterAction @=? contentAfterAction
612
+ , testSession " change template function" $ do
613
+ let content = T. unlines
614
+ [ " {-# LANGUAGE TemplateHaskellQuotes #-}"
615
+ , " module Testing where"
616
+ , " import Language.Haskell.TH (Name)"
617
+ , " foo :: Name"
618
+ , " foo = 'bread"
619
+ ]
620
+ doc <- createDoc " Testing.hs" " haskell" content
621
+ diags <- waitForDiagnostics
622
+ actionsOrCommands <- getCodeActions doc (Range (Position 4 6 ) (Position 4 12 ))
623
+ [fixTypo] <- pure [action | InR action@ CodeAction { _title = actionTitle } <- actionsOrCommands, " break" `T.isInfixOf` actionTitle ]
624
+ executeCodeAction fixTypo
625
+ contentAfterAction <- documentContents doc
626
+ let expectedContentAfterAction = T. unlines
627
+ [ " {-# LANGUAGE TemplateHaskellQuotes #-}"
628
+ , " module Testing where"
629
+ , " import Language.Haskell.TH (Name)"
630
+ , " foo :: Name"
631
+ , " foo = 'break"
632
+ ]
633
+ liftIO $ expectedContentAfterAction @=? contentAfterAction
612
634
]
613
635
614
636
typeWildCardActionTests :: TestTree
You can’t perform that action at this time.
0 commit comments