@@ -179,14 +179,18 @@ documentHighlight hf rf pos = pure highlights
179
179
highlights = do
180
180
n <- ns
181
181
ref <- fromMaybe [] (M. lookup (Right n) rf)
182
- pure $ makeHighlight ref
183
- makeHighlight (sp,dets) =
184
- DocumentHighlight (realSrcSpanToRange sp) (Just $ highlightType $ identInfo dets)
182
+ maybeToList (makeHighlight n ref)
183
+ makeHighlight n (sp,dets)
184
+ | isTvNameSpace (nameNameSpace n) && isBadSpan n sp = Nothing
185
+ | otherwise = Just $ DocumentHighlight (realSrcSpanToRange sp) (Just $ highlightType $ identInfo dets)
185
186
highlightType s =
186
187
if any (isJust . getScopeFromContext) s
187
188
then HkWrite
188
189
else HkRead
189
190
191
+ isBadSpan :: Name -> RealSrcSpan -> Bool
192
+ isBadSpan n sp = srcSpanStartLine sp /= srcSpanEndLine sp || (srcSpanEndCol sp - srcSpanStartCol sp > lengthFS (occNameFS $ nameOccName n))
193
+
190
194
gotoTypeDefinition
191
195
:: MonadIO m
192
196
=> WithHieDb
@@ -290,30 +294,29 @@ atPoint IdeOptions{} (HAR _ (hf :: HieASTs a) _rf _ kind) (DKMap dm km) env pos
290
294
renderEvidenceTree (T. Node (EvidenceInfo {evidenceDetails= Just (EvLetBind _,_,_)}) [x])
291
295
= renderEvidenceTree x
292
296
renderEvidenceTree (T. Node (EvidenceInfo {evidenceDetails= Just (EvLetBind _,_,_), .. }) xs)
293
- = hang (text " - Evidence of constraint `" O. <> expandType evidenceType O. <> " `" ) 2 $
294
- vcat $ text " depending on:" : map renderEvidenceTree' xs
295
- renderEvidenceTree x = renderEvidenceTree' x
297
+ = hang (text " Evidence of constraint `" O. <> expandType evidenceType O. <> " `" ) 2 $
298
+ vcat $ text " constructed using:" : map renderEvidenceTree' xs
299
+ renderEvidenceTree (T. Node (EvidenceInfo {.. }) _)
300
+ = hang (text " Evidence of constraint `" O. <> expandType evidenceType O. <> " `" ) 2 $
301
+ vcat $ printDets evidenceSpan evidenceDetails : map (text . T. unpack) (definedAt evidenceVar)
296
302
297
303
-- renderEvidenceTree' skips let bound evidence variables and prints the children directly
298
304
renderEvidenceTree' (T. Node (EvidenceInfo {evidenceDetails= Just (EvLetBind _,_,_)}) xs)
299
305
= vcat (map renderEvidenceTree' xs)
300
- renderEvidenceTree' (T. Node (EvidenceInfo {.. }) xs)
301
- = hang (text " - Evidence of constraint `" O. <> expandType evidenceType O. <> " `" ) 2 $
302
- vcat $ map (text . T. unpack) (definedAt evidenceVar)
303
- ++ [printDets evidenceSpan evidenceDetails (null xs)]
304
- ++ map renderEvidenceTree' xs
305
-
306
- printDets :: RealSrcSpan -> Maybe (EvVarSource , Scope , Maybe Span ) -> Bool -> SDoc
307
- printDets _ Nothing True = text " "
308
- printDets _ Nothing False = text " constructed using:"
309
- printDets ospn (Just (src,_,mspn)) _ = pprSrc
306
+ renderEvidenceTree' (T. Node (EvidenceInfo {.. }) _)
307
+ = hang (text " - `" O. <> expandType evidenceType O. <> " `" ) 2 $
308
+ vcat $ printDets evidenceSpan evidenceDetails : map (text . T. unpack) (definedAt evidenceVar)
309
+
310
+ printDets :: RealSrcSpan -> Maybe (EvVarSource , Scope , Maybe Span ) -> SDoc
311
+ printDets _ Nothing = text " using an external instance"
312
+ printDets ospn (Just (src,_,mspn)) = pprSrc
310
313
$$ text " at" <+> ppr spn
311
314
where
312
315
-- Use the bind span if we have one, else use the occurence span
313
316
spn = fromMaybe ospn mspn
314
317
pprSrc = case src of
315
318
-- Users don't know what HsWrappers are
316
- EvWrapperBind -> " bound by type signature or pattern "
319
+ EvWrapperBind -> " bound by a context "
317
320
_ -> ppr src
318
321
#endif
319
322
@@ -352,24 +355,12 @@ typeLocationsAtPoint withHieDb lookupModule _ideOptions pos (HAR _ ast _ _ hieKi
352
355
HQualTy a b -> getTypes [a,b]
353
356
HCastTy a -> getTypes [a]
354
357
_ -> []
355
- <<<<<<< HEAD
356
- in fmap nubOrd $ concatMapM (fmap (fromMaybe [] ) . nameToLocation withHieDb lookupModule) (getTypes ts)
357
- ||||||| parent of dc807c4a (Jump to instance definition and explain typeclass evidence)
358
- in fmap nubOrd $ concatMapM (fmap (fromMaybe [] ) . nameToLocation hiedb lookupModule) (getTypes ts)
359
- =======
360
- in nubOrd <$> concatMapM (fmap (fromMaybe [] ) . nameToLocation hiedb lookupModule) (getTypes ts)
361
- >>>>>>> dc807c4a (Jump to instance definition and explain typeclass evidence)
358
+ in nubOrd <$> concatMapM (fmap (fromMaybe [] ) . nameToLocation withHieDb lookupModule) (getTypes ts)
362
359
HieFresh ->
363
360
let ts = concat $ pointCommand ast pos getts
364
361
getts x = nodeType ni ++ mapMaybe identType (M. elems $ nodeIdentifiers ni)
365
362
where ni = nodeInfo x
366
- <<<<<<< HEAD
367
- in fmap nubOrd $ concatMapM (fmap (fromMaybe [] ) . nameToLocation withHieDb lookupModule) (getTypes ts)
368
- ||||||| parent of dc807c4a (Jump to instance definition and explain typeclass evidence)
369
- in fmap nubOrd $ concatMapM (fmap (fromMaybe [] ) . nameToLocation hiedb lookupModule) (getTypes ts)
370
- =======
371
- in nubOrd <$> concatMapM (fmap (fromMaybe [] ) . nameToLocation hiedb lookupModule) (getTypes ts)
372
- >>>>>>> dc807c4a (Jump to instance definition and explain typeclass evidence)
363
+ in nubOrd <$> concatMapM (fmap (fromMaybe [] ) . nameToLocation withHieDb lookupModule) (getTypes ts)
373
364
374
365
namesInType :: Type -> [Name ]
375
366
namesInType (TyVarTy n) = [varName n]
@@ -394,13 +385,7 @@ locationsAtPoint
394
385
-> Position
395
386
-> HieAstResult
396
387
-> m [Location ]
397
- <<<<<<< HEAD
398
- locationsAtPoint withHieDb lookupModule _ideOptions imports pos ast =
399
- ||||||| parent of dc807c4a (Jump to instance definition and explain typeclass evidence)
400
- locationsAtPoint hiedb lookupModule _ideOptions imports pos ast =
401
- =======
402
- locationsAtPoint hiedb lookupModule _ideOptions imports pos (HAR _ ast _rm _ _) =
403
- >>>>>>> dc807c4a (Jump to instance definition and explain typeclass evidence)
388
+ locationsAtPoint withHieDb lookupModule _ideOptions imports pos (HAR _ ast _rm _ _) =
404
389
let ns = concat $ pointCommand ast pos (M. keys . getNodeIds)
405
390
#if MIN_VERSION_ghc(9,0,1)
406
391
evTrees = mapMaybe (either (const Nothing ) $ getEvidenceTree _rm) ns
@@ -410,16 +395,8 @@ locationsAtPoint hiedb lookupModule _ideOptions imports pos (HAR _ ast _rm _ _)
410
395
#endif
411
396
zeroPos = Position 0 0
412
397
zeroRange = Range zeroPos zeroPos
413
- <<<<<<< HEAD
414
- modToLocation m = fmap (\ fs -> pure $ Location (fromNormalizedUri $ filePathToUri' fs) zeroRange) $ M. lookup m imports
415
- in fmap (nubOrd . concat ) $ mapMaybeM (either (pure . modToLocation) $ nameToLocation withHieDb lookupModule) ns
416
- ||||||| parent of dc807c4a (Jump to instance definition and explain typeclass evidence)
417
- modToLocation m = fmap (\ fs -> pure $ Location (fromNormalizedUri $ filePathToUri' fs) zeroRange) $ M. lookup m imports
418
- in fmap (nubOrd . concat ) $ mapMaybeM (either (pure . modToLocation) $ nameToLocation hiedb lookupModule) ns
419
- =======
420
398
modToLocation m = (\ fs -> pure $ Location (fromNormalizedUri $ filePathToUri' fs) zeroRange) <$> M. lookup m imports
421
- in nubOrd . concat <$> mapMaybeM (either (pure . modToLocation) $ nameToLocation hiedb lookupModule) (ns ++ evNs)
422
- >>>>>>> dc807c4a (Jump to instance definition and explain typeclass evidence)
399
+ in nubOrd . concat <$> mapMaybeM (either (pure . modToLocation) $ nameToLocation withHieDb lookupModule) (ns ++ evNs)
423
400
424
401
-- | Given a 'Name' attempt to find the location where it is defined.
425
402
nameToLocation :: MonadIO m => WithHieDb -> LookupModule m -> Name -> m (Maybe [Location ])
0 commit comments