https://github.com/Decodetalkers updated https://github.com/llvm/llvm-project/pull/204511
>From fe14332bfc0507e85cb9fa86c6b8b9acb979950c Mon Sep 17 00:00:00 2001 From: ShootingStarDragons <[email protected]> Date: Thu, 18 Jun 2026 18:08:05 +0900 Subject: [PATCH 1/2] feat: highlight for keyword of import, export in CXX module This pr aims to add highlight for import and export keyword And induced new SemanticHighlight `keyword` --- .../clangd/SemanticHighlighting.cpp | 17 +++++++++++++++++ clang-tools-extra/clangd/SemanticHighlighting.h | 1 + 2 files changed, 18 insertions(+) diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index 856904bc810d1..19b5af7e58f30 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -582,6 +582,19 @@ class CollectExtraHighlightings return true; } + bool VisitImportDecl(const ImportDecl *D) { + H.addToken(D->getLocation(), HighlightingKind::Keyword); + for (const auto ModuleLoc : D->getIdentifierLocs()) { + H.addToken(ModuleLoc, HighlightingKind::Namespace) + .addModifier(HighlightingModifier::DependentName); + } + return true; + } + bool VisitExportDecl(const ExportDecl *D) { + H.addToken(D->getLocation(), HighlightingKind::Keyword); + return true; + } + bool VisitTagDecl(TagDecl *D) { for (TemplateParameterList *TPL : D->getTemplateParameterLists()) H.addAngleBracketTokens(TPL->getLAngleLoc(), TPL->getRAngleLoc()); @@ -1120,6 +1133,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, HighlightingKind K) { return OS << "Function"; case HighlightingKind::Method: return OS << "Method"; + case HighlightingKind::Keyword: + return OS << "Keyword"; case HighlightingKind::StaticMethod: return OS << "StaticMethod"; case HighlightingKind::Field: @@ -1323,6 +1338,8 @@ llvm::StringRef toSemanticTokenType(HighlightingKind Kind) { return "function"; case HighlightingKind::Method: return "method"; + case HighlightingKind::Keyword: + return "keyword"; case HighlightingKind::StaticMethod: // FIXME: better method with static modifier? return "function"; diff --git a/clang-tools-extra/clangd/SemanticHighlighting.h b/clang-tools-extra/clangd/SemanticHighlighting.h index 59d742b83ee52..3b1c12418becb 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.h +++ b/clang-tools-extra/clangd/SemanticHighlighting.h @@ -34,6 +34,7 @@ enum class HighlightingKind { Parameter, Function, Method, + Keyword, StaticMethod, Field, StaticField, >From 5d2a238864c0d7b18290316497f93d1b976226d0 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons <[email protected]> Date: Sat, 20 Jun 2026 18:49:58 +0900 Subject: [PATCH 2/2] chore: add highlight for export in CXX Module since I cannot fix the build for cxx module, so I cannot test import, so I test export first --- .../clangd/unittests/SemanticHighlightingTests.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp index f8b7c242be9ff..569760294e455 100644 --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp @@ -1123,6 +1123,18 @@ sizeof...($TemplateParameter[[Elements]]); )cpp"}}, ~ScopeModifierMask); + checkHighlightings(R"cpp( + module; + export module highlight; + $Keyword[[export]] void $Function_def[[foo]]() { + } + )cpp", + {{"imp.h", R"cpp( + module; + export module ABC; + )cpp"}}, + ~ScopeModifierMask); + // A separate test for macros in headers. checkHighlightings(R"cpp( #include "imp.h" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
