[PATCH] D137943: [clangd] Mark "override" and "final" as keywords
Christian Kandeler via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 14 06:18:56 PST 2022
ckandeler created this revision.
ckandeler added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
ckandeler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
... in semantic highlighting.
These specifiers are keywords for all intents and purposes, except that
they are not, for backward compatibility. As a result, they cannot be
identified by simple lexing (since e.g. variables with these names can
legally be declared), which means they should be semantic tokens.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137943
Files:
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/SemanticHighlighting.h
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -864,7 +864,13 @@
const char *$LocalVariable_def_readonly[[s]] = $LocalVariable_readonly_static[[__func__]];
}
)cpp",
+ // override and final
+ R"cpp(
+ class $Class_def_abstract[[Base]] { virtual void $Method_decl_abstract_virtual[[m]]() = 0; };
+ class $Class_def[[Derived]] : public $Class_abstract[[Base]] { void $Method_decl_virtual[[m]]() $Keyword[[override]]; };
+ class $Class_def[[MoreDerived]] : public $Class[[Derived]] { void $Method_decl_virtual[[m]]() $Keyword[[final]]; };
// Issue 1222: readonly modifier for generic parameter
+ )cpp",
R"cpp(
template <typename $TemplateParameter_def[[T]]>
auto $Function_def[[foo]](const $TemplateParameter[[T]] $Parameter_def_readonly[[template_type]],
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -49,6 +49,7 @@
Concept,
Primitive,
Macro,
+ Keyword,
// This one is different from the other kinds as it's a line style
// rather than a token style.
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -809,6 +809,18 @@
return true;
}
+ bool VisitAttr(Attr *A) {
+ switch (A->getKind()) {
+ case attr::Override:
+ case attr::Final:
+ H.addToken(A->getLocation(), HighlightingKind::Keyword);
+ break;
+ default:
+ break;
+ }
+ return true;
+ }
+
bool VisitDependentNameTypeLoc(DependentNameTypeLoc L) {
H.addToken(L.getNameLoc(), HighlightingKind::Type)
.addModifier(HighlightingModifier::DependentName)
@@ -985,6 +997,8 @@
return OS << "Primitive";
case HighlightingKind::Macro:
return OS << "Macro";
+ case HighlightingKind::Keyword:
+ return OS << "Keyword";
case HighlightingKind::InactiveCode:
return OS << "InactiveCode";
}
@@ -1119,6 +1133,8 @@
return "type";
case HighlightingKind::Macro:
return "macro";
+ case HighlightingKind::Keyword:
+ return "keyword";
case HighlightingKind::InactiveCode:
return "comment";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137943.475128.patch
Type: text/x-patch
Size: 2657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221114/0ad10010/attachment-0001.bin>
More information about the cfe-commits
mailing list