From 8897bcc54d5c9c1a885615e186b5b05e556aaa63 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 18 Dec 2017 17:21:31 -0800 Subject: [PATCH] [indexer] Display declaration line for typedef/using. fix #141 GetDocumentContentInRange calls clang_tokenize, which is not easy to handle multi-line declarations. Only display declaration lines for one-line `typedef`/`using` now. --- src/indexer.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index 370d41b6..148c89ca 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1240,13 +1240,29 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { if (alias_of) type->def.alias_of = alias_of.value(); - type->def.short_name = decl->entityInfo->name; + + Range spell = ResolveSpelling(decl->cursor); + Range extent = ResolveExtent(decl->cursor); + type->def.definition_spelling = spell; + type->def.definition_extent = extent; + type->def.detailed_name = ns->QualifiedName(decl->semanticContainer, type->def.short_name); + // For single line Typedef/CXXTypeAlias, display the declaration line, + // with spelling name replaced with qualified name. + // TODO Think how to display multi-line declaration like `typedef struct { ... } foo;` + if (extent.start.line == extent.end.line) { + std::string decl_text = GetDocumentContentInRange( + param->tu->cx_tu, clang_getCursorExtent(decl->cursor)); + if (decl_text.size() == extent.end.column - extent.start.column) { + type->def.detailed_name = + decl_text.substr(0, spell.start.column - extent.start.column) + + type->def.detailed_name + + decl_text.substr(spell.end.column - extent.start.column); + } + } - type->def.definition_spelling = ResolveSpelling(decl->cursor); - type->def.definition_extent = ResolveExtent(decl->cursor); UniqueAdd(type->uses, decl_loc_spelling); break; }