@@ -23,6 +23,10 @@ module Development.IDE.Spans.AtPoint (
23
23
, LookupModule
24
24
) where
25
25
26
+
27
+ import GHC.Data.FastString (lengthFS )
28
+ import qualified GHC.Utils.Outputable as O
29
+
26
30
import Development.IDE.GHC.Error
27
31
import Development.IDE.GHC.Orphans ()
28
32
import Development.IDE.Types.Location
@@ -59,7 +63,6 @@ import Data.Tree
59
63
import qualified Data.Tree as T
60
64
import Data.Version (showVersion )
61
65
import Development.IDE.Types.Shake (WithHieDb )
62
- import qualified GHC.Utils.Outputable as O
63
66
import HieDb hiding (pointCommand ,
64
67
withHieDb )
65
68
import System.Directory (doesFileExist )
@@ -174,14 +177,18 @@ documentHighlight hf rf pos = pure highlights
174
177
highlights = do
175
178
n <- ns
176
179
ref <- fromMaybe [] (M. lookup (Right n) rf)
177
- pure $ makeHighlight ref
178
- makeHighlight (sp,dets) =
179
- DocumentHighlight (realSrcSpanToRange sp) (Just $ highlightType $ identInfo dets)
180
+ maybeToList (makeHighlight n ref)
181
+ makeHighlight n (sp,dets)
182
+ | isTvNameSpace (nameNameSpace n) && isBadSpan n sp = Nothing
183
+ | otherwise = Just $ DocumentHighlight (realSrcSpanToRange sp) (Just $ highlightType $ identInfo dets)
180
184
highlightType s =
181
185
if any (isJust . getScopeFromContext) s
182
186
then DocumentHighlightKind_Write
183
187
else DocumentHighlightKind_Read
184
188
189
+ isBadSpan :: Name -> RealSrcSpan -> Bool
190
+ isBadSpan n sp = srcSpanStartLine sp /= srcSpanEndLine sp || (srcSpanEndCol sp - srcSpanStartCol sp > lengthFS (occNameFS $ nameOccName n))
191
+
185
192
-- | Locate the type definition of the name at a given position.
186
193
gotoTypeDefinition
187
194
:: MonadIO m
@@ -327,23 +334,22 @@ atPoint IdeOptions{} (HAR _ (hf :: HieASTs a) rf _ (kind :: HieKind hietype)) (D
327
334
renderEvidenceTree (T. Node (EvidenceInfo {evidenceDetails= Just (EvLetBind _,_,_)}) [x])
328
335
= renderEvidenceTree x
329
336
renderEvidenceTree (T. Node (EvidenceInfo {evidenceDetails= Just (EvLetBind _,_,_), .. }) xs)
330
- = hang (text " - Evidence of constraint `" O. <> expandType evidenceType O. <> " `" ) 2 $
331
- vcat $ text " depending on:" : map renderEvidenceTree' xs
332
- renderEvidenceTree x = renderEvidenceTree' x
337
+ = hang (text " Evidence of constraint `" O. <> expandType evidenceType O. <> " `" ) 2 $
338
+ vcat $ text " constructed using:" : map renderEvidenceTree' xs
339
+ renderEvidenceTree (T. Node (EvidenceInfo {.. }) _)
340
+ = hang (text " Evidence of constraint `" O. <> expandType evidenceType O. <> " `" ) 2 $
341
+ vcat $ printDets evidenceSpan evidenceDetails : map (text . T. unpack) (maybeToList $ definedAt evidenceVar)
333
342
334
343
-- renderEvidenceTree' skips let bound evidence variables and prints the children directly
335
344
renderEvidenceTree' (T. Node (EvidenceInfo {evidenceDetails= Just (EvLetBind _,_,_)}) xs)
336
345
= vcat (map renderEvidenceTree' xs)
337
- renderEvidenceTree' (T. Node (EvidenceInfo {.. }) xs)
338
- = hang (text " - Evidence of constraint `" O. <> expandType evidenceType O. <> " `" ) 2 $
339
- vcat $ map (text . T. unpack) (maybeToList $ definedAt evidenceVar)
340
- ++ [printDets evidenceSpan evidenceDetails (null xs)]
341
- ++ map renderEvidenceTree' xs
342
-
343
- printDets :: RealSrcSpan -> Maybe (EvVarSource , Scope , Maybe Span ) -> Bool -> SDoc
344
- printDets _ Nothing True = text " "
345
- printDets _ Nothing False = text " constructed using:"
346
- printDets ospn (Just (src,_,mspn)) _ = pprSrc
346
+ renderEvidenceTree' (T. Node (EvidenceInfo {.. }) _)
347
+ = hang (text " - `" O. <> expandType evidenceType O. <> " `" ) 2 $
348
+ vcat $ printDets evidenceSpan evidenceDetails : map (text . T. unpack) (maybeToList $ definedAt evidenceVar)
349
+
350
+ printDets :: RealSrcSpan -> Maybe (EvVarSource , Scope , Maybe Span ) -> SDoc
351
+ printDets _ Nothing = text " using an external instance"
352
+ printDets ospn (Just (src,_,mspn)) = pprSrc
347
353
$$ text " at" <+> ppr spn
348
354
where
349
355
-- Use the bind span if we have one, else use the occurence span
@@ -409,37 +415,19 @@ locationsAtPoint
409
415
-> IdeOptions
410
416
-> M. Map ModuleName NormalizedFilePath
411
417
-> Position
412
- <<<<<<< HEAD
413
- -> HieASTs a
414
- -> m [(Location , Identifier )]
415
- locationsAtPoint withHieDb lookupModule _ideOptions imports pos ast =
416
- ||||||| parent of 86 ebcf859 (Jump to instance definition and explain typeclass evidence)
417
- -> HieASTs a
418
- -> m [Location ]
419
- locationsAtPoint withHieDb lookupModule _ideOptions imports pos ast =
420
- =======
421
418
-> HieAstResult
422
- -> m [Location ]
419
+ -> m [( Location , Identifier ) ]
423
420
locationsAtPoint withHieDb lookupModule _ideOptions imports pos (HAR _ ast _rm _ _) =
424
- >>>>>>> 86 ebcf859 (Jump to instance definition and explain typeclass evidence)
425
421
let ns = concat $ pointCommand ast pos (M. keys . getNodeIds)
426
422
evTrees = mapMaybe (either (const Nothing ) $ getEvidenceTree _rm) ns
427
423
evNs = concatMap (map (Right . evidenceVar) . T. flatten) evTrees
428
424
zeroPos = Position 0 0
429
425
zeroRange = Range zeroPos zeroPos
430
- <<<<<<< HEAD
431
426
modToLocation m = fmap (\ fs -> pure (Location (fromNormalizedUri $ filePathToUri' fs) zeroRange)) $ M. lookup m imports
432
427
in fmap (nubOrd . concat ) $ mapMaybeM
433
428
(either (\ m -> pure ((fmap $ fmap (,Left m)) (modToLocation m)))
434
429
(\ n -> fmap (fmap $ fmap (,Right n)) (nameToLocation withHieDb lookupModule n)))
435
- ns
436
- ||||||| parent of 86 ebcf859 (Jump to instance definition and explain typeclass evidence)
437
- modToLocation m = fmap (\ fs -> pure $ Location (fromNormalizedUri $ filePathToUri' fs) zeroRange) $ M. lookup m imports
438
- in fmap (nubOrd . concat ) $ mapMaybeM (either (pure . modToLocation) $ nameToLocation withHieDb lookupModule) ns
439
- =======
440
- modToLocation m = (\ fs -> pure $ Location (fromNormalizedUri $ filePathToUri' fs) zeroRange) <$> M. lookup m imports
441
- in nubOrd . concat <$> mapMaybeM (either (pure . modToLocation) $ nameToLocation withHieDb lookupModule) (ns ++ evNs)
442
- >>>>>>> 86 ebcf859 (Jump to instance definition and explain typeclass evidence)
430
+ (ns ++ evNs)
443
431
444
432
-- | Given a 'Name' attempt to find the location where it is defined.
445
433
nameToLocation :: MonadIO m => WithHieDb -> LookupModule m -> Name -> m (Maybe [Location ])
0 commit comments