[PATCH] D55206: [clangd] Get rid of AST matchers in CodeComplete, NFC
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 3 02:48:38 PST 2018
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: arphaman, jkorous, MaskRay, ioeric, ilya-biryukov.
The isIndexedForCodeCompletion is called in the code patch of
SymbolCollector.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D55206
Files:
clangd/CodeComplete.cpp
Index: clangd/CodeComplete.cpp
===================================================================
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -37,7 +37,6 @@
#include "index/Index.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Format/Format.h"
@@ -1645,14 +1644,24 @@
}
bool isIndexedForCodeCompletion(const NamedDecl &ND, ASTContext &ASTCtx) {
- using namespace clang::ast_matchers;
- auto InTopLevelScope = hasDeclContext(
- anyOf(namespaceDecl(), translationUnitDecl(), linkageSpecDecl()));
- return !match(decl(anyOf(InTopLevelScope,
- hasDeclContext(
- enumDecl(InTopLevelScope, unless(isScoped()))))),
- ND, ASTCtx)
- .empty();
+ auto InTopLevelScope = [](const NamedDecl &ND) {
+ switch (ND.getDeclContext()->getDeclKind()) {
+ case Decl::TranslationUnit:
+ case Decl::Namespace:
+ case Decl::LinkageSpec:
+ return true;
+ default:
+ return false;
+ };
+ return false;
+ };
+ if (InTopLevelScope(ND))
+ return true;
+
+ if (const auto *EnumDecl = dyn_cast<clang::EnumDecl>(ND.getDeclContext()))
+ return InTopLevelScope(*EnumDecl) && !EnumDecl->isScoped();
+
+ return false;
}
CompletionItem CodeCompletion::render(const CodeCompleteOptions &Opts) const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55206.176348.patch
Type: text/x-patch
Size: 1482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181203/92ace75e/attachment.bin>
More information about the cfe-commits
mailing list