kadircet updated this revision to Diff 246405. kadircet marked 2 inline comments as done. kadircet added a comment.
- Address comments Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75106/new/ https://reviews.llvm.org/D75106 Files: clang-tools-extra/clangd/Selection.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp clang-tools-extra/clangd/unittests/SelectionTests.cpp Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -375,6 +375,9 @@ int test(I *f) { return 42 + [[f.^foo]]; } )cpp", "ObjCPropertyRefExpr"}, + {"struct foo { [[int has^h<:32:>]]; };", "FieldDecl"}, + // FIXME: This should be class itself instead. + {"struct foo { [[fo^o(){}]] };", "CXXConstructorDecl"}, }; for (const Case &C : Cases) { Annotations Test(C.Code); Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -339,14 +339,12 @@ HI.Definition = "~X()"; HI.Parameters.emplace(); }}, - {"class X { operator [[in^t]](); };", + {"class X { operator [[^X]](); };", [](HoverInfo &HI) { HI.NamespaceScope = ""; - HI.Name = "operator int"; - HI.LocalScope = "X::"; - HI.Kind = index::SymbolKind::ConversionFunction; - HI.Definition = "operator int()"; - HI.Parameters.emplace(); + HI.Name = "X"; + HI.Kind = index::SymbolKind::Class; + HI.Definition = "class X {}"; }}, // auto on lambda Index: clang-tools-extra/clangd/Selection.cpp =================================================================== --- clang-tools-extra/clangd/Selection.cpp +++ clang-tools-extra/clangd/Selection.cpp @@ -10,6 +10,7 @@ #include "Logger.h" #include "SourceCode.h" #include "clang/AST/ASTTypeTraits.h" +#include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" @@ -605,13 +606,22 @@ // Usually empty, but sometimes children cover tokens but shouldn't own them. SourceRange earlySourceRange(const DynTypedNode &N) { if (const Decl *D = N.get<Decl>()) { + // We want constructor name to be claimed by TypeLoc not the constructor + // itself. + // FIXME: Unfortunately this doesn't work, even though RecursiveASTVisitor + // traverses the underlying TypeLoc inside DeclarationName, it is null for + // constructors. + if (isa<CXXConstructorDecl>(D)) + return SourceRange(); + // This will capture Field, Function, MSProperty, NonTypeTemplateParm and + // VarDecls. We want the name in the declarator to be claimed by the decl + // and not by any children. For example: // void [[foo]](); - if (auto *FD = llvm::dyn_cast<FunctionDecl>(D)) - return FD->getNameInfo().getSourceRange(); // int (*[[s]])(); - else if (auto *VD = llvm::dyn_cast<VarDecl>(D)) - return VD->getLocation(); - } else if (const auto* CCI = N.get<CXXCtorInitializer>()) { + // struct X { int [[hash]] [32]; [[operator]] int();} + if (auto *DD = llvm::dyn_cast<DeclaratorDecl>(D)) + return DD->getLocation(); + } else if (const auto *CCI = N.get<CXXCtorInitializer>()) { // : [[b_]](42) return CCI->getMemberLocation(); }
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -375,6 +375,9 @@ int test(I *f) { return 42 + [[f.^foo]]; } )cpp", "ObjCPropertyRefExpr"}, + {"struct foo { [[int has^h<:32:>]]; };", "FieldDecl"}, + // FIXME: This should be class itself instead. + {"struct foo { [[fo^o(){}]] };", "CXXConstructorDecl"}, }; for (const Case &C : Cases) { Annotations Test(C.Code); Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -339,14 +339,12 @@ HI.Definition = "~X()"; HI.Parameters.emplace(); }}, - {"class X { operator [[in^t]](); };", + {"class X { operator [[^X]](); };", [](HoverInfo &HI) { HI.NamespaceScope = ""; - HI.Name = "operator int"; - HI.LocalScope = "X::"; - HI.Kind = index::SymbolKind::ConversionFunction; - HI.Definition = "operator int()"; - HI.Parameters.emplace(); + HI.Name = "X"; + HI.Kind = index::SymbolKind::Class; + HI.Definition = "class X {}"; }}, // auto on lambda Index: clang-tools-extra/clangd/Selection.cpp =================================================================== --- clang-tools-extra/clangd/Selection.cpp +++ clang-tools-extra/clangd/Selection.cpp @@ -10,6 +10,7 @@ #include "Logger.h" #include "SourceCode.h" #include "clang/AST/ASTTypeTraits.h" +#include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" @@ -605,13 +606,22 @@ // Usually empty, but sometimes children cover tokens but shouldn't own them. SourceRange earlySourceRange(const DynTypedNode &N) { if (const Decl *D = N.get<Decl>()) { + // We want constructor name to be claimed by TypeLoc not the constructor + // itself. + // FIXME: Unfortunately this doesn't work, even though RecursiveASTVisitor + // traverses the underlying TypeLoc inside DeclarationName, it is null for + // constructors. + if (isa<CXXConstructorDecl>(D)) + return SourceRange(); + // This will capture Field, Function, MSProperty, NonTypeTemplateParm and + // VarDecls. We want the name in the declarator to be claimed by the decl + // and not by any children. For example: // void [[foo]](); - if (auto *FD = llvm::dyn_cast<FunctionDecl>(D)) - return FD->getNameInfo().getSourceRange(); // int (*[[s]])(); - else if (auto *VD = llvm::dyn_cast<VarDecl>(D)) - return VD->getLocation(); - } else if (const auto* CCI = N.get<CXXCtorInitializer>()) { + // struct X { int [[hash]] [32]; [[operator]] int();} + if (auto *DD = llvm::dyn_cast<DeclaratorDecl>(D)) + return DD->getLocation(); + } else if (const auto *CCI = N.get<CXXCtorInitializer>()) { // : [[b_]](42) return CCI->getMemberLocation(); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits