Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
(results, ()) <- par (uses GenerateCore files) (void $ uses GetHieAst files)

-- Update the exports map for non FOIs
-- 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