From 61efdcc721b8003903e63816ffc4eed427504eb6 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Wed, 24 Jan 2018 19:15:18 -0800 Subject: [PATCH] Better inline code lens location for functions --- src/messages/text_document_code_lens.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/messages/text_document_code_lens.cc b/src/messages/text_document_code_lens.cc index 24732ab0..08c6af4f 100644 --- a/src/messages/text_document_code_lens.cc +++ b/src/messages/text_document_code_lens.cc @@ -171,28 +171,41 @@ struct TextDocumentCodeLensHandler int16_t offset = 0; + // For functions, the outline will report a location that is using the extent since that is better for outline. This tries to convert the extent location to the spelling location. + auto try_ensure_spelling = [&](SymbolRef sym) { + optional def = GetDefinitionSpellingOfSymbol(db, sym.idx); + if (!def || + def->path != sym.loc.path || + def->range.start.line != sym.loc.range.start.line) { + return sym.loc; + } + return *def; + }; + std::vector base_callers = GetCallersForAllBaseFunctions(db, func); std::vector derived_callers = GetCallersForAllDerivedFunctions(db, func); if (base_callers.empty() && derived_callers.empty()) { + QueryLocation loc = try_ensure_spelling(ref); AddCodeLens("call", "calls", &common, - ref.loc.OffsetStartColumn(offset++), + loc.OffsetStartColumn(offset++), ToQueryLocation(db, func.callers), nullopt, true /*force_display*/); } else { + QueryLocation loc = try_ensure_spelling(ref); AddCodeLens("direct call", "direct calls", &common, - ref.loc.OffsetStartColumn(offset++), + loc.OffsetStartColumn(offset++), ToQueryLocation(db, func.callers), nullopt, false /*force_display*/); if (!base_callers.empty()) AddCodeLens("base call", "base calls", &common, - ref.loc.OffsetStartColumn(offset++), + loc.OffsetStartColumn(offset++), ToQueryLocation(db, base_callers), nullopt, false /*force_display*/); if (!derived_callers.empty()) AddCodeLens("derived call", "derived calls", &common, - ref.loc.OffsetStartColumn(offset++), + loc.OffsetStartColumn(offset++), ToQueryLocation(db, derived_callers), nullopt, false /*force_display*/); }