Skip to content

Commit

Permalink
Exclude the implicit prelude import (#2798)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophHochrainer committed Oct 9, 2022
1 parent 4898f5b commit 7c9c968
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ lensProvider
-- haskell-lsp provides conversion functions
| Just nfp <- uriToNormalizedFilePath $ toNormalizedUri _uri = liftIO $
do
mbMinImports <- runAction "" state $ useWithStale MinimalImports nfp
mbMinImports <- runAction "MinimalImports" state $ useWithStale MinimalImports nfp
case mbMinImports of
-- Implement the provider logic:
-- for every import, if it's lacking a explicit list, generate a code lens
Expand Down Expand Up @@ -212,13 +212,23 @@ minimalImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \Minimal
Map.fromList
[ (realSrcSpanStart l, printOutputable i)
| L (locA -> RealSrcSpan l _) i <- fromMaybe [] mbMinImports
, not (isImplicitPrelude i)
]
res =
[ (i, Map.lookup (realSrcSpanStart l) importsMap)
| i <- imports
, RealSrcSpan l _ <- [getLoc i]
]
return ([], MinimalImportsResult res <$ mbMinImports)
where
isImplicitPrelude :: (Outputable a) => a -> Bool
isImplicitPrelude importDecl =
T.isPrefixOf implicitPreludeImportPrefix (printOutputable importDecl)

-- | This is the prefix of an implicit prelude import which should be ignored,
-- when considering the minimal imports rule
implicitPreludeImportPrefix :: T.Text
implicitPreludeImportPrefix = "import (implicit) Prelude"

--------------------------------------------------------------------------------

Expand Down

0 comments on commit 7c9c968

Please sign in to comment.