From 8e70a1078e63828afad2276d8741bd077780a205 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 28 Feb 2018 17:53:43 -0800 Subject: [PATCH] Use call sites for callHierarchy --- src/message_handler.cc | 3 ++- src/messages/cquery_call_hierarchy.cc | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/message_handler.cc b/src/message_handler.cc index 4cf6e718..d5fbdd95 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -167,7 +167,8 @@ void EmitSemanticHighlighting(QueryDatabase* db, if (start_line >= 0 && start_line < working_file->index_lines.size()) { std::string_view line = working_file->index_lines[start_line]; sym.range.end.line = start_line; - if (line.compare(start_col, concise_name.size(), concise_name) == 0) + if (start_col + concise_name.size() <= line.size() && + line.compare(start_col, concise_name.size(), concise_name) == 0) sym.range.end.column = start_col + concise_name.size(); else continue; // applies to for loop diff --git a/src/messages/cquery_call_hierarchy.cc b/src/messages/cquery_call_hierarchy.cc index 905253cb..aadac31b 100644 --- a/src/messages/cquery_call_hierarchy.cc +++ b/src/messages/cquery_call_hierarchy.cc @@ -84,6 +84,8 @@ bool Expand(MessageHandler* m, if (levels > 0) { Out_CqueryCallHierarchy::Entry entry1; entry1.id = QueryFuncId(use.id); + if (auto loc = GetLsLocation(m->db, m->working_files, use)) + entry1.location = *loc; entry1.callType = call_type; if (Expand(m, &entry1, callee, call_type, detailed_name, levels - 1)) entry->children.push_back(std::move(entry1)); @@ -109,11 +111,6 @@ bool Expand(MessageHandler* m, entry->name = def->detailed_name; else entry->name = def->ShortName(); - if (def->spell) { - if (optional loc = - GetLsLocation(m->db, m->working_files, *def->spell)) - entry->location = *loc; - } handle_uses(func, CallType::Direct); // Callers/callees of base functions. @@ -166,6 +163,11 @@ struct CqueryCallHierarchyHandler Out_CqueryCallHierarchy::Entry entry; entry.id = root_id; entry.callType = CallType::Direct; + if (def->spell) { + if (optional loc = + GetLsLocation(db, working_files, *def->spell)) + entry.location = *loc; + } Expand(this, &entry, callee, call_type, detailed_name, levels); return entry; }