@@ -839,8 +839,13 @@ suggestAddTypeAnnotationToSatisfyContraints sourceOpt Diagnostic{_range=_range,.
839
839
in [( title, edits )]
840
840
841
841
842
- suggestReplaceIdentifier :: Maybe T. Text -> Diagnostic -> [(T. Text , [TextEdit ])]
843
- suggestReplaceIdentifier contents Diagnostic {_range= _range,.. }
842
+ -- | GHC strips out backticks in case of infix functions as well as single quote
843
+ -- in case of quoted name when using TemplateHaskellQuotes. Which is not desired.
844
+ --
845
+ -- For example:
846
+ -- 1.
847
+ --
848
+ -- @
844
849
-- File.hs:52:41: error:
845
850
-- * Variable not in scope:
846
851
-- suggestAcion :: Maybe T.Text -> Range -> Range
@@ -852,6 +857,27 @@ suggestReplaceIdentifier contents Diagnostic{_range=_range,..}
852
857
-- ‘T.isInfixOf’ (imported from Data.Text),
853
858
-- ‘T.isSuffixOf’ (imported from Data.Text)
854
859
-- Module ‘Data.Text’ does not export ‘isPrfixOf’.
860
+ -- @
861
+ --
862
+ -- * action: \`suggestAcion\` will be renamed to \`suggestAction\` keeping back ticks around the function
863
+ --
864
+ -- 2.
865
+ --
866
+ -- @
867
+ -- import Language.Haskell.TH (Name)
868
+ -- foo :: Name
869
+ -- foo = 'bread
870
+ --
871
+ -- File.hs:8:7: error:
872
+ -- Not in scope: ‘bread’
873
+ -- * Perhaps you meant one of these:
874
+ -- ‘break’ (imported from Prelude), ‘read’ (imported from Prelude)
875
+ -- * In the Template Haskell quotation 'bread
876
+ -- @
877
+ --
878
+ -- * action: 'bread will be renamed to 'break keeping single quote on beginning of name
879
+ suggestReplaceIdentifier :: Maybe T. Text -> Diagnostic -> [(T. Text , [TextEdit ])]
880
+ suggestReplaceIdentifier contents Diagnostic {_range= _range,.. }
855
881
| renameSuggestions@ (_: _) <- extractRenamableTerms _message
856
882
= [ (" Replace with ‘" <> name <> " ’" , [mkRenameEdit contents _range name]) | name <- renameSuggestions ]
857
883
| otherwise = []
@@ -1771,15 +1797,17 @@ extractDoesNotExportModuleName x
1771
1797
1772
1798
1773
1799
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
1800
+ mkRenameEdit contents range name
1801
+ | maybeIsInfixFunction == Just True = TextEdit range ( " ` " <> name <> " ` " )
1802
+ | maybeIsTemplateFunction == Just True = TextEdit range (" ' " <> name)
1803
+ | otherwise = TextEdit range name
1778
1804
where
1779
1805
maybeIsInfixFunction = do
1780
1806
curr <- textInRange range <$> contents
1781
1807
pure $ " `" `T.isPrefixOf` curr && " `" `T.isSuffixOf` curr
1782
-
1808
+ maybeIsTemplateFunction = do
1809
+ curr <- textInRange range <$> contents
1810
+ pure $ " '" `T.isPrefixOf` curr
1783
1811
1784
1812
-- | Extract the type and surround it in parentheses except in obviously safe cases.
1785
1813
--
0 commit comments