11{-# LANGUAGE DataKinds #-}
22{-# LANGUAGE OverloadedStrings #-}
3- {-# OPTIONS_GHC -Wall #-}
3+ {-# OPTIONS_GHC -Wall -Werror #-}
44
55{-| Logic for renaming qualified import aliases.
66
@@ -47,7 +47,6 @@ import Data.Generics
4747import qualified Data.Map as M
4848import Data.Maybe
4949import qualified Data.Text as T
50- import Debug.Trace (trace , traceShowWith )
5150import Development.IDE (realSrcSpanToCodePointRange )
5251import Development.IDE.Core.FileStore (getVersionedTextDoc )
5352import Development.IDE.Core.PluginUtils
@@ -56,7 +55,6 @@ import Development.IDE.Core.Service hiding (Log)
5655import Development.IDE.Core.Shake hiding (Log )
5756import Development.IDE.GHC.Compat hiding (importDecl )
5857import GHC.Data.FastString (lengthFS )
59- import GHC.Utils.Outputable (showPprUnsafe )
6058import Ide.Plugin.Error
6159import qualified Language.LSP.Protocol.Lens as L
6260import Language.LSP.Protocol.Message
@@ -195,7 +193,8 @@ findAliasUseAtPos ::
195193 Maybe (VFS. CodePointRange , [ImportAlias ])
196194findAliasUseAtPos pos exports imports hsDecls =
197195 let qualifiersAtPos = do
198- locatedRdrName <- locateRdrNames exports hsDecls True
196+ locatedRdrName :: XRec GhcPs RdrName <-
197+ listify (const True ) exports ++ listify (const True ) hsDecls
199198 Qual qualifier _ <- [unLoc locatedRdrName]
200199 RealSrcSpan qualifiedNameSpan _ <- [getLoc locatedRdrName]
201200 let qualifiedNameRange = realSrcSpanToCodePointRange qualifiedNameSpan
@@ -205,7 +204,7 @@ findAliasUseAtPos pos exports imports hsDecls =
205204 qualifierRange = qualifiedNameRange
206205 & VFS. end .~ (qualifierStart & VFS. character +~ qualifierLength)
207206 guard (rangeContainsPositionInclusive qualifierRange pos)
208- traceShowWith ( \ x -> " findAliasUseAtPos/qualifierAtPos: " <> show x) [(qualifierRange, qualifier)]
207+ [(qualifierRange, qualifier)]
209208 in case qualifiersAtPos of
210209 [] -> Nothing
211210 (rangeAtPos, qualifierAtPos) : _ -> Just $ (,) rangeAtPos $ do
@@ -230,7 +229,8 @@ aliasUseSiteRanges ::
230229aliasUseSiteRanges importAlias exports hsDecls = nubOrd $ do
231230 let ImportAlias {aliasName} = importAlias
232231 aliasLength = fromIntegral (moduleNameLength aliasName)
233- locatedRdrName <- locateRdrNames exports hsDecls False
232+ locatedRdrName :: XRec GhcPs RdrName <-
233+ listify (const True ) exports ++ listify (const True ) hsDecls
234234 Qual qualifier _ <- [unLoc locatedRdrName]
235235 guard (qualifier == aliasName)
236236 RealSrcSpan qualifiedNameSpan _ <- [getLoc locatedRdrName]
@@ -275,7 +275,8 @@ aliasUseSiteRangesDisambiguated tcModule importAlias exports hsDecls = nubOrd $
275275 let rdrEnv = tcg_rdr_env (tmrTypechecked tcModule)
276276 ImportAlias {aliasModuleName, aliasName} = importAlias
277277 aliasLength = fromIntegral (moduleNameLength aliasName)
278- locatedRdrName <- locateRdrNames exports hsDecls False
278+ locatedRdrName :: XRec GhcPs RdrName <-
279+ listify (const True ) exports ++ listify (const True ) hsDecls
279280 rdrName@ (Qual qualifier name) <- [unLoc locatedRdrName]
280281 guard (qualifier == aliasName)
281282 nameGREElement <- pickGREs rdrName $ lookupGlobalRdrEnv rdrEnv name
@@ -305,24 +306,6 @@ ambiguousAliasErrorMessage _ = ""
305306---------------------------------------------------------------------------------------------------
306307-- Utility functions
307308
308- instance Show RdrName where
309- show (Unqual name) = show name
310- show (Qual moduleName name) = show moduleName ++ " ." ++ show name
311- show (Orig mod name) = " Orig: " <> show mod <> " ." <> show name
312- show (Exact name) = " Exact: " <> showPprUnsafe name
313-
314- -- | Locate 'RdrName' identifiers in the given export list and declarations.
315- locateRdrNames ::
316- Maybe (XRec GhcPs [LIE GhcPs ]) ->
317- [LHsDecl GhcPs ] ->
318- Bool ->
319- [XRec GhcPs RdrName ]
320- locateRdrNames exports hsDecls traceEveryProducedName =
321- listify const_True exports ++ listify const_True hsDecls
322- where const_True = if traceEveryProducedName
323- then \ x -> trace (" listify: " <> show (unLoc x) <> " at " <> show (getLoc x)) True
324- else const True
325-
326309-- | Check whether a 'CodePointRange' contains a 'CodePointPosition' (inclusive
327310-- start, inclusive end).
328311-- NOTE: The use of inclusive end allows the user to place the cursor at the end
0 commit comments