#include "clang/AST/ExprCXX.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/SourceManager.h"
+#include "llvm/Support/raw_ostream.h"
namespace clang {
namespace clangd {
toHalfOpenFileRange(AST.getSourceManager(), AST.getLangOpts(), R);
if (!FileRange)
return;
+ // The hint may be in a file other than the main file (for example, a header
+ // file that was included after the preamble), do not show in that case.
+ if (!AST.getSourceManager().isWrittenInMainFile(FileRange->getBegin()))
+ return;
Results.push_back(InlayHint{
Range{
sourceLocToPosition(AST.getSourceManager(), FileRange->getBegin()),
#include "InlayHints.h"
#include "Protocol.h"
#include "TestTU.h"
+#include "TestWorkspace.h"
#include "XRefs.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
ExpectedHint{"timeout_millis: ", "timeout_millis"});
}
+TEST(ParameterHints, IncludeAtNonGlobalScope) {
+ Annotations FooInc(R"cpp(
+ void bar() { foo(42); }
+ )cpp");
+ Annotations FooCC(R"cpp(
+ struct S {
+ void foo(int param);
+ #include "foo.inc"
+ };
+ )cpp");
+
+ TestWorkspace Workspace;
+ Workspace.addSource("foo.inc", FooInc.code());
+ Workspace.addMainFile("foo.cc", FooCC.code());
+
+ auto AST = Workspace.openFile("foo.cc");
+ ASSERT_TRUE(bool(AST));
+
+ // Ensure the hint for the call in foo.inc is NOT materialized in foo.cc.
+ EXPECT_EQ(hintsOfKind(*AST, InlayHintKind::ParameterHint).size(), 0u);
+}
+
TEST(TypeHints, Smoke) {
assertTypeHints(R"cpp(
auto $waldo[[waldo]] = 42;