From 0ef5aec3fc451f51ca6ae0648ae1213c99372435 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 8 Jan 2018 00:19:32 -0800 Subject: [PATCH] Initial values of variables are useful. For now, enable it for const qualified types. Qualified names may also be useful but they can not be easily combined. See #260 --- src/indexer.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index c675de45..81894292 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -409,8 +409,8 @@ void SetVarDetail(IndexVar* var, IndexFile* db, IndexParam* param) { IndexVar::Def& def = var->def; - std::string type_name = - ToString(clang_getTypeSpelling(clang_getCursorType(cursor.cx_cursor))); + const CXType cx_type = clang_getCursorType(cursor.cx_cursor); + std::string type_name = ToString(clang_getTypeSpelling(cx_type)); // clang may report "(lambda at foo.cc)" which end up being a very long // string. Shorten it to just "lambda". if (type_name.find("(lambda at") != std::string::npos) @@ -427,6 +427,12 @@ void SetVarDetail(IndexVar* var, def.detailed_name = std::move(type_name); ConcatTypeAndName(def.detailed_name, qualified_name); } + // TODO Initial values of variables are useful. For now, enable it for const + // qualified types. Qualified names may also be useful but they can not be + // easily combined. + if (clang_isConstQualifiedType(cx_type)) + def.hover = GetDocumentContentInRange( + param->tu->cx_tu, clang_getCursorExtent(cursor.cx_cursor)); if (is_first_seen) { optional var_type = ResolveToDeclarationType(db, cursor);