Skip to content

Commit fbb96e8

Browse files
wz1000mergify[bot]
andauthored
Make find-definition work better with multi-components (#1357)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent d87a5db commit fbb96e8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ghcide/src/Development/IDE/Spans/AtPoint.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,15 @@ nameToLocation hiedb lookupModule name = runMaybeT $
318318
mod <- MaybeT $ return $ nameModule_maybe name
319319
erow <- liftIO $ findDef hiedb (nameOccName name) (Just $ moduleName mod) (Just $ moduleUnitId mod)
320320
case erow of
321-
[] -> MaybeT $ pure Nothing
321+
[] -> do
322+
-- If the lookup failed, try again without specifying a unit-id.
323+
-- This is a hack to make find definition work better with ghcide's nascent multi-component support,
324+
-- where names from a component that has been indexed in a previous session but not loaded in this
325+
-- session may end up with different unit ids
326+
erow <- liftIO $ findDef hiedb (nameOccName name) (Just $ moduleName mod) Nothing
327+
case erow of
328+
[] -> MaybeT $ pure Nothing
329+
xs -> lift $ mapMaybeM (runMaybeT . defRowToLocation lookupModule) xs
322330
xs -> lift $ mapMaybeM (runMaybeT . defRowToLocation lookupModule) xs
323331

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

0 commit comments

Comments
 (0)