Skip to content

Commit a81897e

Browse files
fix: Prefer doc comment on defn over forward decl (#298)
1 parent 1cf1a10 commit a81897e

File tree

7 files changed

+73
-8
lines changed

7 files changed

+73
-8
lines changed

indexer/Indexer.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ void MacroIndexer::emitDocumentOccurrencesAndSymbols(
239239
switch (macroOcc.role) {
240240
case Role::Definition: {
241241
scip::SymbolInformation symbolInfo;
242-
*symbolInfo.add_documentation() = "No documentation available.";
242+
*symbolInfo.add_documentation() =
243+
scip::missingDocumentationPlaceholder;
243244
ENFORCE(!occ.symbol().empty());
244245
macroOcc.emitSymbolInformation(occ.symbol(), symbolInfo);
245246
*document.add_symbols() = std::move(symbolInfo);
@@ -967,7 +968,7 @@ void TuIndexer::saveDefinition(
967968
return;
968969
}
969970
if (optSymbolInfo.has_value() && optSymbolInfo->documentation_size() == 0) {
970-
*optSymbolInfo->add_documentation() = "No documentation available.";
971+
*optSymbolInfo->add_documentation() = scip::missingDocumentationPlaceholder;
971972
}
972973
if (optStableFileId->isInProject) {
973974
auto &doc = this->saveOccurrence(symbol, expansionLoc,

indexer/ScipExtras.cc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,25 @@ void IndexBuilder::addForwardDeclaration(
275275
this->externalSymbols.erase(extIt);
276276
}
277277
if (!forwardDeclSym.documentation().empty()) {
278-
// FIXME(def: better-doc-merging): We shouldn't drop documentation
279-
// attached to a definition, if present.
278+
// FIXME(def: better-doc-merging): The missing documentation placeholder
279+
// value is due to a bug in the backend which seemingly came up randomly
280+
// and also got fixed somehow. We should remove the workaround if this
281+
// is no longer an issue.
280282
if (auto *symbolInfo = it->second.dyn_cast<scip::SymbolInformation *>()) {
281-
symbolInfo->mutable_documentation()->Clear();
282-
for (auto &doc : *forwardDeclSym.mutable_documentation()) {
283-
*symbolInfo->add_documentation() = std::move(doc);
283+
bool isMissingDocumentation =
284+
symbolInfo->documentation_size() == 0
285+
|| (symbolInfo->documentation_size() == 1
286+
&& symbolInfo->documentation()[0]
287+
== scip::missingDocumentationPlaceholder);
288+
if (isMissingDocumentation) {
289+
symbolInfo->mutable_documentation()->Clear();
290+
for (auto &doc : *forwardDeclSym.mutable_documentation()) {
291+
*symbolInfo->add_documentation() = std::move(doc);
292+
}
284293
}
285294
} else {
286295
auto &symbolInfoBuilder = *it->second.get<SymbolInformationBuilder *>();
287-
// FIXME(def: better-documentation-merging): We shouldn't drop
296+
// FIXME(def: better-doc-merging): We shouldn't drop
288297
// documentation attached to a forward declaration.
289298
if (!symbolInfoBuilder.hasDocumentation()) {
290299
symbolInfoBuilder.setDocumentation(

indexer/ScipExtras.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ struct OccurrenceExt {
7777
}
7878
};
7979

80+
constexpr char missingDocumentationPlaceholder[28] =
81+
"No documentation available.";
82+
8083
class SymbolInformationBuilder final {
8184
std::vector<std::string> documentation;
8285
absl::flat_hash_set<RelationshipExt> relationships;

test/index/fwd_decl/doc_check.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// format-options: showDocs
2+
3+
/// Doc comment on forward decl
4+
class F;
5+
6+
/// From forward decl
7+
class UndocumentedClass;
8+
9+
void f(F *) {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// format-options: showDocs
2+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition [..] `<file>/doc_check.cc`/
3+
//documentation
4+
//| File: doc_check.cc
5+
6+
/// Doc comment on forward decl
7+
class F;
8+
// ^ reference [..] F#
9+
10+
/// From forward decl
11+
class UndocumentedClass;
12+
// ^^^^^^^^^^^^^^^^^ reference [..] UndocumentedClass#
13+
14+
void f(F *) {}
15+
// ^ definition [..] f(84962a9dbd25570f).
16+
// documentation
17+
// | No documentation available.
18+
// ^ reference [..] F#

test/index/fwd_decl/doc_check_def.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// format-options: showDocs
2+
3+
/// Doc comment on definition
4+
class F {
5+
};
6+
7+
class UndocumentedClass {
8+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// format-options: showDocs
2+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition [..] `<file>/doc_check_def.cc`/
3+
//documentation
4+
//| File: doc_check_def.cc
5+
6+
/// Doc comment on definition
7+
class F {
8+
// ^ definition [..] F#
9+
// documentation
10+
// | Doc comment on definition
11+
};
12+
13+
class UndocumentedClass {
14+
// ^^^^^^^^^^^^^^^^^ definition [..] UndocumentedClass#
15+
// documentation
16+
// | From forward decl
17+
};

0 commit comments

Comments
 (0)