Skip to content

Change refine imports behaviour for qualified imports #3806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,20 @@ filterByImport _ _ = Nothing

constructImport :: LImportDecl GhcRn -> (ModuleName, [AvailInfo]) -> LImportDecl GhcRn
#if MIN_VERSION_ghc(9,5,0)
constructImport (L lim imd@ImportDecl {ideclName = L _ _, ideclImportList = Just (hiding, L _ names)})
constructImport (L lim imd@ImportDecl {ideclName = L _ _, ideclQualified = qualified, ideclImportList = Just (hiding, L _ names)})
#else
constructImport (L lim imd@ImportDecl{ideclName = L _ _, ideclHiding = Just (hiding, L _ names)})
constructImport (L lim imd@ImportDecl{ideclName = L _ _, ideclQualified = qualified, ideclHiding = Just (hiding, L _ names)})
#endif
(newModuleName, avails) = L lim imd
{ ideclName = noLocA newModuleName
#if MIN_VERSION_ghc(9,5,0)
, ideclImportList = Just (hiding, noLocA newNames)
, ideclImportList = if hiding == Exactly && qualified /= NotQualified
then Nothing
else Just (hiding, noLocA newNames)
#else
, ideclHiding = Just (hiding, noLocA newNames)
, ideclHiding = if hiding == Exactly && qualified /= NotQualified
then Nothing
else Just (hiding, noLocA newNames)
#endif
}
where newNames = filter (\n -> any (n `containsAvail`) avails) names
Expand Down
1 change: 1 addition & 0 deletions plugins/hls-explicit-imports-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ main = defaultTestRunner $ testGroup "import-actions"
"Refine Imports"
[ codeActionGoldenTest "RefineWithOverride" 3 1
, codeLensGoldenTest isRefineImports "RefineUsualCase" 1
, codeLensGoldenTest isRefineImports "RefineQualified" 1
],
testGroup
"Make imports explicit"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Main where

import qualified RefineB as RA
import qualified RefineC as RA
import RefineD
import Data.List (intercalate)

main :: IO ()
main = putStrLn
$ "hello "
<> intercalate ", " [RA.b1, RA.c1, e2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Main where

import qualified RefineA as RA
import RefineD
import Data.List (intercalate)

main :: IO ()
main = putStrLn
$ "hello "
<> intercalate ", " [RA.b1, RA.c1, e2]
2 changes: 1 addition & 1 deletion plugins/hls-explicit-imports-plugin/test/testdata/hie.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

cradle:
direct:
arguments:
Expand All @@ -9,6 +8,7 @@ cradle:
- ExplicitA.hs
- ExplicitB.hs
- RefineUsualCase.hs
- RefineQualified.hs
- RefineWithOverride.hs
- RefineA.hs
- RefineB.hs
Expand Down