parent
25ae9a84c3
commit
22fa465a8c
|
@ -14,9 +14,9 @@
|
|||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_AST_H_
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_AST_H_
|
||||
|
||||
#include "index/Index.h"
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "clang/Basic/SourceLocation.h"
|
||||
#include "index/Index.h"
|
||||
|
||||
namespace clang {
|
||||
class SourceManager;
|
||||
|
|
|
@ -614,18 +614,18 @@ void ClangdLSPServer::onCodeAction(const CodeActionParams &Params,
|
|||
|
||||
void ClangdLSPServer::onCompletion(const TextDocumentPositionParams &Params,
|
||||
Callback<CompletionList> Reply) {
|
||||
Server->codeComplete(Params.textDocument.uri.file(), Params.position, CCOpts,
|
||||
Server->codeComplete(
|
||||
Params.textDocument.uri.file(), Params.position, CCOpts,
|
||||
Bind(
|
||||
[this](decltype(Reply) Reply,
|
||||
Expected<CodeCompleteResult> List) {
|
||||
[this](decltype(Reply) Reply, Expected<CodeCompleteResult> List) {
|
||||
if (!List)
|
||||
return Reply(List.takeError());
|
||||
CompletionList LSPList;
|
||||
LSPList.isIncomplete = List->HasMore;
|
||||
for (const auto &R : List->Completions) {
|
||||
CompletionItem C = R.render(CCOpts);
|
||||
C.kind = adjustKindToCapability(
|
||||
C.kind, SupportedCompletionItemKinds);
|
||||
C.kind =
|
||||
adjustKindToCapability(C.kind, SupportedCompletionItemKinds);
|
||||
LSPList.items.push_back(std::move(C));
|
||||
}
|
||||
return Reply(std::move(LSPList));
|
||||
|
|
|
@ -159,9 +159,7 @@ void ClangdServer::addDocument(PathRef File, StringRef Contents,
|
|||
WantDiags);
|
||||
}
|
||||
|
||||
void ClangdServer::removeDocument(PathRef File) {
|
||||
WorkScheduler.remove(File);
|
||||
}
|
||||
void ClangdServer::removeDocument(PathRef File) { WorkScheduler.remove(File); }
|
||||
|
||||
void ClangdServer::codeComplete(PathRef File, Position Pos,
|
||||
const clangd::CodeCompleteOptions &Opts,
|
||||
|
|
|
@ -879,9 +879,8 @@ public:
|
|||
IndexRequest.IDs.size(), FetchedDocs.size());
|
||||
}
|
||||
|
||||
llvm::sort(
|
||||
ScoredSignatures,
|
||||
[](const ScoredSignature &L, const ScoredSignature &R) {
|
||||
llvm::sort(ScoredSignatures, [](const ScoredSignature &L,
|
||||
const ScoredSignature &R) {
|
||||
// Ordering follows:
|
||||
// - Less number of parameters is better.
|
||||
// - Function is better than FunctionType which is better than
|
||||
|
|
|
@ -69,7 +69,8 @@ std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) {
|
|||
// Sanity check that the comment does not come from the PCH. We choose to not
|
||||
// write them into PCH, because they are racy and slow to load.
|
||||
assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
|
||||
std::string Doc = RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
|
||||
std::string Doc =
|
||||
RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
|
||||
return looksLikeDocComment(Doc) ? Doc : "";
|
||||
}
|
||||
|
||||
|
|
|
@ -240,8 +240,8 @@ CodeAction toCodeAction(const Fix &F, const URIForFile &File) {
|
|||
return Action;
|
||||
}
|
||||
|
||||
void toLSPDiags(
|
||||
const Diag &D, const URIForFile &File, const ClangdDiagnosticOptions &Opts,
|
||||
void toLSPDiags(const Diag &D, const URIForFile &File,
|
||||
const ClangdDiagnosticOptions &Opts,
|
||||
function_ref<void(clangd::Diagnostic, ArrayRef<Fix>)> OutFn) {
|
||||
auto FillBasicFields = [](const DiagBase &D) -> clangd::Diagnostic {
|
||||
clangd::Diagnostic Res;
|
||||
|
|
|
@ -41,8 +41,7 @@ public:
|
|||
StringRef FileName = llvm::sys::path::filename(Path);
|
||||
if (FileName.startswith("preamble-") && FileName.endswith(".pch"))
|
||||
return File;
|
||||
return std::unique_ptr<VolatileFile>(
|
||||
new VolatileFile(std::move(*File)));
|
||||
return std::unique_ptr<VolatileFile>(new VolatileFile(std::move(*File)));
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -718,7 +718,8 @@ json::Value toJSON(const DocumentHighlight &DH) {
|
|||
|
||||
llvm::json::Value toJSON(const FileStatus &FStatus) {
|
||||
return json::Object{
|
||||
{"uri", FStatus.uri}, {"state", FStatus.state},
|
||||
{"uri", FStatus.uri},
|
||||
{"state", FStatus.state},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
// preamble. However, unlike AST, the same preamble can be read concurrently, so
|
||||
// we run each of async preamble reads on its own thread.
|
||||
//
|
||||
// To limit the concurrent load that clangd produces we maintain a semaphore that
|
||||
// keeps more than a fixed number of threads from running concurrently.
|
||||
// To limit the concurrent load that clangd produces we maintain a semaphore
|
||||
// that keeps more than a fixed number of threads from running concurrently.
|
||||
//
|
||||
// Rationale for cancelling updates.
|
||||
// LSP clients can send updates to clangd on each keystroke. Some files take
|
||||
|
@ -334,8 +334,9 @@ ASTWorker::ASTWorker(PathRef FileName, TUScheduler::ASTCache &LRUCache,
|
|||
bool StorePreamblesInMemory, ParsingCallbacks &Callbacks)
|
||||
: IdleASTs(LRUCache), RunSync(RunSync), UpdateDebounce(UpdateDebounce),
|
||||
FileName(FileName), StorePreambleInMemory(StorePreamblesInMemory),
|
||||
Callbacks(Callbacks), PCHs(std::move(PCHs)),
|
||||
Status{TUAction(TUAction::Idle, ""), TUStatus::BuildDetails()},
|
||||
Callbacks(Callbacks),
|
||||
PCHs(std::move(PCHs)), Status{TUAction(TUAction::Idle, ""),
|
||||
TUStatus::BuildDetails()},
|
||||
Barrier(Barrier), Done(false) {}
|
||||
|
||||
ASTWorker::~ASTWorker() {
|
||||
|
@ -537,9 +538,7 @@ void ASTWorker::getCurrentPreamble(
|
|||
RequestsCV.notify_all();
|
||||
}
|
||||
|
||||
void ASTWorker::waitForFirstPreamble() const {
|
||||
PreambleWasBuilt.wait();
|
||||
}
|
||||
void ASTWorker::waitForFirstPreamble() const { PreambleWasBuilt.wait(); }
|
||||
|
||||
std::size_t ASTWorker::getUsedBytes() const {
|
||||
// Note that we don't report the size of ASTs currently used for processing
|
||||
|
|
|
@ -226,7 +226,8 @@ private:
|
|||
/// propagated.
|
||||
template <typename T>
|
||||
std::future<T> runAsync(llvm::unique_function<T()> Action) {
|
||||
return std::async(std::launch::async,
|
||||
return std::async(
|
||||
std::launch::async,
|
||||
[](llvm::unique_function<T()> &&Action, Context Ctx) {
|
||||
WithContext WithCtx(std::move(Ctx));
|
||||
return Action();
|
||||
|
|
|
@ -124,9 +124,7 @@ private:
|
|||
}
|
||||
|
||||
// May be called by any thread.
|
||||
void markEnded() {
|
||||
EndTime = Tracer->timestamp();
|
||||
}
|
||||
void markEnded() { EndTime = Tracer->timestamp(); }
|
||||
|
||||
private:
|
||||
static int64_t nextID() {
|
||||
|
|
|
@ -46,8 +46,7 @@ void logIfOverflow(const SymbolLocation &Loc) {
|
|||
// TUPath is used to resolve the path of URI.
|
||||
// FIXME: figure out a good home for it, and share the implementation with
|
||||
// FindSymbols.
|
||||
Optional<Location> toLSPLocation(const SymbolLocation &Loc,
|
||||
StringRef TUPath) {
|
||||
Optional<Location> toLSPLocation(const SymbolLocation &Loc, StringRef TUPath) {
|
||||
if (!Loc)
|
||||
return None;
|
||||
auto Uri = URI::parse(Loc.FileURI);
|
||||
|
@ -336,8 +335,7 @@ std::vector<Location> findDefinitions(ParsedAST &AST, Position Pos,
|
|||
for (auto It : CandidatesIndex)
|
||||
QueryRequest.IDs.insert(It.first);
|
||||
std::string TUPath;
|
||||
const FileEntry *FE =
|
||||
SM.getFileEntryForID(SM.getMainFileID());
|
||||
const FileEntry *FE = SM.getFileEntryForID(SM.getMainFileID());
|
||||
if (auto Path = getCanonicalPath(FE, SM))
|
||||
TUPath = *Path;
|
||||
// Query the index and populate the empty slot.
|
||||
|
|
|
@ -477,8 +477,8 @@ int hello;
|
|||
|
||||
Locations = runFindDefinitions(Server, FooCpp, FooSource.point());
|
||||
EXPECT_TRUE(bool(Locations));
|
||||
EXPECT_THAT(*Locations, ElementsAre(FileRange(FooCpp,
|
||||
FooSource.range("two"))));
|
||||
EXPECT_THAT(*Locations,
|
||||
ElementsAre(FileRange(FooCpp, FooSource.range("two"))));
|
||||
}
|
||||
|
||||
TEST_F(ClangdVFSTest, MemoryUsage) {
|
||||
|
|
|
@ -255,8 +255,7 @@ main.cpp:2:3: error: something terrible happened)");
|
|||
|
||||
// Transform dianostics and check the results.
|
||||
std::vector<std::pair<clangd::Diagnostic, std::vector<clangd::Fix>>> LSPDiags;
|
||||
toLSPDiags(
|
||||
D,
|
||||
toLSPDiags(D,
|
||||
#ifdef _WIN32
|
||||
URIForFile::canonicalize("c:\\path\\to\\foo\\bar\\main.cpp",
|
||||
/*TUPath=*/""),
|
||||
|
|
|
@ -516,7 +516,8 @@ TEST(CompletionTest, ScopedWithFilter) {
|
|||
|
||||
TEST(CompletionTest, ReferencesAffectRanking) {
|
||||
auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")});
|
||||
EXPECT_THAT(Results.Completions, HasSubsequence(Named("absb"), Named("absl")));
|
||||
EXPECT_THAT(Results.Completions,
|
||||
HasSubsequence(Named("absb"), Named("absl")));
|
||||
Results = completions("int main() { abs^ }",
|
||||
{withReferences(10000, ns("absl")), func("absb")});
|
||||
EXPECT_THAT(Results.Completions,
|
||||
|
@ -1662,7 +1663,8 @@ TEST(CompletionTest, CompletionTokenRange) {
|
|||
auto Results = completions(Server, TestCode.code(), TestCode.point());
|
||||
|
||||
EXPECT_EQ(Results.Completions.size(), 1u);
|
||||
EXPECT_THAT(Results.Completions.front().CompletionTokenRange, TestCode.range());
|
||||
EXPECT_THAT(Results.Completions.front().CompletionTokenRange,
|
||||
TestCode.range());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2095,11 +2097,10 @@ TEST(SignatureHelpTest, ConstructorInitializeFields) {
|
|||
A a_elem;
|
||||
};
|
||||
)cpp");
|
||||
EXPECT_THAT(Results.signatures, UnorderedElementsAre(
|
||||
Sig("A(int)", {"int"}),
|
||||
EXPECT_THAT(Results.signatures,
|
||||
UnorderedElementsAre(Sig("A(int)", {"int"}),
|
||||
Sig("A(A &&)", {"A &&"}),
|
||||
Sig("A(const A &)", {"const A &"})
|
||||
));
|
||||
Sig("A(const A &)", {"const A &"})));
|
||||
}
|
||||
{
|
||||
const auto Results = signatures(R"cpp(
|
||||
|
@ -2115,11 +2116,10 @@ TEST(SignatureHelpTest, ConstructorInitializeFields) {
|
|||
C c_elem;
|
||||
};
|
||||
)cpp");
|
||||
EXPECT_THAT(Results.signatures, UnorderedElementsAre(
|
||||
Sig("A(int)", {"int"}),
|
||||
EXPECT_THAT(Results.signatures,
|
||||
UnorderedElementsAre(Sig("A(int)", {"int"}),
|
||||
Sig("A(A &&)", {"A &&"}),
|
||||
Sig("A(const A &)", {"const A &"})
|
||||
));
|
||||
Sig("A(const A &)", {"const A &"})));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2136,8 +2136,7 @@ TEST(CompletionTest, IncludedCompletionKinds) {
|
|||
auto Results = completions(Server,
|
||||
R"cpp(
|
||||
#include "^"
|
||||
)cpp"
|
||||
);
|
||||
)cpp");
|
||||
EXPECT_THAT(Results.Completions,
|
||||
AllOf(Has("sub/", CompletionItemKind::Folder),
|
||||
Has("bar.h\"", CompletionItemKind::File)));
|
||||
|
@ -2147,8 +2146,7 @@ TEST(CompletionTest, NoCrashAtNonAlphaIncludeHeader) {
|
|||
auto Results = completions(
|
||||
R"cpp(
|
||||
#include "./^"
|
||||
)cpp"
|
||||
);
|
||||
)cpp");
|
||||
EXPECT_TRUE(Results.Completions.empty());
|
||||
}
|
||||
|
||||
|
@ -2222,8 +2220,7 @@ TEST(CompletionTest, ObjectiveCMethodNoArguments) {
|
|||
Foo *foo = [Foo new]; int y = [foo v^]
|
||||
)objc",
|
||||
/*IndexSymbols=*/{},
|
||||
/*Opts=*/{},
|
||||
"Foo.m");
|
||||
/*Opts=*/{}, "Foo.m");
|
||||
|
||||
auto C = Results.Completions;
|
||||
EXPECT_THAT(C, ElementsAre(Named("value")));
|
||||
|
@ -2241,8 +2238,7 @@ TEST(CompletionTest, ObjectiveCMethodOneArgument) {
|
|||
Foo *foo = [Foo new]; int y = [foo v^]
|
||||
)objc",
|
||||
/*IndexSymbols=*/{},
|
||||
/*Opts=*/{},
|
||||
"Foo.m");
|
||||
/*Opts=*/{}, "Foo.m");
|
||||
|
||||
auto C = Results.Completions;
|
||||
EXPECT_THAT(C, ElementsAre(Named("valueForCharacter:")));
|
||||
|
@ -2260,16 +2256,15 @@ TEST(CompletionTest, ObjectiveCMethodTwoArgumentsFromBeginning) {
|
|||
id val = [Foo foo^]
|
||||
)objc",
|
||||
/*IndexSymbols=*/{},
|
||||
/*Opts=*/{},
|
||||
"Foo.m");
|
||||
/*Opts=*/{}, "Foo.m");
|
||||
|
||||
auto C = Results.Completions;
|
||||
EXPECT_THAT(C, ElementsAre(Named("fooWithValue:")));
|
||||
EXPECT_THAT(C, ElementsAre(Kind(CompletionItemKind::Method)));
|
||||
EXPECT_THAT(C, ElementsAre(ReturnType("id")));
|
||||
EXPECT_THAT(C, ElementsAre(Signature("(int) fooey:(unsigned int)")));
|
||||
EXPECT_THAT(C,
|
||||
ElementsAre(SnippetSuffix("${1:(int)} fooey:${2:(unsigned int)}")));
|
||||
EXPECT_THAT(
|
||||
C, ElementsAre(SnippetSuffix("${1:(int)} fooey:${2:(unsigned int)}")));
|
||||
}
|
||||
|
||||
TEST(CompletionTest, ObjectiveCMethodTwoArgumentsFromMiddle) {
|
||||
|
@ -2280,8 +2275,7 @@ TEST(CompletionTest, ObjectiveCMethodTwoArgumentsFromMiddle) {
|
|||
id val = [Foo fooWithValue:10 f^]
|
||||
)objc",
|
||||
/*IndexSymbols=*/{},
|
||||
/*Opts=*/{},
|
||||
"Foo.m");
|
||||
/*Opts=*/{}, "Foo.m");
|
||||
|
||||
auto C = Results.Completions;
|
||||
EXPECT_THAT(C, ElementsAre(Named("fooey:")));
|
||||
|
|
|
@ -355,10 +355,9 @@ TEST(FileIndexTest, ReferencesInMainFileWithPreamble) {
|
|||
// Prepare preamble.
|
||||
auto CI = buildCompilerInvocation(PI);
|
||||
auto PreambleData = buildPreamble(
|
||||
MainFile,
|
||||
*buildCompilerInvocation(PI), /*OldPreamble=*/nullptr,
|
||||
tooling::CompileCommand(), PI,
|
||||
std::make_shared<PCHContainerOperations>(), /*StoreInMemory=*/true,
|
||||
MainFile, *buildCompilerInvocation(PI), /*OldPreamble=*/nullptr,
|
||||
tooling::CompileCommand(), PI, std::make_shared<PCHContainerOperations>(),
|
||||
/*StoreInMemory=*/true,
|
||||
[&](ASTContext &Ctx, std::shared_ptr<Preprocessor> PP) {});
|
||||
// Build AST for main file with preamble.
|
||||
auto AST =
|
||||
|
@ -369,8 +368,7 @@ TEST(FileIndexTest, ReferencesInMainFileWithPreamble) {
|
|||
FileIndex Index;
|
||||
Index.updateMain(MainFile, *AST);
|
||||
|
||||
auto Foo =
|
||||
findSymbol(TestTU::withHeaderCode(Header).headerSymbols(), "Foo");
|
||||
auto Foo = findSymbol(TestTU::withHeaderCode(Header).headerSymbols(), "Foo");
|
||||
RefsRequest Request;
|
||||
Request.IDs.insert(Foo.ID);
|
||||
|
||||
|
|
|
@ -19,8 +19,7 @@ namespace {
|
|||
|
||||
// No fmemopen on windows or on versions of MacOS X earlier than 10.13, so we
|
||||
// can't easily run this test.
|
||||
#if !(defined(WIN32) || \
|
||||
(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
|
||||
#if !(defined(WIN32) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
|
||||
__MAC_OS_X_VERSION_MIN_REQUIRED < 101300))
|
||||
|
||||
// Fixture takes care of managing the input/output buffers for the transport.
|
||||
|
|
|
@ -99,9 +99,9 @@ TEST(SerializationTest, YAMLConversions) {
|
|||
auto ParsedYAML = readIndexFile(YAML);
|
||||
ASSERT_TRUE(bool(ParsedYAML)) << ParsedYAML.takeError();
|
||||
ASSERT_TRUE(bool(ParsedYAML->Symbols));
|
||||
EXPECT_THAT(*ParsedYAML->Symbols,
|
||||
UnorderedElementsAre(ID("057557CEBF6E6B2D"),
|
||||
ID("057557CEBF6E6B2E")));
|
||||
EXPECT_THAT(
|
||||
*ParsedYAML->Symbols,
|
||||
UnorderedElementsAre(ID("057557CEBF6E6B2D"), ID("057557CEBF6E6B2E")));
|
||||
|
||||
auto Sym1 = *ParsedYAML->Symbols->find(
|
||||
cantFail(SymbolID::fromStr("057557CEBF6E6B2D")));
|
||||
|
@ -131,8 +131,7 @@ TEST(SerializationTest, YAMLConversions) {
|
|||
ASSERT_TRUE(bool(ParsedYAML->Refs));
|
||||
EXPECT_THAT(
|
||||
*ParsedYAML->Refs,
|
||||
UnorderedElementsAre(
|
||||
Pair(cantFail(SymbolID::fromStr("057557CEBF6E6B2D")),
|
||||
UnorderedElementsAre(Pair(cantFail(SymbolID::fromStr("057557CEBF6E6B2D")),
|
||||
testing::SizeIs(1))));
|
||||
auto Ref1 = ParsedYAML->Refs->begin()->second.front();
|
||||
EXPECT_EQ(Ref1.Kind, RefKind::Reference);
|
||||
|
|
|
@ -248,8 +248,7 @@ public:
|
|||
Args.push_back(TestFileName);
|
||||
|
||||
tooling::ToolInvocation Invocation(
|
||||
Args,
|
||||
Factory->create(), Files.get(),
|
||||
Args, Factory->create(), Files.get(),
|
||||
std::make_shared<PCHContainerOperations>());
|
||||
|
||||
InMemoryFileSystem->addFile(TestHeaderName, 0,
|
||||
|
@ -422,8 +421,7 @@ o]]();
|
|||
int Y;
|
||||
)cpp");
|
||||
runSymbolCollector(Header.code(), Main.code());
|
||||
EXPECT_THAT(
|
||||
Symbols,
|
||||
EXPECT_THAT(Symbols,
|
||||
UnorderedElementsAre(
|
||||
AllOf(QName("X"), DeclRange(Header.range("xdecl")),
|
||||
DefRange(Main.range("xdef"))),
|
||||
|
@ -432,8 +430,7 @@ o]]();
|
|||
AllOf(QName("print"), DeclRange(Header.range("printdecl")),
|
||||
DefRange(Main.range("printdef"))),
|
||||
AllOf(QName("Z"), DeclRange(Header.range("zdecl"))),
|
||||
AllOf(QName("foo"), DeclRange(Header.range("foodecl")))
|
||||
));
|
||||
AllOf(QName("foo"), DeclRange(Header.range("foodecl")))));
|
||||
}
|
||||
|
||||
TEST_F(SymbolCollectorTest, Refs) {
|
||||
|
@ -537,8 +534,8 @@ TEST_F(SymbolCollectorTest, SymbolRelativeWithFallback) {
|
|||
TestHeaderURI = URI::create(testPath(TestHeaderName)).toString();
|
||||
CollectorOpts.FallbackDir = testRoot();
|
||||
runSymbolCollector("class Foo {};", /*Main=*/"");
|
||||
EXPECT_THAT(Symbols,
|
||||
UnorderedElementsAre(AllOf(QName("Foo"), DeclURI(TestHeaderURI))));
|
||||
EXPECT_THAT(Symbols, UnorderedElementsAre(
|
||||
AllOf(QName("Foo"), DeclURI(TestHeaderURI))));
|
||||
}
|
||||
|
||||
TEST_F(SymbolCollectorTest, UnittestURIScheme) {
|
||||
|
@ -605,8 +602,7 @@ TEST_F(SymbolCollectorTest, SymbolFormedFromRegisteredSchemeFromMacro) {
|
|||
)");
|
||||
|
||||
runSymbolCollector(Header.code(), /*Main=*/"");
|
||||
EXPECT_THAT(
|
||||
Symbols,
|
||||
EXPECT_THAT(Symbols,
|
||||
UnorderedElementsAre(
|
||||
AllOf(QName("abc_Test"), DeclRange(Header.range("expansion")),
|
||||
DeclURI(TestHeaderURI)),
|
||||
|
|
|
@ -44,8 +44,7 @@ TEST(SymbolInfoTests, All) {
|
|||
fo^o();
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@F@foo#")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@F@foo#")}},
|
||||
{
|
||||
R"cpp( // Simple function reference - definition
|
||||
void foo() {}
|
||||
|
@ -53,8 +52,7 @@ TEST(SymbolInfoTests, All) {
|
|||
fo^o();
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@F@foo#")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@F@foo#")}},
|
||||
{
|
||||
R"cpp( // Function in namespace reference
|
||||
namespace bar {
|
||||
|
@ -64,8 +62,7 @@ TEST(SymbolInfoTests, All) {
|
|||
}
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "bar::", "c:@N@bar@F@foo#")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "bar::", "c:@N@bar@F@foo#")}},
|
||||
{
|
||||
R"cpp( // Function in different namespace reference
|
||||
namespace bar {
|
||||
|
@ -77,8 +74,7 @@ TEST(SymbolInfoTests, All) {
|
|||
}
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "bar::", "c:@N@bar@F@foo#")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "bar::", "c:@N@bar@F@foo#")}},
|
||||
{
|
||||
R"cpp( // Function in global namespace reference
|
||||
void foo();
|
||||
|
@ -90,8 +86,7 @@ TEST(SymbolInfoTests, All) {
|
|||
}
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@F@foo#")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@F@foo#")}},
|
||||
{
|
||||
R"cpp( // Function in anonymous namespace reference
|
||||
namespace {
|
||||
|
@ -103,8 +98,8 @@ TEST(SymbolInfoTests, All) {
|
|||
}
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "(anonymous)", "c:TestTU.cpp@aN@F@foo#")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "(anonymous)",
|
||||
"c:TestTU.cpp@aN@F@foo#")}},
|
||||
{
|
||||
R"cpp( // Function reference - ADL
|
||||
namespace bar {
|
||||
|
@ -118,8 +113,8 @@ TEST(SymbolInfoTests, All) {
|
|||
}
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "bar::", "c:@N@bar@F@foo#&1$@N@bar@S@BarType#")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails(
|
||||
"foo", "bar::", "c:@N@bar@F@foo#&1$@N@bar@S@BarType#")}},
|
||||
{
|
||||
R"cpp( // Global value reference
|
||||
int value;
|
||||
|
@ -128,22 +123,21 @@ TEST(SymbolInfoTests, All) {
|
|||
foo(val^ue);
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("value", "", "c:@value")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("value", "", "c:@value")}},
|
||||
{
|
||||
R"cpp( // Local value reference
|
||||
void foo() { int aaa; int bbb = aa^a; }
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("aaa", "foo", "c:TestTU.cpp@49@F@foo#@aaa")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("aaa", "foo",
|
||||
"c:TestTU.cpp@49@F@foo#@aaa")}},
|
||||
{
|
||||
R"cpp( // Function param
|
||||
void bar(int aaa) {
|
||||
int bbb = a^aa;
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("aaa", "bar", "c:TestTU.cpp@38@F@bar#I#@aaa")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("aaa", "bar",
|
||||
"c:TestTU.cpp@38@F@bar#I#@aaa")}},
|
||||
{
|
||||
R"cpp( // Lambda capture
|
||||
int ii;
|
||||
|
@ -151,14 +145,13 @@ TEST(SymbolInfoTests, All) {
|
|||
return i^i;
|
||||
};
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("ii", "", "c:@ii")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("ii", "", "c:@ii")}},
|
||||
{
|
||||
R"cpp( // Macro reference
|
||||
#define MACRO 5\nint i = MAC^RO;
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("MACRO", "", "c:TestTU.cpp@55@macro@MACRO")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("MACRO", "",
|
||||
"c:TestTU.cpp@55@macro@MACRO")}},
|
||||
{
|
||||
R"cpp( // Multiple symbols returned - using overloaded function name
|
||||
void foo() {}
|
||||
|
@ -168,12 +161,9 @@ TEST(SymbolInfoTests, All) {
|
|||
using ::fo^o;
|
||||
}
|
||||
)cpp",
|
||||
{
|
||||
CreateExpectedSymbolDetails("foo", "", "c:@F@foo#"),
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@F@foo#"),
|
||||
CreateExpectedSymbolDetails("foo", "", "c:@F@foo#b#"),
|
||||
CreateExpectedSymbolDetails("foo", "", "c:@F@foo#I#")
|
||||
}
|
||||
},
|
||||
CreateExpectedSymbolDetails("foo", "", "c:@F@foo#I#")}},
|
||||
{
|
||||
R"cpp( // Multiple symbols returned - implicit conversion
|
||||
struct foo {};
|
||||
|
@ -187,24 +177,23 @@ TEST(SymbolInfoTests, All) {
|
|||
}
|
||||
)cpp",
|
||||
{
|
||||
CreateExpectedSymbolDetails("ff", "func_baz2", "c:TestTU.cpp@218@F@func_baz2#@ff"),
|
||||
CreateExpectedSymbolDetails("bar", "bar::", "c:@S@bar@F@bar#&1$@S@foo#"),
|
||||
}
|
||||
},
|
||||
CreateExpectedSymbolDetails(
|
||||
"ff", "func_baz2", "c:TestTU.cpp@218@F@func_baz2#@ff"),
|
||||
CreateExpectedSymbolDetails(
|
||||
"bar", "bar::", "c:@S@bar@F@bar#&1$@S@foo#"),
|
||||
}},
|
||||
{
|
||||
R"cpp( // Type reference - declaration
|
||||
struct foo;
|
||||
void bar(fo^o*);
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@S@foo")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@S@foo")}},
|
||||
{
|
||||
R"cpp( // Type reference - definition
|
||||
struct foo {};
|
||||
void bar(fo^o*);
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@S@foo")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@S@foo")}},
|
||||
{
|
||||
R"cpp( // Type Reference - template argumen
|
||||
struct foo {};
|
||||
|
@ -213,24 +202,21 @@ TEST(SymbolInfoTests, All) {
|
|||
bar<fo^o> b;
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@S@foo")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@S@foo")}},
|
||||
{
|
||||
R"cpp( // Template parameter reference - type param
|
||||
template<class TT> struct bar {
|
||||
T^T t;
|
||||
};
|
||||
)cpp",
|
||||
{ /* not implemented */ }
|
||||
},
|
||||
{/* not implemented */}},
|
||||
{
|
||||
R"cpp( // Template parameter reference - type param
|
||||
template<int NN> struct bar {
|
||||
int a = N^N;
|
||||
};
|
||||
)cpp",
|
||||
{ /* not implemented */ }
|
||||
},
|
||||
{/* not implemented */}},
|
||||
{
|
||||
R"cpp( // Class member reference - objec
|
||||
struct foo {
|
||||
|
@ -241,8 +227,7 @@ TEST(SymbolInfoTests, All) {
|
|||
f.a^a;
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("aa", "foo::", "c:@S@foo@FI@aa")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("aa", "foo::", "c:@S@foo@FI@aa")}},
|
||||
{
|
||||
R"cpp( // Class member reference - pointer
|
||||
struct foo {
|
||||
|
@ -252,8 +237,7 @@ TEST(SymbolInfoTests, All) {
|
|||
&foo::a^a;
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("aa", "foo::", "c:@S@foo@FI@aa")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("aa", "foo::", "c:@S@foo@FI@aa")}},
|
||||
{
|
||||
R"cpp( // Class method reference - objec
|
||||
struct foo {
|
||||
|
@ -264,8 +248,7 @@ TEST(SymbolInfoTests, All) {
|
|||
f.a^a();
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("aa", "foo::", "c:@S@foo@F@aa#")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("aa", "foo::", "c:@S@foo@F@aa#")}},
|
||||
{
|
||||
R"cpp( // Class method reference - pointer
|
||||
struct foo {
|
||||
|
@ -275,8 +258,7 @@ TEST(SymbolInfoTests, All) {
|
|||
&foo::a^a;
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("aa", "foo::", "c:@S@foo@F@aa#")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("aa", "foo::", "c:@S@foo@F@aa#")}},
|
||||
{
|
||||
R"cpp( // Typedef
|
||||
typedef int foo;
|
||||
|
@ -284,8 +266,7 @@ TEST(SymbolInfoTests, All) {
|
|||
fo^o a;
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:TestTU.cpp@T@foo")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:TestTU.cpp@T@foo")}},
|
||||
{
|
||||
R"cpp( // Type alias
|
||||
using foo = int;
|
||||
|
@ -293,15 +274,13 @@ TEST(SymbolInfoTests, All) {
|
|||
fo^o a;
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@foo")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@foo")}},
|
||||
{
|
||||
R"cpp( // Namespace reference
|
||||
namespace foo {}
|
||||
using namespace fo^o;
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@N@foo")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("foo", "", "c:@N@foo")}},
|
||||
{
|
||||
R"cpp( // Enum value reference
|
||||
enum foo { bar, baz };
|
||||
|
@ -309,8 +288,7 @@ TEST(SymbolInfoTests, All) {
|
|||
foo fff = ba^r;
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("bar", "foo", "c:@E@foo@bar")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("bar", "foo", "c:@E@foo@bar")}},
|
||||
{
|
||||
R"cpp( // Enum class value reference
|
||||
enum class foo { bar, baz };
|
||||
|
@ -318,8 +296,7 @@ TEST(SymbolInfoTests, All) {
|
|||
foo fff = foo::ba^r;
|
||||
}
|
||||
)cpp",
|
||||
{CreateExpectedSymbolDetails("bar", "foo::", "c:@E@foo@bar")}
|
||||
},
|
||||
{CreateExpectedSymbolDetails("bar", "foo::", "c:@E@foo@bar")}},
|
||||
{
|
||||
R"cpp( // Type inferrence with auto keyword
|
||||
struct foo {};
|
||||
|
@ -328,8 +305,7 @@ TEST(SymbolInfoTests, All) {
|
|||
au^to a = getfoo();
|
||||
}
|
||||
)cpp",
|
||||
{/* not implemented */}
|
||||
},
|
||||
{/* not implemented */}},
|
||||
{
|
||||
R"cpp( // decltype
|
||||
struct foo {};
|
||||
|
@ -338,8 +314,7 @@ TEST(SymbolInfoTests, All) {
|
|||
declt^ype(f);
|
||||
}
|
||||
)cpp",
|
||||
{/* not implemented */}
|
||||
},
|
||||
{/* not implemented */}},
|
||||
};
|
||||
|
||||
for (const auto &T : TestInputExpectedOutput) {
|
||||
|
|
|
@ -148,6 +148,5 @@ RefSlab getRefs(const SymbolIndex &Index, SymbolID ID) {
|
|||
return std::move(Slab).build();
|
||||
}
|
||||
|
||||
|
||||
} // namespace clangd
|
||||
} // namespace clang
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
#include "Matchers.h"
|
||||
#include "TUScheduler.h"
|
||||
#include "TestFS.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "llvm/ADT/ScopeExit.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
@ -389,11 +389,11 @@ TEST_F(TUSchedulerTests, ManyUpdates) {
|
|||
}
|
||||
{
|
||||
WithContextValue WithNonce(NonceKey, ++Nonce);
|
||||
S.runWithAST("CheckAST", File,
|
||||
S.runWithAST(
|
||||
"CheckAST", File,
|
||||
[File, Inputs, Nonce, &Mut,
|
||||
&TotalASTReads](Expected<InputsAndAST> AST) {
|
||||
EXPECT_THAT(Context::current().get(NonceKey),
|
||||
Pointee(Nonce));
|
||||
EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce));
|
||||
|
||||
ASSERT_TRUE((bool)AST);
|
||||
EXPECT_EQ(AST->Inputs.FS, Inputs.FS);
|
||||
|
@ -401,9 +401,7 @@ TEST_F(TUSchedulerTests, ManyUpdates) {
|
|||
|
||||
std::lock_guard<std::mutex> Lock(Mut);
|
||||
++TotalASTReads;
|
||||
EXPECT_EQ(
|
||||
File,
|
||||
*TUScheduler::getFileBeingProcessedInContext());
|
||||
EXPECT_EQ(File, *TUScheduler::getFileBeingProcessedInContext());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -505,12 +503,12 @@ TEST_F(TUSchedulerTests, EmptyPreamble) {
|
|||
)cpp";
|
||||
auto WithEmptyPreamble = R"cpp(int main() {})cpp";
|
||||
S.update(Foo, getInputs(Foo, WithPreamble), WantDiagnostics::Auto);
|
||||
S.runWithPreamble("getNonEmptyPreamble", Foo, TUScheduler::Stale,
|
||||
S.runWithPreamble(
|
||||
"getNonEmptyPreamble", Foo, TUScheduler::Stale,
|
||||
[&](Expected<InputsAndPreamble> Preamble) {
|
||||
// We expect to get a non-empty preamble.
|
||||
EXPECT_GT(cantFail(std::move(Preamble))
|
||||
.Preamble->Preamble.getBounds()
|
||||
.Size,
|
||||
EXPECT_GT(
|
||||
cantFail(std::move(Preamble)).Preamble->Preamble.getBounds().Size,
|
||||
0u);
|
||||
});
|
||||
// Wait for the preamble is being built.
|
||||
|
@ -520,12 +518,12 @@ TEST_F(TUSchedulerTests, EmptyPreamble) {
|
|||
S.update(Foo, getInputs(Foo, WithEmptyPreamble), WantDiagnostics::Auto);
|
||||
// Wait for the preamble is being built.
|
||||
ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
|
||||
S.runWithPreamble("getEmptyPreamble", Foo, TUScheduler::Stale,
|
||||
S.runWithPreamble(
|
||||
"getEmptyPreamble", Foo, TUScheduler::Stale,
|
||||
[&](Expected<InputsAndPreamble> Preamble) {
|
||||
// We expect to get an empty preamble.
|
||||
EXPECT_EQ(cantFail(std::move(Preamble))
|
||||
.Preamble->Preamble.getBounds()
|
||||
.Size,
|
||||
EXPECT_EQ(
|
||||
cantFail(std::move(Preamble)).Preamble->Preamble.getBounds().Size,
|
||||
0u);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -156,7 +156,8 @@ TEST(GoToDefinition, WithIndex) {
|
|||
)cpp");
|
||||
EXPECT_THAT(runFindDefinitionsWithIndex(Test),
|
||||
testing::ElementsAreArray({
|
||||
RangeIs(Test.range()), RangeIs(SymbolHeader.range("forward")),
|
||||
RangeIs(Test.range()),
|
||||
RangeIs(SymbolHeader.range("forward")),
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue