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

Make find-definition work better with multi-components #1357

Merged
merged 4 commits into from
Feb 13, 2021
Merged
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
10 changes: 9 additions & 1 deletion ghcide/src/Development/IDE/Spans/AtPoint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,15 @@ nameToLocation hiedb lookupModule name = runMaybeT $
mod <- MaybeT $ return $ nameModule_maybe name
erow <- liftIO $ findDef hiedb (nameOccName name) (Just $ moduleName mod) (Just $ moduleUnitId mod)
case erow of
[] -> MaybeT $ pure Nothing
[] -> do
-- If the lookup failed, try again without specifying a unit-id.
-- This is a hack to make find definition work better with ghcide's nascent multi-component support,
-- where names from a component that has been indexed in a previous session but not loaded in this
-- session may end up with different unit ids
erow <- liftIO $ findDef hiedb (nameOccName name) (Just $ moduleName mod) Nothing
case erow of
[] -> MaybeT $ pure Nothing
xs -> lift $ mapMaybeM (runMaybeT . defRowToLocation lookupModule) xs
xs -> lift $ mapMaybeM (runMaybeT . defRowToLocation lookupModule) xs

defRowToLocation :: Monad m => LookupModule m -> Res DefRow -> MaybeT m Location
Expand Down