Skip to content

Commit a85e1d6

Browse files
committed
[Markup] Print Tags in documentation comment XML
This information needs to be picked up through SourceKit. It might be useful as both metadata for sorting/filtering as well as presentation, so it makes sense to print it in the normal XML inside CommentParts. rdar://problem/32877771
1 parent ce8c0eb commit a85e1d6

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

Diff for: bindings/xml/comment-xml-schema.rng

+31
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
<optional>
4747
<ref name="ResultDiscussion" />
4848
</optional>
49+
<optional>
50+
<ref name="Tags" />
51+
</optional>
4952
<optional>
5053
<ref name="Discussion" />
5154
</optional>
@@ -115,6 +118,9 @@
115118
<optional>
116119
<ref name="ResultDiscussion" />
117120
</optional>
121+
<optional>
122+
<ref name="Tags" />
123+
</optional>
118124
<optional>
119125
<ref name="Discussion" />
120126
</optional>
@@ -166,6 +172,9 @@
166172
<optional>
167173
<ref name="ResultDiscussion" />
168174
</optional>
175+
<optional>
176+
<ref name="Tags" />
177+
</optional>
169178

170179
<optional>
171180
<ref name="Discussion" />
@@ -209,6 +218,9 @@
209218
<optional>
210219
<ref name="ResultDiscussion" />
211220
</optional>
221+
<optional>
222+
<ref name="Tags" />
223+
</optional>
212224

213225
<optional>
214226
<ref name="Discussion" />
@@ -252,6 +264,9 @@
252264
<optional>
253265
<ref name="ResultDiscussion" />
254266
</optional>
267+
<optional>
268+
<ref name="Tags" />
269+
</optional>
255270

256271
<optional>
257272
<ref name="Discussion" />
@@ -294,6 +309,9 @@
294309
<optional>
295310
<ref name="ResultDiscussion" />
296311
</optional>
312+
<optional>
313+
<ref name="Tags" />
314+
</optional>
297315

298316
<optional>
299317
<ref name="Discussion" />
@@ -337,6 +355,9 @@
337355
<optional>
338356
<ref name="ResultDiscussion" />
339357
</optional>
358+
<optional>
359+
<ref name="Tags" />
360+
</optional>
340361

341362
<optional>
342363
<ref name="Discussion" />
@@ -640,6 +661,16 @@
640661
</element>
641662
</define>
642663

664+
<define name="Tags">
665+
<element name="Tags">
666+
<oneOrMore>
667+
<element name="Tag">
668+
<data type="string" />
669+
</element>
670+
</oneOrMore>
671+
</element>
672+
</define>
673+
643674
<define name="Parameters">
644675
<element name="Parameters">
645676
<!-- Parameter elements should be sorted according to index. -->

Diff for: lib/IDE/CommentConversion.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,19 @@ struct CommentToXMLConverter {
245245
OS << "</ThrowsDiscussion>";
246246
}
247247

248+
void printTagFields(ArrayRef<StringRef> Tags) {
249+
OS << "<Tags>";
250+
for (const auto Tag : Tags) {
251+
if (Tag.empty()) {
252+
continue;
253+
}
254+
OS << "<Tag>";
255+
appendWithXMLEscaping(OS, Tag);
256+
OS << "</Tag>";
257+
}
258+
OS << "</Tags>";
259+
}
260+
248261
void visitDocComment(const DocComment *DC);
249262
void visitCommentParts(const swift::markup::CommentParts &Parts);
250263
};
@@ -271,6 +284,10 @@ void CommentToXMLConverter::visitCommentParts(const swift::markup::CommentParts
271284
if (Parts.ThrowsField.hasValue())
272285
printThrowsDiscussion(Parts.ThrowsField.getValue());
273286

287+
if (!Parts.Tags.empty()) {
288+
printTagFields(Parts.Tags);
289+
}
290+
274291
if (!Parts.BodyNodes.empty()) {
275292
OS << "<Discussion>";
276293
for (const auto *N : Parts.BodyNodes)

Diff for: test/Inputs/comment_to_something_conversion.swift

+12
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,15 @@ public func localizationKeyShouldNotAppearInDocComments() {}
477477
/// - LocalizationKey: ABC
478478
public func localizationKeyShouldNotAppearInDocComments2() {}
479479
// CHECK: DocCommentAsXML=[<Function file="{{.*}}" line="{{.*}}" column="{{.*}}"><Name>localizationKeyShouldNotAppearInDocComments2()</Name><USR>s:14comment_to_xml44localizationKeyShouldNotAppearInDocComments2yyF</USR><Declaration>public func localizationKeyShouldNotAppearInDocComments2()</Declaration><CommentParts></CommentParts></Function>]
480+
481+
/// Brief.
482+
///
483+
/// - Tag:
484+
/// - Tag:
485+
/// - Tag: Tag_A
486+
/// - Tag: Tag B
487+
/// - Tag: Dedupe tag
488+
/// - Tag: Dedupe tag
489+
/// - TAG: TAG_C
490+
public func tags() {}
491+
// CHECK: DocCommentAsXML=[<Function file="{{.*}}" line="{{.*}}" column="{{.*}}"><Name>tags()</Name><USR>s:14comment_to_xml4tagsyyF</USR><Declaration>public func tags()</Declaration><CommentParts><Abstract><Para>Brief.</Para></Abstract><Tags><Tag>Tag_A</Tag><Tag>Tag B</Tag><Tag>Dedupe tag</Tag><Tag>TAG_C</Tag></Tags></CommentParts></Function>]

0 commit comments

Comments
 (0)