Skip to content

Commit c5ca3b1

Browse files
author
izuzu
committed
Revert "Demonstrate that listify is lazy"
This reverts commit ef4e33b.
1 parent ef4e33b commit c5ca3b1

4 files changed

Lines changed: 8 additions & 69 deletions

File tree

plugins/hls-rename-plugin/src/Ide/Plugin/Rename/ImportAlias.hs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
4747
import qualified Data.Map as M
4848
import Data.Maybe
4949
import qualified Data.Text as T
50-
import Debug.Trace (trace, traceShowWith)
5150
import Development.IDE (realSrcSpanToCodePointRange)
5251
import Development.IDE.Core.FileStore (getVersionedTextDoc)
5352
import Development.IDE.Core.PluginUtils
@@ -56,7 +55,6 @@ import Development.IDE.Core.Service hiding (Log)
5655
import Development.IDE.Core.Shake hiding (Log)
5756
import Development.IDE.GHC.Compat hiding (importDecl)
5857
import GHC.Data.FastString (lengthFS)
59-
import GHC.Utils.Outputable (showPprUnsafe)
6058
import Ide.Plugin.Error
6159
import qualified Language.LSP.Protocol.Lens as L
6260
import Language.LSP.Protocol.Message
@@ -195,7 +193,8 @@ findAliasUseAtPos ::
195193
Maybe (VFS.CodePointRange, [ImportAlias])
196194
findAliasUseAtPos 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 ::
230229
aliasUseSiteRanges 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

plugins/hls-rename-plugin/test/Main.hs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,6 @@ renameTests = testGroup "Identifier"
130130
rename doc (Position 3 31) "Maybe"
131131
, goldenWithRename "Import alias at use site (shared by unrelated imports)" "ImportAliasShared" $ \doc ->
132132
rename doc (Position 6 6) "Maybe"
133-
134-
-- REVIEW: `listify (const True) exports` produces 2 elements. The 2nd one,
135-
-- `M.isJust`, has its alias at the cursor. The `qualifiersAtPos` pattern
136-
-- match consumes it, and then doesn't consume any more elements. `listify
137-
-- exports` then stops, and `listify hsDecls` is not evaluated at all.
138-
-- The console shows 2 `listify:` traces.
139-
, goldenWithRename "Import alias in export list (proving 'listify' is lazy)" "ImportAliasLazyListify" $ \doc ->
140-
rename doc (Position 0 39) "Maybe"
141-
142-
-- REVIEW: `listify (const True) exports ++ listify (const True) hsDecls`
143-
-- produces elements until it produces one whose alias is at the cursor.
144-
-- This element is then consumed in the pattern match. `listify` then stops
145-
-- producing.
146-
-- The console shows traces for all `RdrName`s except for the `M.fromMaybe`
147-
-- on the last line.
148-
, goldenWithRename "Import alias in definition (proving 'listify' is lazy)" "ImportAliasLazyListify" $ \doc ->
149-
rename doc (Position 9 6) "Maybe"
150-
151133
, goldenWithRename "Import alias declaration (with re-exports)" "ImportAliasReexport" $ \doc -> do
152134
rename doc (Position 1 18) "Reexport"
153135
, testCase "Import alias at use site (ambiguous due to re-exports)" $ runRenameSession "" $ do

plugins/hls-rename-plugin/test/testdata/ImportAliasLazyListify.expected.hs

Lines changed: 0 additions & 13 deletions
This file was deleted.

plugins/hls-rename-plugin/test/testdata/ImportAliasLazyListify.hs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)