Skip to content

Commit f2c9a2e

Browse files
committed
broken reference warnings
#feat fix #844
1 parent 136f63a commit f2c9a2e

File tree

10 files changed

+198
-13
lines changed

10 files changed

+198
-13
lines changed

src/lib/Metadata/Finalizers/ReferenceFinalizer.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,14 @@ finalize(doc::Node& node)
234234

235235
if constexpr(std::derived_from<NodeTy, doc::Reference>)
236236
{
237-
if (!resolveReference(N))
237+
if (!resolveReference(N) &&
238+
!warned_.contains({N.string, current_->Name}))
238239
{
239-
// The warning shouldn't be triggered if the symbol name
240-
// has been explicitly marked excluded in mrdocs.yml.
241-
// Finalizer needs to be updated to handle this case.
242-
// When tagfile support is implemented, we can't
243-
// report an error if the reference exists in the tagfile.
244-
// if constexpr (false)
245-
// {
246-
// report::warn(
247-
// "Failed to resolve reference to '{}' from '{}'",
248-
// N.string,
249-
// current_->Name);
250-
// }
240+
report::warn(
241+
"Failed to resolve reference to '{}' from '{}'",
242+
N.string,
243+
current_->Name);
244+
warned_.insert({N.string, current_->Name});
251245
}
252246
}
253247
});

src/lib/Metadata/Finalizers/ReferenceFinalizer.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include "lib/Lib/Info.hpp"
1616
#include "lib/Lib/Lookup.hpp"
17+
#include <set>
18+
#include <utility>
1719

1820
namespace clang::mrdocs {
1921

@@ -30,6 +32,7 @@ class ReferenceFinalizer
3032
InfoSet& info_;
3133
SymbolLookup& lookup_;
3234
Info* current_ = nullptr;
35+
std::set<std::pair<std::string, std::string>> warned_;
3336

3437
bool
3538
resolveReference(doc::Reference& ref) const;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
= Reference
2+
:mrdocs:
3+
4+
[#index]
5+
== Global namespace
6+
7+
8+
=== Functions
9+
10+
[cols=2]
11+
|===
12+
| Name | Description
13+
14+
| <<f0,`f0`>>
15+
|
16+
17+
| <<f1,`f1`>>
18+
| See xref:#f0[f0]
19+
20+
|===
21+
22+
[#f0]
23+
== f0
24+
25+
26+
=== Synopsis
27+
28+
29+
Declared in `&lt;broken&hyphen;ref&period;cpp&gt;`
30+
31+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
32+
----
33+
void
34+
f0();
35+
----
36+
37+
[#f1]
38+
== f1
39+
40+
41+
See xref:#f0[f0]
42+
43+
=== Synopsis
44+
45+
46+
Declared in `&lt;broken&hyphen;ref&period;cpp&gt;`
47+
48+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
49+
----
50+
void
51+
f1();
52+
----
53+
54+
=== Description
55+
56+
57+
See &colon;&colon;f2
58+
59+
Broken should be warned only once
60+
61+
See &colon;&colon;f2
62+
63+
64+
65+
66+
67+
[.small]#Created with https://www.mrdocs.com[MrDocs]#
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void f0();
2+
3+
/**
4+
See @ref f0
5+
6+
See @ref ::f2
7+
8+
Broken should be warned only once
9+
10+
See @ref ::f2
11+
*/
12+
void f1();
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<html lang="en">
2+
<head>
3+
<title>Reference</title>
4+
</head>
5+
<body>
6+
<div>
7+
<h1>Reference</h1>
8+
<div>
9+
<div>
10+
<h2 id="index">Global namespace</h2>
11+
</div>
12+
<h2>Functions</h2>
13+
<table style="table-layout: fixed; width: 100%;">
14+
<thead>
15+
<tr>
16+
<th>Name</th><th>Description</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr>
21+
<td><a href="#f0"><code>f0</code></a> </td><td>
22+
</td></tr><tr>
23+
<td><a href="#f1"><code>f1</code></a> </td><td><span><span>See </span><a href="#f0"><code>f0</code></a></span>
24+
25+
</td></tr>
26+
</tbody>
27+
</table>
28+
</div>
29+
<div>
30+
<div>
31+
<h2 id="f0">f0</h2>
32+
</div>
33+
<div>
34+
<h3>Synopsis</h3>
35+
<div>
36+
Declared in <code>&lt;broken-ref.cpp&gt;</code></div>
37+
<pre>
38+
<code class="source-code cpp">
39+
void
40+
f0();
41+
</code>
42+
</pre>
43+
</div>
44+
</div>
45+
<div>
46+
<div>
47+
<h2 id="f1">f1</h2>
48+
<div>
49+
<span><span>See </span><a href="#f0"><code>f0</code></a></span>
50+
51+
52+
</div>
53+
</div>
54+
<div>
55+
<h3>Synopsis</h3>
56+
<div>
57+
Declared in <code>&lt;broken-ref.cpp&gt;</code></div>
58+
<pre>
59+
<code class="source-code cpp">
60+
void
61+
f1();
62+
</code>
63+
</pre>
64+
</div>
65+
<div>
66+
<h3>Description</h3>
67+
<p><span>See </span><span>::f2</span></p>
68+
<p><span>Broken should be warned only once</span></p>
69+
<p><span>See </span><span>::f2</span></p>
70+
71+
72+
</div>
73+
</div>
74+
75+
</div>
76+
<div>
77+
<h4>Created with <a href="https://www.mrdocs.com">MrDocs</a></h4>
78+
</div>
79+
</body>
80+
</html>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc">
4+
<namespace id="//////////////////////////8=">
5+
<function name="f0" id="e1UQQek5v3C9OClW5cGf57XvwQo=">
6+
<file short-path="broken-ref.cpp" source-path="broken-ref.cpp" line="1"/>
7+
</function>
8+
<function name="f1" id="CnO51rIKTzfiVKHkR3TdPa0eo+8=">
9+
<file short-path="broken-ref.cpp" source-path="broken-ref.cpp" line="12"/>
10+
<doc>
11+
<para>
12+
<text>See </text>
13+
<reference id="e1UQQek5v3C9OClW5cGf57XvwQo=">f0</reference>
14+
</para>
15+
<para>
16+
<text>See </text>
17+
<reference>::f2</reference>
18+
</para>
19+
<para>
20+
<text>Broken should be warned only once</text>
21+
</para>
22+
<para>
23+
<text>See </text>
24+
<reference>::f2</reference>
25+
</para>
26+
</doc>
27+
</function>
28+
</namespace>
29+
</mrdocs>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)