Skip to content

Commit

Permalink
Add useRange to call hierarchy nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-dyshel committed Feb 22, 2023
1 parent 5b85e1f commit 9efe88b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
18 changes: 18 additions & 0 deletions configure-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -e

export PATH=/usr/local/opt/llvm/bin:$PATH

mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_INSTALL_PREFIX=$HOME/opt/ccls \
-DCMAKE_EXPORT_COMPILE_COMMANDS=YES \
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_PREFIX_PATH=/usr/local/opt/llvm \
-DCMAKE_LINKER=ld.ldd \
-DCMAKE_AR=llvm-ar \
-DCMAKE_RANLIB=llvm-ranlib
ln -sf build/compile_commands.json
20 changes: 14 additions & 6 deletions src/messages/ccls_call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,21 @@ struct Out_cclsCall {
std::string id;
std::string_view name;
Location location;
lsRange useRange;
CallType callType = CallType::Direct;
int numChildren;
// Empty if the |levels| limit is reached.
std::vector<Out_cclsCall> children;
bool operator==(const Out_cclsCall &o) const {
return location == o.location;
return (location == o.location) && (useRange == o.useRange);
}
bool operator<(const Out_cclsCall &o) const
{
return location == o.location ? useRange < o.useRange
: location < o.location;
}
bool operator<(const Out_cclsCall &o) const { return location < o.location; }
};
REFLECT_STRUCT(Out_cclsCall, id, name, location, callType, numChildren,
REFLECT_STRUCT(Out_cclsCall, id, name, location, useRange, callType, numChildren,
children);

struct Out_incomingCall {
Expand All @@ -80,7 +85,7 @@ bool expand(MessageHandler *m, Out_cclsCall *entry, bool callee,
entry->numChildren = 0;
if (!def)
return false;
auto handle = [&](SymbolRef sym, int file_id, CallType call_type1) {
auto handle = [&](SymbolRef sym, int file_id, CallType call_type1, Range useRange) {
entry->numChildren++;
if (levels > 0) {
Out_cclsCall entry1;
Expand All @@ -89,6 +94,9 @@ bool expand(MessageHandler *m, Out_cclsCall *entry, bool callee,
if (auto loc = getLsLocation(m->db, m->wfiles,
Use{{sym.range, sym.role}, file_id}))
entry1.location = *loc;
if (auto loc = getLsLocation(m->db, m->wfiles,
Use{{useRange, sym.role}, file_id}))
entry1.useRange = loc->range;
entry1.callType = call_type1;
if (expand(m, &entry1, callee, call_type, qualified, levels - 1))
entry->children.push_back(std::move(entry1));
Expand All @@ -99,7 +107,7 @@ bool expand(MessageHandler *m, Out_cclsCall *entry, bool callee,
if (const auto *def = func.anyDef())
for (SymbolRef sym : def->callees)
if (sym.kind == Kind::Func)
handle(sym, def->file_id, call_type);
handle(sym, def->file_id, call_type, sym.range);
} else {
for (Use use : func.uses) {
const QueryFile &file1 = m->db->files[use.file_id];
Expand All @@ -111,7 +119,7 @@ bool expand(MessageHandler *m, Out_cclsCall *entry, bool callee,
(!best || best->extent.start < sym.extent.start))
best = sym;
if (best)
handle(*best, use.file_id, call_type);
handle(*best, use.file_id, call_type, use.range);
}
}
};
Expand Down

0 comments on commit 9efe88b

Please sign in to comment.