@@ -66,56 +66,59 @@ getAtPoint file pos = runMaybeT $ do
6666 ! pos' <- MaybeT (return $ fromCurrentPosition mapping pos)
6767 MaybeT $ liftIO $ fmap (first (toCurrentRange mapping =<< )) <$> AtPoint. atPoint opts hf dkMap env pos'
6868
69- -- | For each Location, determine if we have the PositionMapping
70- -- for the correct file. If not, get the correct position mapping
71- -- and then apply the position mapping to the location.
72- toCurrentLocations
69+ -- | Converts locations in the source code to their current positions,
70+ -- taking into account changes that may have occurred due to edits.
71+ toCurrentLocation
7372 :: PositionMapping
7473 -> NormalizedFilePath
75- -> [Location ]
76- -> IdeAction [Location ]
77- toCurrentLocations mapping file = mapMaybeM go
74+ -> Location
75+ -> IdeAction (Maybe Location )
76+ toCurrentLocation mapping file (Location uri range) =
77+ -- The Location we are going to might be in a different
78+ -- file than the one we are calling gotoDefinition from.
79+ -- So we check that the location file matches the file
80+ -- we are in.
81+ if nUri == normalizedFilePathToUri file
82+ -- The Location matches the file, so use the PositionMapping
83+ -- we have.
84+ then pure $ Location uri <$> toCurrentRange mapping range
85+ -- The Location does not match the file, so get the correct
86+ -- PositionMapping and use that instead.
87+ else do
88+ otherLocationMapping <- fmap (fmap snd ) $ runMaybeT $ do
89+ otherLocationFile <- MaybeT $ pure $ uriToNormalizedFilePath nUri
90+ useWithStaleFastMT GetHieAst otherLocationFile
91+ pure $ Location uri <$> (flip toCurrentRange range =<< otherLocationMapping)
7892 where
79- go :: Location -> IdeAction (Maybe Location )
80- go (Location uri range) =
81- -- The Location we are going to might be in a different
82- -- file than the one we are calling gotoDefinition from.
83- -- So we check that the location file matches the file
84- -- we are in.
85- if nUri == normalizedFilePathToUri file
86- -- The Location matches the file, so use the PositionMapping
87- -- we have.
88- then pure $ Location uri <$> toCurrentRange mapping range
89- -- The Location does not match the file, so get the correct
90- -- PositionMapping and use that instead.
91- else do
92- otherLocationMapping <- fmap (fmap snd ) $ runMaybeT $ do
93- otherLocationFile <- MaybeT $ pure $ uriToNormalizedFilePath nUri
94- useWithStaleFastMT GetHieAst otherLocationFile
95- pure $ Location uri <$> (flip toCurrentRange range =<< otherLocationMapping)
96- where
97- nUri :: NormalizedUri
98- nUri = toNormalizedUri uri
93+ nUri :: NormalizedUri
94+ nUri = toNormalizedUri uri
9995
10096-- | Goto Definition.
101- getDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [Location ])
97+ getDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [( Location , Identifier ) ])
10298getDefinition file pos = runMaybeT $ do
10399 ide@ ShakeExtras { withHieDb, hiedbWriter } <- ask
104100 opts <- liftIO $ getIdeOptionsIO ide
105101 (HAR _ hf _ _ _, mapping) <- useWithStaleFastMT GetHieAst file
106102 (ImportMap imports, _) <- useWithStaleFastMT GetImportMap file
107103 ! pos' <- MaybeT (pure $ fromCurrentPosition mapping pos)
108- locations <- AtPoint. gotoDefinition withHieDb (lookupMod hiedbWriter) opts imports hf pos'
109- MaybeT $ Just <$> toCurrentLocations mapping file locations
104+ locationsWithIdentifier <- AtPoint. gotoDefinition withHieDb (lookupMod hiedbWriter) opts imports hf pos'
105+ mapMaybeM (\ (location, identifier) -> do
106+ fixedLocation <- MaybeT $ toCurrentLocation mapping file location
107+ pure $ Just (fixedLocation, identifier)
108+ ) locationsWithIdentifier
110109
111- getTypeDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [Location ])
110+
111+ getTypeDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [(Location , Identifier )])
112112getTypeDefinition file pos = runMaybeT $ do
113113 ide@ ShakeExtras { withHieDb, hiedbWriter } <- ask
114114 opts <- liftIO $ getIdeOptionsIO ide
115115 (hf, mapping) <- useWithStaleFastMT GetHieAst file
116116 ! pos' <- MaybeT (return $ fromCurrentPosition mapping pos)
117- locations <- AtPoint. gotoTypeDefinition withHieDb (lookupMod hiedbWriter) opts hf pos'
118- MaybeT $ Just <$> toCurrentLocations mapping file locations
117+ locationsWithIdentifier <- AtPoint. gotoTypeDefinition withHieDb (lookupMod hiedbWriter) opts hf pos'
118+ mapMaybeM (\ (location, identifier) -> do
119+ fixedLocation <- MaybeT $ toCurrentLocation mapping file location
120+ pure $ Just (fixedLocation, identifier)
121+ ) locationsWithIdentifier
119122
120123highlightAtPoint :: NormalizedFilePath -> Position -> IdeAction (Maybe [DocumentHighlight ])
121124highlightAtPoint file pos = runMaybeT $ do
0 commit comments