From 2dfdabb204fa24c362151314de57955fb6557e60 Mon Sep 17 00:00:00 2001 From: ykiko Date: Sun, 1 Sep 2024 13:06:39 +0800 Subject: [PATCH] update SemanticTokens. --- src/Feature/SemanticTokens.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Feature/SemanticTokens.cpp b/src/Feature/SemanticTokens.cpp index 1dd18973..4fedf719 100644 --- a/src/Feature/SemanticTokens.cpp +++ b/src/Feature/SemanticTokens.cpp @@ -14,7 +14,9 @@ class SemanticToken {}; class Highlighter : public clang::RecursiveASTVisitor { public: - Highlighter(ParsedAST& ast) : fileManager(ast.fileManager), preproc(ast.preproc), sourceManager(ast.sourceManager), context(ast.context), tokenBuffer(ast.tokenBuffer) {} + Highlighter(ParsedAST& ast) : + fileManager(ast.fileManager), preproc(ast.preproc), sourceManager(ast.sourceManager), context(ast.context), + tokenBuffer(ast.tokenBuffer) {} std::vector highlight(llvm::StringRef filepath) { std::vector result; @@ -45,8 +47,9 @@ private: public: Traverse(TranslationUnitDecl) { for(auto decl: node->decls()) { - // we only need to highlight the token in main file. - // so filter out the nodes which are in headers for better performance. + // FIXME: some decls are located in their parents' file + // e.g. `ClassTemplateSpecializationDecl`, find and exclude them + node->getLexicalDeclContext(); if(sourceManager.isInFileID(decl->getLocation(), fileID)) { TraverseDecl(decl); }