@@ -43,7 +43,8 @@ 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 (toCurrentPosition ,
47+ toCurrentRange )
4748import Development.IDE.Core.RuleTypes (TcModuleResult (.. ),
4849 TypeCheck (.. ))
4950import qualified Development.IDE.Core.Shake as Shake
@@ -204,19 +205,19 @@ inlayHintDotdotProvider _ state pId InlayHintParams {_textDocument = TextDocumen
204205 | record <- records
205206 , pos <- maybeToList $ fmap _start $ recordInfoToDotDotRange record ]
206207 defnLocsList <- lift $ sequence locations
207- pure $ InL $ mapMaybe (mkInlayHint crr pragma) defnLocsList
208+ pure $ InL $ mapMaybe (mkInlayHint crr pragma pm ) defnLocsList
208209 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) =
211212 let range = recordInfoToDotDotRange record
212213 textEdits = maybeToList (renderRecordInfoAsTextEdit nameMap record)
213214 <> maybeToList (pragmaEdit enabledExtensions pragma)
214215 names = renderRecordInfoAsDotdotLabelName record
215216 in do
216- end <- fmap _end range
217+ currentEnd <- range >>= toCurrentPosition pm . _end
217218 names' <- names
218219 defnLocs' <- defnLocs
219- let excludeDotDot (Location _ (Range _ end' )) = end' /= end
220+ let excludeDotDot (Location _ (Range _ end)) = end /= currentEnd
220221 -- find location from dotdot definitions that name equal to label name
221222 findLocation name locations =
222223 let -- filter locations not within dotdot range
@@ -227,7 +228,7 @@ inlayHintDotdotProvider _ state pId InlayHintParams {_textDocument = TextDocumen
227228 valueWithLoc = [ (T. pack $ printName name, findLocation name defnLocs') | name <- names' ]
228229 -- use `, ` to separate labels with definition location
229230 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
231232 , _label = InR label
232233 , _kind = Nothing -- neither a type nor a parameter
233234 , _textEdits = Just textEdits -- same as CodeAction
@@ -319,11 +320,11 @@ collectNamesRule = defineNoDiagnostics mempty $ \CollectNames nfp -> runMaybeT $
319320-- | Collects all 'Name's of a given source file, to be used
320321-- in the variable usage analysis.
321322getNames :: TcModuleResult -> UniqFM Name [Name ]
322- #if __GLASGOW_HASKELL__ < 910
323+
323324getNames (tmrRenamed -> (group,_,_,_)) = collectNames group
324- #else
325- getNames (tmrRenamed -> (group,_,_,_,_)) = collectNames group
326- #endif
325+
326+
327+
327328
328329data CollectRecords = CollectRecords
329330 deriving (Eq , Show , Generic )
@@ -506,11 +507,11 @@ showRecordPatFlds (ConPat _ _ args) = do
506507 where
507508 processRecCon (RecCon flds) = Just $ processRecordFlds flds
508509 processRecCon _ = Nothing
509- #if __GLASGOW_HASKELL__ < 911
510+
510511 getOccName (FieldOcc x _) = Just $ getName x
511- #else
512- getOccName ( FieldOcc _ x) = Just $ getName (unLoc x)
513- #endif
512+
513+
514+
514515 getOccName _ = Nothing
515516 getFieldName = getOccName . unLoc . hfbLHS . unLoc
516517showRecordPatFlds _ = Nothing
@@ -561,11 +562,11 @@ getRecCons :: LHsExpr GhcTc -> ([RecordInfo], Bool)
561562-- because there is a possibility that there were be more than one result per
562563-- branch
563564
564- #if __GLASGOW_HASKELL__ >= 910
565- getRecCons (unLoc -> XExpr ( ExpandedThingTc a _)) = (collectRecords a, False )
566- #else
565+
566+
567+
567568getRecCons (unLoc -> XExpr (ExpansionExpr (HsExpanded _ a))) = (collectRecords a, True )
568- #endif
569+
569570getRecCons e@ (unLoc -> RecordCon _ _ flds)
570571 | isJust (rec_dotdot flds) = (mkRecInfo e, False )
571572 where
@@ -593,11 +594,11 @@ getRecCons expr@(unLoc -> app@(HsApp _ _ _)) =
593594
594595 getExprFields :: HsExpr GhcTc -> [FieldLabel ]
595596 getExprFields (XExpr (ConLikeTc (conLikeFieldLabels -> fls) _ _)) = fls
596- #if __GLASGOW_HASKELL__ >= 911
597- getExprFields ( XExpr ( WrapExpr _ expr)) = getExprFields expr
598- #else
597+
598+
599+
599600 getExprFields (XExpr (WrapExpr (HsWrap _ expr))) = getExprFields expr
600- #endif
601+
601602 getExprFields _ = []
602603getRecCons _ = ([] , False )
603604
0 commit comments