@@ -43,7 +43,8 @@ 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 (toCurrentPosition ,
47
+ toCurrentRange )
47
48
import Development.IDE.Core.RuleTypes (TcModuleResult (.. ),
48
49
TypeCheck (.. ))
49
50
import qualified Development.IDE.Core.Shake as Shake
@@ -204,19 +205,19 @@ inlayHintDotdotProvider _ state pId InlayHintParams {_textDocument = TextDocumen
204
205
| record <- records
205
206
, pos <- maybeToList $ fmap _start $ recordInfoToDotDotRange record ]
206
207
defnLocsList <- lift $ sequence locations
207
- pure $ InL $ mapMaybe (mkInlayHint crr pragma) defnLocsList
208
+ pure $ InL $ mapMaybe (mkInlayHint crr pragma pm ) defnLocsList
208
209
where
209
- mkInlayHint :: CollectRecordsResult -> NextPragmaInfo -> (Maybe [(Location , Identifier )], RecordInfo ) -> Maybe InlayHint
210
- mkInlayHint CRR {enabledExtensions, nameMap} pragma (defnLocs, record) =
210
+ mkInlayHint :: CollectRecordsResult -> NextPragmaInfo -> PositionMapping -> (Maybe [(Location , Identifier )], RecordInfo ) -> Maybe InlayHint
211
+ mkInlayHint CRR {enabledExtensions, nameMap} pragma pm (defnLocs, record) =
211
212
let range = recordInfoToDotDotRange record
212
213
textEdits = maybeToList (renderRecordInfoAsTextEdit nameMap record)
213
214
<> maybeToList (pragmaEdit enabledExtensions pragma)
214
215
names = renderRecordInfoAsDotdotLabelName record
215
216
in do
216
- end <- fmap _end range
217
+ currentEnd <- range >>= toCurrentPosition pm . _end
217
218
names' <- names
218
219
defnLocs' <- defnLocs
219
- let excludeDotDot (Location _ (Range _ end' )) = end' /= end
220
+ let excludeDotDot (Location _ (Range _ end)) = end /= currentEnd
220
221
-- find location from dotdot definitions that name equal to label name
221
222
findLocation name locations =
222
223
let -- filter locations not within dotdot range
@@ -227,7 +228,7 @@ inlayHintDotdotProvider _ state pId InlayHintParams {_textDocument = TextDocumen
227
228
valueWithLoc = [ (T. pack $ printName name, findLocation name defnLocs') | name <- names' ]
228
229
-- use `, ` to separate labels with definition location
229
230
label = intersperse (mkInlayHintLabelPart (" , " , Nothing )) $ fmap mkInlayHintLabelPart valueWithLoc
230
- pure $ InlayHint { _position = end -- at the end of dotdot
231
+ pure $ InlayHint { _position = currentEnd -- at the end of dotdot
231
232
, _label = InR label
232
233
, _kind = Nothing -- neither a type nor a parameter
233
234
, _textEdits = Just textEdits -- same as CodeAction
@@ -319,11 +320,11 @@ collectNamesRule = defineNoDiagnostics mempty $ \CollectNames nfp -> runMaybeT $
319
320
-- | Collects all 'Name's of a given source file, to be used
320
321
-- in the variable usage analysis.
321
322
getNames :: TcModuleResult -> UniqFM Name [Name ]
322
- #if __GLASGOW_HASKELL__ < 910
323
+
323
324
getNames (tmrRenamed -> (group,_,_,_)) = collectNames group
324
- #else
325
- getNames (tmrRenamed -> (group,_,_,_,_)) = collectNames group
326
- #endif
325
+
326
+
327
+
327
328
328
329
data CollectRecords = CollectRecords
329
330
deriving (Eq , Show , Generic )
@@ -506,11 +507,11 @@ showRecordPatFlds (ConPat _ _ args) = do
506
507
where
507
508
processRecCon (RecCon flds) = Just $ processRecordFlds flds
508
509
processRecCon _ = Nothing
509
- #if __GLASGOW_HASKELL__ < 911
510
+
510
511
getOccName (FieldOcc x _) = Just $ getName x
511
- #else
512
- getOccName ( FieldOcc _ x) = Just $ getName (unLoc x)
513
- #endif
512
+
513
+
514
+
514
515
getOccName _ = Nothing
515
516
getFieldName = getOccName . unLoc . hfbLHS . unLoc
516
517
showRecordPatFlds _ = Nothing
@@ -561,11 +562,11 @@ getRecCons :: LHsExpr GhcTc -> ([RecordInfo], Bool)
561
562
-- because there is a possibility that there were be more than one result per
562
563
-- branch
563
564
564
- #if __GLASGOW_HASKELL__ >= 910
565
- getRecCons (unLoc -> XExpr ( ExpandedThingTc a _)) = (collectRecords a, False )
566
- #else
565
+
566
+
567
+
567
568
getRecCons (unLoc -> XExpr (ExpansionExpr (HsExpanded _ a))) = (collectRecords a, True )
568
- #endif
569
+
569
570
getRecCons e@ (unLoc -> RecordCon _ _ flds)
570
571
| isJust (rec_dotdot flds) = (mkRecInfo e, False )
571
572
where
@@ -593,11 +594,11 @@ getRecCons expr@(unLoc -> app@(HsApp _ _ _)) =
593
594
594
595
getExprFields :: HsExpr GhcTc -> [FieldLabel ]
595
596
getExprFields (XExpr (ConLikeTc (conLikeFieldLabels -> fls) _ _)) = fls
596
- #if __GLASGOW_HASKELL__ >= 911
597
- getExprFields ( XExpr ( WrapExpr _ expr)) = getExprFields expr
598
- #else
597
+
598
+
599
+
599
600
getExprFields (XExpr (WrapExpr (HsWrap _ expr))) = getExprFields expr
600
- #endif
601
+
601
602
getExprFields _ = []
602
603
getRecCons _ = ([] , False )
603
604
0 commit comments