18#include "clang/Basic/LangOptions.h"
19#include "clang/Basic/SourceManager.h"
20#include "llvm/Testing/Support/Error.h"
21#include "gmock/gmock.h"
22#include "gtest/gtest.h"
25using namespace testing;
37 EXPECT_THAT(CXX, HasSubstr(
"#include <string>"));
38 EXPECT_THAT(CXX, HasSubstr(
"#include <cstdio>"));
39 EXPECT_THAT(CXX, Not(HasSubstr(
"#include <ios646.h>")));
43 EXPECT_THAT(C, Not(HasSubstr(
"#include <string>")));
44 EXPECT_THAT(C, Not(HasSubstr(
"#include <cstdio>")));
45 EXPECT_THAT(C, HasSubstr(
"#include <stdio.h>"));
48MATCHER_P(Named, Name,
"") {
return arg.Name == Name; }
53 FS.
Files[
"std/foo.h"] = R
"cpp(
54 #include <platform_stuff.h>
55 #if __cplusplus >= 201703L
57 #elif __cplusplus >= 201402L
63 FS.Files["nonstd/platform_stuff.h"] =
"int magic = 42;";
66 OriginalInputs.
TFS = &FS;
67 OriginalInputs.CompileCommand.Filename =
testPath(
"main.cc");
68 OriginalInputs.CompileCommand.CommandLine = {
"clang++",
testPath(
"main.cc"),
70 "-isystemnonstd/",
"-std=c++14"};
71 OriginalInputs.CompileCommand.Directory =
testRoot();
81 EXPECT_THAT(
Symbols, ElementsAre(Named(
"foo14")));
87 FS.
Files[
"std/_"] =
"";
88 FS.Files[
"libc/_"] =
"";
90 HeaderSearchOptions HSOpts;
91 auto Add = [&](
const LangOptions &LO,
92 std::vector<llvm::StringRef> SearchPath) {
93 SourceManagerForFile SM(
"scratch",
"");
94 SM.get().getFileManager().setVirtualFileSystem(FS.view(std::nullopt));
95 HeaderSearch HS(HSOpts, SM.get(), SM.get().getDiagnostics(), LO,
97 for (
auto P : SearchPath)
100 cantFail(SM.get().getFileManager().getDirectoryRef(
testPath(P))),
101 SrcMgr::C_System,
false),
103 return Set.add(LO, HS);
112 EXPECT_FALSE(Add(LO, {
"std"})) <<
"Disabled in config";
115 Cfg.Index.StandardLibrary =
true;
118 EXPECT_FALSE(Add(LO, {
"std"})) <<
"No <vector> found";
119 FS.Files[
"std/vector"] =
"class vector;";
120 EXPECT_TRUE(Add(LO, {
"std"})) <<
"Indexing as C++98";
121 EXPECT_FALSE(Add(LO, {
"std"})) <<
"Don't reindex";
122 LO.CPlusPlus11 =
true;
123 EXPECT_TRUE(Add(LO, {
"std"})) <<
"Indexing as C++11";
124 LO.CPlusPlus =
false;
125 EXPECT_FALSE(Add(LO, {
"libc"})) <<
"No <stdio.h>";
126 FS.Files[
"libc/stdio.h"] =
true;
127 EXPECT_TRUE(Add(LO, {
"libc"})) <<
"Indexing as C";
131 return arg.Name == Name && arg.Includes.size() == 1 &&
132 llvm::StringRef(arg.Includes.front().Header).starts_with(
"<");
135TEST(StdLibTests, EndToEnd) {
141 FS.
Files[
"stdlib/vector"] =
142 "namespace std { template <class> class vector; }";
143 FS.Files[
"stdlib/list"] =
144 " namespace std { template <typename T> class list; }";
148 Opts.BuildDynamicSymbolIndex =
true;
153 Server.addDocument(
testPath(
"foo.cc"),
A.code());
154 ASSERT_TRUE(Server.blockUntilIdleForTest());
155 clangd::CodeCompleteOptions CCOpts;
159 Completions.Completions,
160 UnorderedElementsAre(StdlibSymbol(
"list"), StdlibSymbol(
"vector")));
163TEST(StdLibTests, StdLibDocComments) {
169 FS.
Files[
"stdlib/vector"] = R
"cpp(
180 Opts.BuildDynamicSymbolIndex =
true;
185 Server.addDocument(
testPath(
"foo.cc"),
"");
188 ASSERT_TRUE(Server.blockUntilIdleForTest());
196 Req.Scopes = {
"std::vector::"};
198 Inputs.Inputs.Index->fuzzyFind(
199 Req, [&](
const Symbol &Sym) {
202 Result = std::move(Builder).
build();
205 ASSERT_EQ(Result.size(), 1u);
206 EXPECT_EQ(Result.begin()->Documentation,
"doc comment");
static cl::opt< std::string > Config("config", desc(R"(
Specifies a configuration in YAML/JSON format:
-config="{Checks:' *', CheckOptions:{x:y}}"
When the value is empty, clang-tidy will
attempt to find a file named .clang-tidy for
each source file in its parent directories.
)"), cl::init(""), cl::cat(ClangTidyCategory))
Same as llvm::Annotations, but adjusts functions to LSP-specific types for positions and ranges.
Manages a collection of source files and derived data (ASTs, indexes), and provides language-aware fe...
static Options optsForTest()
std::vector< std::string > ExtraClangFlags
llvm::StringMap< std::string > Files
SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
SymbolSlab build() &&
Consumes the builder to finalize the slab.
An immutable symbol container that stores a set of symbols.
WithContextValue extends Context::current() with a single value.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
std::unique_ptr< CompilerInvocation > buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D, std::vector< std::string > *CC1Args)
Builds compiler invocation that could be used to build AST or preamble.
llvm::Expected< CodeCompleteResult > runCodeComplete(ClangdServer &Server, PathRef File, Position Pos, clangd::CodeCompleteOptions Opts)
std::string testPath(PathRef File, llvm::sys::path::Style Style)
TEST(BackgroundQueueTest, Priority)
llvm::StringRef getStdlibUmbrellaHeader(const LangOptions &LO)
llvm::Error runCustomAction(ClangdServer &Server, PathRef File, llvm::function_ref< void(InputsAndAST)> Action)
SymbolSlab indexStandardLibrary(llvm::StringRef HeaderSources, std::unique_ptr< CompilerInvocation > CI, const StdLibLocation &Loc, const ThreadsafeFS &TFS)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Settings that express user/project preferences and control clangd behavior.
static clangd::Key< Config > Key
Context key which can be used to set the current Config.
struct clang::clangd::Config::@072252370142323110175010006107105013140064217165 Index
Controls index behavior.
std::string Query
A query string for the fuzzy find.
llvm::SmallVector< std::string > Paths
The class presents a C++ symbol, e.g.