@@ -66,36 +66,32 @@ getAtPoint file pos = runMaybeT $ do
66
66
! pos' <- MaybeT (return $ fromCurrentPosition mapping pos)
67
67
MaybeT $ liftIO $ fmap (first (toCurrentRange mapping =<< )) <$> AtPoint. atPoint opts hf dkMap env pos'
68
68
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
73
72
:: PositionMapping
74
73
-> 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)
78
92
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
99
95
100
96
-- | Goto Definition.
101
97
getDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [(Location , Identifier )])
@@ -106,10 +102,11 @@ getDefinition file pos = runMaybeT $ do
106
102
(ImportMap imports, _) <- useWithStaleFastMT GetImportMap file
107
103
! pos' <- MaybeT (pure $ fromCurrentPosition mapping pos)
108
104
locationsWithIdentifier <- AtPoint. gotoDefinition withHieDb (lookupMod hiedbWriter) opts imports hf pos'
109
- MaybeT $ do
110
- let (locations, names) = unzip locationsWithIdentifier
111
- curLocations <- toCurrentLocations mapping file locations
112
- pure (Just $ zip curLocations names)
105
+ mapMaybeM (\ (location, identifier) -> do
106
+ fixedLocation <- MaybeT $ toCurrentLocation mapping file location
107
+ pure $ Just (fixedLocation, identifier)
108
+ ) locationsWithIdentifier
109
+
113
110
114
111
getTypeDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [(Location , Identifier )])
115
112
getTypeDefinition file pos = runMaybeT $ do
@@ -118,10 +115,10 @@ getTypeDefinition file pos = runMaybeT $ do
118
115
(hf, mapping) <- useWithStaleFastMT GetHieAst file
119
116
! pos' <- MaybeT (return $ fromCurrentPosition mapping pos)
120
117
locationsWithIdentifier <- AtPoint. gotoTypeDefinition withHieDb (lookupMod hiedbWriter) opts hf pos'
121
- MaybeT $ do
122
- let (locations, names) = unzip locationsWithIdentifier
123
- curLocations <- toCurrentLocations mapping file locations
124
- pure ( Just $ zip curLocations names)
118
+ mapMaybeM ( \ (location, identifier) -> do
119
+ fixedLocation <- MaybeT $ toCurrentLocation mapping file location
120
+ pure $ Just (fixedLocation, identifier)
121
+ ) locationsWithIdentifier
125
122
126
123
highlightAtPoint :: NormalizedFilePath -> Position -> IdeAction (Maybe [DocumentHighlight ])
127
124
highlightAtPoint file pos = runMaybeT $ do
0 commit comments