diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/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(TP)) - return kindForDecl(TD->getDecl(), Resolver); + if (auto Kind = kindForDecl(TD->getDecl(), Resolver)) + return Kind; if (isa(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? diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/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",