[PATCH] D138908: [clangd] Highlight "miscellaneous" types as `type` as a fallback.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 29 04:04:30 PST 2022
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.
This allows them to carry modifiers like `deduced`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138908
Files:
clang-tools-extra/clangd/SemanticHighlighting.cpp
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
@@ -114,7 +114,7 @@
$Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_def[[VeryLongVariableName]] = 12312;
$Class[[AS]] $LocalVariable_def[[AA]];
$Primitive_deduced_defaultLibrary[[auto]] $LocalVariable_def[[L]] = $LocalVariable[[AA]].$Field[[SomeMember]] + $Parameter[[A]];
- auto $LocalVariable_def[[FN]] = [ $LocalVariable[[AA]]](int $Parameter_def[[A]]) -> void {};
+ $Type_deduced[[auto]] $LocalVariable_def[[FN]] = [ $LocalVariable[[AA]]](int $Parameter_def[[A]]) -> void {};
$LocalVariable[[FN]](12312);
}
)cpp",
@@ -122,7 +122,7 @@
void $Function_decl[[foo]](int);
void $Function_decl[[Gah]]();
void $Function_def[[foo]]() {
- auto $LocalVariable_def[[Bou]] = $Function[[Gah]];
+ $Type_deduced[[auto]] $LocalVariable_def[[Bou]] = $Function[[Gah]];
}
struct $Class_def[[A]] {
void $Method_decl[[abc]]();
@@ -331,7 +331,7 @@
$Enum_deduced[[auto]] &$Variable_def[[AER]] = $Variable[[AE]];
$Primitive_deduced_defaultLibrary[[auto]] $Variable_def[[Form]] = 10.2 + 2 * 4;
$Primitive_deduced_defaultLibrary[[decltype]]($Variable[[Form]]) $Variable_def[[F]] = 10;
- auto $Variable_def[[Fun]] = []()->void{};
+ $Type_deduced[[auto]] $Variable_def[[Fun]] = []()->void{};
)cpp",
R"cpp(
class $Class_def[[G]] {};
@@ -901,7 +901,7 @@
};
void $Function_def[[s]]($Class[[Foo]] $Parameter_def[[f]]) {
- auto $LocalVariable_def[[k]] = &$Class[[Foo]]::$Method[[foo]];
+ $Type_deduced[[auto]] $LocalVariable_def[[k]] = &$Class[[Foo]]::$Method[[foo]];
($Parameter[[f]].*$LocalVariable[[k]])(); // no crash on VisitCXXMemberCallExpr
}
)cpp"};
@@ -972,7 +972,7 @@
)cpp",
R"cpp(
// Lambdas are considered functions, not classes.
- auto $Variable_fileScope[[x]] = [$LocalVariable_functionScope[[m]](42)] {
+ $Type_fileScope[[auto]] $Variable_fileScope[[x]] = [$LocalVariable_functionScope[[m]](42)] {
return $LocalVariable_functionScope[[m]];
};
)cpp",
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -99,7 +99,8 @@
// We try to highlight typedefs as their underlying type.
if (auto K =
kindForType(TD->getUnderlyingType().getTypePtrOrNull(), Resolver))
- return K;
+ if (*K != HighlightingKind::Type)
+ return K;
// And fallback to a generic kind if this fails.
return HighlightingKind::Typedef;
}
@@ -171,12 +172,14 @@
if (TP->isBuiltinType()) // Builtins are special, they do not have decls.
return HighlightingKind::Primitive;
if (auto *TD = dyn_cast<TemplateTypeParmType>(TP))
- return kindForDecl(TD->getDecl(), Resolver);
+ if (auto Kind = kindForDecl(TD->getDecl(), Resolver))
+ return Kind;
if (isa<ObjCObjectPointerType>(TP))
return HighlightingKind::Class;
if (auto *TD = TP->getAsTagDecl())
- return kindForDecl(TD, Resolver);
- return llvm::None;
+ if (auto K = kindForDecl(TD, Resolver))
+ return K;
+ return HighlightingKind::Type;
}
// Whether T is const in a loose sense - is a variable with this type readonly?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138908.478512.patch
Type: text/x-patch
Size: 3692 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221129/004dcda5/attachment.bin>
More information about the cfe-commits
mailing list