From dd84a85b75318badbedb38896263540f76134679 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 17 Jan 2018 00:17:04 -0800 Subject: [PATCH] Filter out inside-out syntax and array types for variable hover --- src/indexer.cc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index aa969676..c4365174 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -437,12 +437,22 @@ void SetVarDetail(IndexVar* var, } else { def.detailed_name = std::move(type_name); ConcatTypeAndName(def.detailed_name, qualified_name); - const FileContents& fc = param->file_contents[db->path]; - optional spell_end = fc.ToOffset(cursor.get_spelling_range().end); - optional extent_end = fc.ToOffset(cursor.get_extent().end); - if (extent_end && *spell_end < *extent_end) - def.hover = def.detailed_name + - fc.content.substr(*spell_end, *extent_end - *spell_end); + // The following check is used to skip inside-out syntax and array types + // which we can't display well. + // For other types, append the textual initializer, bit field, constructor + // or whatever. + CXType deref = cx_type, next; + while ((next = clang_getPointeeType(deref)).kind != CXType_Invalid) + deref = next; + if (clang_getResultType(deref).kind == CXType_Invalid && + clang_getElementType(deref).kind == CXType_Invalid) { + const FileContents& fc = param->file_contents[db->path]; + optional spell_end = fc.ToOffset(cursor.get_spelling_range().end); + optional extent_end = fc.ToOffset(cursor.get_extent().end); + if (extent_end && *spell_end < *extent_end) + def.hover = def.detailed_name + + fc.content.substr(*spell_end, *extent_end - *spell_end); + } } if (is_first_seen) {