@@ -43,7 +43,9 @@ import Development.IDE (IdeState,
4343 srcSpanToLocation ,
4444 srcSpanToRange , viaShow )
4545import Development.IDE.Core.PluginUtils
46- import Development.IDE.Core.PositionMapping (toCurrentRange )
46+ import Development.IDE.Core.PositionMapping (PositionMapping ,
47+ toCurrentPosition ,
48+ toCurrentRange )
4749import Development.IDE.Core.RuleTypes (TcModuleResult (.. ),
4850 TypeCheck (.. ))
4951import qualified Development.IDE.Core.Shake as Shake
@@ -204,19 +206,19 @@ inlayHintDotdotProvider _ state pId InlayHintParams {_textDocument = TextDocumen
204206 | record <- records
205207 , pos <- maybeToList $ fmap _start $ recordInfoToDotDotRange record ]
206208 defnLocsList <- lift $ sequence locations
207- pure $ InL $ mapMaybe (mkInlayHint crr pragma) defnLocsList
209+ pure $ InL $ mapMaybe (mkInlayHint crr pragma pm ) defnLocsList
208210 where
209- mkInlayHint :: CollectRecordsResult -> NextPragmaInfo -> (Maybe [(Location , Identifier )], RecordInfo ) -> Maybe InlayHint
210- mkInlayHint CRR {enabledExtensions, nameMap} pragma (defnLocs, record) =
211+ mkInlayHint :: CollectRecordsResult -> NextPragmaInfo -> PositionMapping -> (Maybe [(Location , Identifier )], RecordInfo ) -> Maybe InlayHint
212+ mkInlayHint CRR {enabledExtensions, nameMap} pragma pm (defnLocs, record) =
211213 let range = recordInfoToDotDotRange record
212214 textEdits = maybeToList (renderRecordInfoAsTextEdit nameMap record)
213215 <> maybeToList (pragmaEdit enabledExtensions pragma)
214216 names = renderRecordInfoAsDotdotLabelName record
215217 in do
216- end <- fmap _end range
218+ currentEnd <- range >>= toCurrentPosition pm . _end
217219 names' <- names
218220 defnLocs' <- defnLocs
219- let excludeDotDot (Location _ (Range _ end' )) = end' /= end
221+ let excludeDotDot (Location _ (Range _ end)) = end /= currentEnd
220222 -- find location from dotdot definitions that name equal to label name
221223 findLocation name locations =
222224 let -- filter locations not within dotdot range
@@ -227,7 +229,7 @@ inlayHintDotdotProvider _ state pId InlayHintParams {_textDocument = TextDocumen
227229 valueWithLoc = [ (T. pack $ printName name, findLocation name defnLocs') | name <- names' ]
228230 -- use `, ` to separate labels with definition location
229231 label = intersperse (mkInlayHintLabelPart (" , " , Nothing )) $ fmap mkInlayHintLabelPart valueWithLoc
230- pure $ InlayHint { _position = end -- at the end of dotdot
232+ pure $ InlayHint { _position = currentEnd -- at the end of dotdot
231233 , _label = InR label
232234 , _kind = Nothing -- neither a type nor a parameter
233235 , _textEdits = Just textEdits -- same as CodeAction
@@ -248,20 +250,22 @@ inlayHintPosRecProvider _ state _pId InlayHintParams {_textDocument = TextDocume
248250 | Just range <- [toCurrentRange pm visibleRange]
249251 , uid <- RangeMap. elementsInRange range crCodeActions
250252 , Just record <- [IntMap. lookup uid crCodeActionResolve] ]
251- pure $ InL (concatMap (mkInlayHints nameMap) records)
253+ pure $ InL (concatMap (mkInlayHints nameMap pm ) records)
252254 where
253- mkInlayHints :: UniqFM Name [Name ] -> RecordInfo -> [InlayHint ]
254- mkInlayHints nameMap record@ (RecordInfoApp _ (RecordAppExpr _ fla)) =
255+ mkInlayHints :: UniqFM Name [Name ] -> PositionMapping -> RecordInfo -> [InlayHint ]
256+ mkInlayHints nameMap pm record@ (RecordInfoApp _ (RecordAppExpr _ fla)) =
255257 let textEdits = renderRecordInfoAsTextEdit nameMap record
256- in mapMaybe (mkInlayHint textEdits) fla
257- mkInlayHints _ _ = []
258- mkInlayHint :: Maybe TextEdit -> (Located FieldLabel , HsExpr GhcTc ) -> Maybe InlayHint
259- mkInlayHint te (label, _) =
258+ in mapMaybe (mkInlayHint textEdits pm) fla
259+ mkInlayHints _ _ _ = []
260+
261+ mkInlayHint :: Maybe TextEdit -> PositionMapping -> (Located FieldLabel , HsExpr GhcTc ) -> Maybe InlayHint
262+ mkInlayHint te pm (label, _) =
260263 let (name, loc) = ((flSelector . unLoc) &&& (srcSpanToLocation . getLoc)) label
261264 fieldDefLoc = srcSpanToLocation (nameSrcSpan name)
262265 in do
263266 (Location _ recRange) <- loc
264- pure InlayHint { _position = _start recRange
267+ currentStart <- toCurrentPosition pm (_start recRange)
268+ pure InlayHint { _position = currentStart
265269 , _label = InR $ pure (mkInlayHintLabelPart name fieldDefLoc)
266270 , _kind = Nothing -- neither a type nor a parameter
267271 , _textEdits = Just (maybeToList te) -- same as CodeAction
@@ -270,6 +274,7 @@ inlayHintPosRecProvider _ state _pId InlayHintParams {_textDocument = TextDocume
270274 , _paddingRight = Nothing
271275 , _data_ = Nothing
272276 }
277+
273278 mkInlayHintLabelPart name loc = InlayHintLabelPart (printOutputable (pprNameUnqualified name) <> " =" ) Nothing loc Nothing
274279
275280mkTitle :: [Extension ] -> Text
0 commit comments