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