Skip to content
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

Fix extend imports regression #769

Merged
merged 5 commits into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ test-suite ghcide-tests
binary,
bytestring,
containers,
data-default,
directory,
extra,
filepath,
Expand All @@ -325,6 +326,7 @@ test-suite ghcide-tests
haddock-library,
haskell-lsp,
haskell-lsp-types,
hls-plugin-api,
network-uri,
lens,
lsp-test >= 0.11.0.6 && < 0.12,
Expand Down
20 changes: 18 additions & 2 deletions ghcide/src/Development/IDE/Core/OfInterest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ import Development.IDE.Types.Logger
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Shake
import Data.Maybe (catMaybes)
import Data.List.Extra (nubOrd)
import Development.IDE.Import.DependencyInformation
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.Class
import Development.IDE.Types.Options

newtype OfInterestVar = OfInterestVar (Var (HashMap NormalizedFilePath FileOfInterestStatus))
instance IsIdeGlobal OfInterestVar
Expand Down Expand Up @@ -94,11 +99,22 @@ kick = do
ShakeExtras{progressUpdate} <- getShakeExtras
liftIO $ progressUpdate KickStarted

-- Update the exports map for the project
-- Update the exports map for FOIs
ndmitchell marked this conversation as resolved.
Show resolved Hide resolved
(results, ()) <- par (uses GenerateCore files) (void $ uses GetHieAst files)

-- Update the exports map for non FOIs
ndmitchell marked this conversation as resolved.
Show resolved Hide resolved
-- We can skip this if checkProject is True, assuming they never change under our feet.
IdeOptions{ optCheckProject = checkProject } <- getIdeOptions
ifaces <- if checkProject then return Nothing else runMaybeT $ do
deps <- MaybeT $ sequence <$> uses GetDependencies files
hiResults <- lift $ uses GetModIface (nubOrd $ foldMap transitiveModuleDeps deps)
return $ map hirModIface $ catMaybes hiResults

ShakeExtras{exportsMap} <- getShakeExtras
let mguts = catMaybes results
!exportsMap' = createExportsMapMg mguts
liftIO $ modifyVar_ exportsMap $ evaluate . (exportsMap' <>)
!exportsMap'' = maybe mempty createExportsMap ifaces
liftIO $ modifyVar_ exportsMap $ evaluate . (exportsMap'' <>) . (exportsMap' <>)

liftIO $ progressUpdate KickCompleted

13 changes: 10 additions & 3 deletions ghcide/src/Development/IDE/Plugin/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,14 @@ suggestExtendImport exportsMap contents Diagnostic{_range=_range,..}
| Just match <- Map.lookup binding (getExportsMap exportsMap)
, [(ident, _)] <- filter (\(_,m) -> mod == m) (Set.toList match)
= Just ident
| otherwise = Nothing

-- fallback to using GHC suggestion even though it is not always correct
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see a test for this branch added - would be good to see it reflected there.

Copy link
Collaborator Author

@pepeiborra pepeiborra Jan 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I duplicated the test suite to run without checkProject, but I just checked and it doesn't cover this branch. It might be very tricky to construct a test that covers it though, so I'm inclined to leave it until a user complains

| otherwise
= Just IdentInfo
{ name = binding
, rendered = binding
, parent = Nothing
, isDatacon = False}

suggestFixConstructorImport :: Maybe T.Text -> Diagnostic -> [(T.Text, [TextEdit])]
suggestFixConstructorImport _ Diagnostic{_range=_range,..}
Expand Down Expand Up @@ -968,8 +975,8 @@ extractQualifiedModuleName :: T.Text -> Maybe T.Text
extractQualifiedModuleName x
| Just [m] <- matchRegexUnifySpaces x "module named [^‘]*‘([^’]*)’"
= Just m
| otherwise
= Nothing
| otherwise
= Nothing

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

Expand Down
Loading