From 3e1a068c19b461c9b09c04cde008385c39f5f161 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 2 Jan 2018 16:30:03 -0800 Subject: [PATCH] Make implicit calls spanning one more column to the left/right This is hacky but useful. e.g. textDocument/definition on the space/semicolon in `A a;` or `return 42;` will take you to the constructor. --- src/query.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/query.cc b/src/query.cc index 4b867cb1..39e54c47 100644 --- a/src/query.cc +++ b/src/query.cc @@ -230,9 +230,17 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) { add_outline(id_map.ToSymbol(func.id), decl.spelling); } for (const IndexFuncRef& caller : func.callers) { - // if (caller.is_implicit) - // continue; - add_all_symbols(id_map.ToSymbol(func.id), caller.loc); + // Make ranges of implicit function calls larger (spanning one more column + // to the left/right). This is hacky but useful. e.g. + // textDocument/definition on the space/semicolon in `A a;` or `return 42;` + // will take you to the constructor. + Range range = caller.loc; + if (caller.is_implicit) { + if (range.start.column > 1) + range.start.column--; + range.end.column++; + } + add_all_symbols(id_map.ToSymbol(func.id), range); } } for (const IndexVar& var : indexed.vars) {