@@ -43,7 +43,9 @@ import Development.IDE (IdeState,
43
43
srcSpanToLocation ,
44
44
srcSpanToRange , viaShow )
45
45
import Development.IDE.Core.PluginUtils
46
- import Development.IDE.Core.PositionMapping (toCurrentRange )
46
+ import Development.IDE.Core.PositionMapping (PositionMapping ,
47
+ toCurrentPosition ,
48
+ toCurrentRange )
47
49
import Development.IDE.Core.RuleTypes (TcModuleResult (.. ),
48
50
TypeCheck (.. ))
49
51
import qualified Development.IDE.Core.Shake as Shake
@@ -204,19 +206,19 @@ inlayHintDotdotProvider _ state pId InlayHintParams {_textDocument = TextDocumen
204
206
| record <- records
205
207
, pos <- maybeToList $ fmap _start $ recordInfoToDotDotRange record ]
206
208
defnLocsList <- lift $ sequence locations
207
- pure $ InL $ mapMaybe (mkInlayHint crr pragma) defnLocsList
209
+ pure $ InL $ mapMaybe (mkInlayHint crr pragma pm ) defnLocsList
208
210
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) =
211
213
let range = recordInfoToDotDotRange record
212
214
textEdits = maybeToList (renderRecordInfoAsTextEdit nameMap record)
213
215
<> maybeToList (pragmaEdit enabledExtensions pragma)
214
216
names = renderRecordInfoAsDotdotLabelName record
215
217
in do
216
- end <- fmap _end range
218
+ currentEnd <- range >>= toCurrentPosition pm . _end
217
219
names' <- names
218
220
defnLocs' <- defnLocs
219
- let excludeDotDot (Location _ (Range _ end' )) = end' /= end
221
+ let excludeDotDot (Location _ (Range _ end)) = end /= currentEnd
220
222
-- find location from dotdot definitions that name equal to label name
221
223
findLocation name locations =
222
224
let -- filter locations not within dotdot range
@@ -227,7 +229,7 @@ inlayHintDotdotProvider _ state pId InlayHintParams {_textDocument = TextDocumen
227
229
valueWithLoc = [ (T. pack $ printName name, findLocation name defnLocs') | name <- names' ]
228
230
-- use `, ` to separate labels with definition location
229
231
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
231
233
, _label = InR label
232
234
, _kind = Nothing -- neither a type nor a parameter
233
235
, _textEdits = Just textEdits -- same as CodeAction
@@ -248,20 +250,22 @@ inlayHintPosRecProvider _ state _pId InlayHintParams {_textDocument = TextDocume
248
250
| Just range <- [toCurrentRange pm visibleRange]
249
251
, uid <- RangeMap. elementsInRange range crCodeActions
250
252
, Just record <- [IntMap. lookup uid crCodeActionResolve] ]
251
- pure $ InL (concatMap (mkInlayHints nameMap) records)
253
+ pure $ InL (concatMap (mkInlayHints nameMap pm ) records)
252
254
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)) =
255
257
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, _) =
260
263
let (name, loc) = ((flSelector . unLoc) &&& (srcSpanToLocation . getLoc)) label
261
264
fieldDefLoc = srcSpanToLocation (nameSrcSpan name)
262
265
in do
263
266
(Location _ recRange) <- loc
264
- pure InlayHint { _position = _start recRange
267
+ currentStart <- toCurrentPosition pm (_start recRange)
268
+ pure InlayHint { _position = currentStart
265
269
, _label = InR $ pure (mkInlayHintLabelPart name fieldDefLoc)
266
270
, _kind = Nothing -- neither a type nor a parameter
267
271
, _textEdits = Just (maybeToList te) -- same as CodeAction
@@ -270,6 +274,7 @@ inlayHintPosRecProvider _ state _pId InlayHintParams {_textDocument = TextDocume
270
274
, _paddingRight = Nothing
271
275
, _data_ = Nothing
272
276
}
277
+
273
278
mkInlayHintLabelPart name loc = InlayHintLabelPart (printOutputable (pprNameUnqualified name) <> " =" ) Nothing loc Nothing
274
279
275
280
mkTitle :: [Extension ] -> Text
0 commit comments