Skip to content

Commit 646963c

Browse files
[clangd] Store documentation when indexing standard library
Fixes clangd/clangd#2344
1 parent fff8f03 commit 646963c

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

clang-tools-extra/clangd/index/Background.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ llvm::Error BackgroundIndex::index(tooling::CompileCommand Cmd) {
306306
return true;
307307
};
308308
IndexOpts.CollectMainFileRefs = true;
309+
IndexOpts.StoreAllDocumentation = false;
309310

310311
IndexFileIn Index;
311312
auto Action = createStaticIndexingAction(

clang-tools-extra/clangd/index/IndexAction.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ std::unique_ptr<FrontendAction> createStaticIndexingAction(
223223
Opts.CollectIncludePath = true;
224224
if (Opts.Origin == SymbolOrigin::Unknown)
225225
Opts.Origin = SymbolOrigin::Static;
226-
Opts.StoreAllDocumentation = false;
227226
if (RefsCallback != nullptr) {
228227
Opts.RefFilter = RefKind::All;
229228
Opts.RefsInHeaders = true;

clang-tools-extra/clangd/indexer/IndexerMain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class IndexActionFactory : public tooling::FrontendActionFactory {
5555
std::unique_ptr<FrontendAction> create() override {
5656
SymbolCollector::Options Opts;
5757
Opts.CountReferences = true;
58+
Opts.StoreAllDocumentation = false;
5859
Opts.FileFilter = [&](const SourceManager &SM, FileID FID) {
5960
const auto F = SM.getFileEntryRefForID(FID);
6061
if (!F)

clang-tools-extra/clangd/unittests/StdLibTests.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,43 @@ TEST(StdLibTests, EndToEnd) {
158158
UnorderedElementsAre(StdlibSymbol("list"), StdlibSymbol("vector")));
159159
}
160160

161+
TEST(StdLibTests, StdLibDocComments) {
162+
Config Cfg;
163+
Cfg.Index.StandardLibrary = true;
164+
WithContextValue Enabled(Config::Key, std::move(Cfg));
165+
166+
MockFS FS;
167+
FS.Files["stdlib/vector"] = R"cpp(
168+
namespace std {
169+
template <typename T>
170+
class vector {
171+
public:
172+
/**doc comment*/
173+
unsigned int size() const;
174+
};
175+
}
176+
)cpp";
177+
MockCompilationDatabase CDB;
178+
CDB.ExtraClangFlags.push_back("-isystem" + testPath("stdlib"));
179+
ClangdServer::Options Opts = ClangdServer::optsForTest();
180+
Opts.BuildDynamicSymbolIndex = true; // also used for stdlib index
181+
ClangdServer Server(CDB, FS, Opts);
182+
183+
Annotations A(R"cpp(
184+
#include <vector>
185+
void foo() {
186+
std::vector<int> v;
187+
v.si^ze();
188+
}
189+
)cpp");
190+
191+
Server.addDocument(testPath("foo.cc"), A.code());
192+
ASSERT_TRUE(Server.blockUntilIdleForTest());
193+
auto HI = cantFail(runHover(Server, testPath("foo.cc"), A.point()));
194+
EXPECT_TRUE(HI.has_value());
195+
EXPECT_EQ(HI->Documentation, "doc comment");
196+
}
197+
161198
} // namespace
162199
} // namespace clangd
163200
} // namespace clang

clang-tools-extra/clangd/unittests/SyncAPI.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ template <typename T> CaptureProxy<T> capture(std::optional<T> &Target) {
6868
}
6969
} // namespace
7070

71+
llvm::Expected<std::optional<HoverInfo>> runHover(ClangdServer &Server,
72+
PathRef File, Position Pos) {
73+
std::optional<llvm::Expected<std::optional<HoverInfo>>> HI;
74+
Server.findHover(File, Pos, capture(HI));
75+
return std::move(*HI);
76+
}
77+
7178
llvm::Expected<CodeCompleteResult>
7279
runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
7380
clangd::CodeCompleteOptions Opts) {

clang-tools-extra/clangd/unittests/SyncAPI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ void runAddDocument(ClangdServer &Server, PathRef File, StringRef Contents,
2929
WantDiagnostics WantDiags = WantDiagnostics::Auto,
3030
bool ForceRebuild = false);
3131

32+
llvm::Expected<std::optional<HoverInfo>> runHover(ClangdServer &Server,
33+
PathRef File, Position Pos);
34+
3235
llvm::Expected<CodeCompleteResult>
3336
runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
3437
clangd::CodeCompleteOptions Opts);

0 commit comments

Comments
 (0)