63
63
#include " llvm/ADT/StringRef.h"
64
64
#include " llvm/Support/Casting.h"
65
65
#include " llvm/Support/Error.h"
66
+ #include " llvm/Support/ErrorHandling.h"
66
67
#include " llvm/Support/Path.h"
67
68
#include " llvm/Support/raw_ostream.h"
68
69
#include < optional>
@@ -2272,7 +2273,7 @@ incomingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index) {
2272
2273
// Initially store the ranges in a map keyed by SymbolID of the caller.
2273
2274
// This allows us to group different calls with the same caller
2274
2275
// into the same CallHierarchyIncomingCall.
2275
- llvm::DenseMap<SymbolID, std::vector<Range >> CallsIn;
2276
+ llvm::DenseMap<SymbolID, std::vector<Location >> CallsIn;
2276
2277
// We can populate the ranges based on a refs request only. As we do so, we
2277
2278
// also accumulate the container IDs into a lookup request.
2278
2279
LookupRequest ContainerLookup;
@@ -2282,8 +2283,8 @@ incomingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index) {
2282
2283
elog (" incomingCalls failed to convert location: {0}" , Loc.takeError ());
2283
2284
return ;
2284
2285
}
2285
- auto It = CallsIn.try_emplace (R.Container , std::vector<Range >{}).first ;
2286
- It->second .push_back (Loc-> range );
2286
+ auto It = CallsIn.try_emplace (R.Container , std::vector<Location >{}).first ;
2287
+ It->second .push_back (* Loc);
2287
2288
2288
2289
ContainerLookup.IDs .insert (R.Container );
2289
2290
});
@@ -2292,9 +2293,21 @@ incomingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index) {
2292
2293
Index->lookup (ContainerLookup, [&](const Symbol &Caller) {
2293
2294
auto It = CallsIn.find (Caller.ID );
2294
2295
assert (It != CallsIn.end ());
2295
- if (auto CHI = symbolToCallHierarchyItem (Caller, Item.uri .file ()))
2296
+ if (auto CHI = symbolToCallHierarchyItem (Caller, Item.uri .file ())) {
2297
+ std::vector<Range> FromRanges;
2298
+ for (const Location &L : It->second ) {
2299
+ if (L.uri != CHI->uri ) {
2300
+ // Call location not in same file as caller.
2301
+ // This can happen in some edge cases. There's not much we can do,
2302
+ // since the protocol only allows returning ranges interpreted as
2303
+ // being in the caller's file.
2304
+ continue ;
2305
+ }
2306
+ FromRanges.push_back (L.range );
2307
+ }
2296
2308
Results.push_back (
2297
- CallHierarchyIncomingCall{std::move (*CHI), std::move (It->second )});
2309
+ CallHierarchyIncomingCall{std::move (*CHI), std::move (FromRanges)});
2310
+ }
2298
2311
});
2299
2312
// Sort results by name of container.
2300
2313
llvm::sort (Results, [](const CallHierarchyIncomingCall &A,
0 commit comments