|
16 | 16 | #include "Selection.h" |
17 | 17 | #include "SourceCode.h" |
18 | 18 | #include "index/SymbolCollector.h" |
19 | | - |
20 | 19 | #include "clang/AST/ASTContext.h" |
21 | 20 | #include "clang/AST/ASTTypeTraits.h" |
22 | 21 | #include "clang/AST/Decl.h" |
23 | 22 | #include "clang/AST/DeclBase.h" |
24 | 23 | #include "clang/AST/DeclTemplate.h" |
25 | 24 | #include "clang/AST/PrettyPrinter.h" |
| 25 | +#include "clang/AST/Type.h" |
26 | 26 | #include "clang/Index/IndexSymbol.h" |
27 | 27 | #include "llvm/ADT/STLExtras.h" |
28 | 28 | #include "llvm/ADT/SmallVector.h" |
@@ -101,6 +101,7 @@ std::string printDefinition(const Decl *D) { |
101 | 101 | printingPolicyForDecls(D->getASTContext().getPrintingPolicy()); |
102 | 102 | Policy.IncludeTagDefinition = false; |
103 | 103 | Policy.SuppressTemplateArgsInCXXConstructors = true; |
| 104 | + Policy.SuppressTagKeyword = true; |
104 | 105 | D->print(OS, Policy); |
105 | 106 | OS.flush(); |
106 | 107 | return Definition; |
@@ -233,9 +234,7 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D, |
233 | 234 | HI.Parameters->emplace_back(); |
234 | 235 | auto &P = HI.Parameters->back(); |
235 | 236 | if (!PVD->getType().isNull()) { |
236 | | - P.Type.emplace(); |
237 | | - llvm::raw_string_ostream OS(*P.Type); |
238 | | - PVD->getType().print(OS, Policy); |
| 237 | + P.Type = PVD->getType().getAsString(Policy); |
239 | 238 | } else { |
240 | 239 | std::string Param; |
241 | 240 | llvm::raw_string_ostream OS(Param); |
@@ -344,13 +343,10 @@ HoverInfo getHoverContents(const NamedDecl *D, const SymbolIndex *Index) { |
344 | 343 | } |
345 | 344 |
|
346 | 345 | // Fill in types and params. |
347 | | - if (const FunctionDecl *FD = getUnderlyingFunction(D)) { |
| 346 | + if (const FunctionDecl *FD = getUnderlyingFunction(D)) |
348 | 347 | fillFunctionTypeAndParams(HI, D, FD, Policy); |
349 | | - } else if (const auto *VD = dyn_cast<ValueDecl>(D)) { |
350 | | - HI.Type.emplace(); |
351 | | - llvm::raw_string_ostream OS(*HI.Type); |
352 | | - VD->getType().print(OS, Policy); |
353 | | - } |
| 348 | + else if (const auto *VD = dyn_cast<ValueDecl>(D)) |
| 349 | + HI.Type = VD->getType().getAsString(Policy); |
354 | 350 |
|
355 | 351 | // Fill in value with evaluated initializer if possible. |
356 | 352 | if (const auto *Var = dyn_cast<VarDecl>(D)) { |
@@ -380,9 +376,9 @@ HoverInfo getHoverContents(QualType T, ASTContext &ASTCtx, |
380 | 376 | enhanceFromIndex(HI, *CommentD, Index); |
381 | 377 | } else { |
382 | 378 | // Builtin types |
383 | | - llvm::raw_string_ostream OS(HI.Name); |
384 | | - PrintingPolicy Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy()); |
385 | | - T.print(OS, Policy); |
| 379 | + auto Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy()); |
| 380 | + Policy.SuppressTagKeyword = true; |
| 381 | + HI.Name = T.getAsString(Policy); |
386 | 382 | } |
387 | 383 | return HI; |
388 | 384 | } |
|
0 commit comments