Skip to content

Commit 5795ae4

Browse files
add documentation category to the symbol graph
1 parent 2e7e6c0 commit 5795ae4

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ extension Text {
119119

120120
## `@_documentation(...)`
121121

122-
Adds a "documentation category" to the given symbol.
122+
Adds a "documentation category" to the given symbol. The identifier in the
123+
attribute is added to the symbol graph in the `"category"` field of the symbol.
123124

124125
There are two special-case categories: `underscored` will treat the given symbol
125126
as having an underscored name regardless of its actual name, effectively marking

lib/SymbolGraphGen/Symbol.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/Basic/PrimitiveParsing.h"
2020
#include "swift/Basic/SourceManager.h"
2121
#include "swift/Basic/Unicode.h"
22+
#include "swift/SymbolGraphGen/DocumentationCategory.h"
2223
#include "clang/AST/ASTContext.h"
2324
#include "clang/AST/Decl.h"
2425
#include "clang/Basic/SourceManager.h"
@@ -452,6 +453,12 @@ void Symbol::serializeAccessLevelMixin(llvm::json::OStream &OS) const {
452453
OS.attribute("accessLevel", getAccessLevelSpelling(VD->getFormalAccess()));
453454
}
454455

456+
void Symbol::serializeCategoryMixin(llvm::json::OStream &OS) const {
457+
StringRef Category = documentationCategoryForDecl(VD);
458+
if (!Category.empty())
459+
OS.attribute("category", Category);
460+
}
461+
455462
void Symbol::serializeLocationMixin(llvm::json::OStream &OS) const {
456463
if (ClangNode ClangN = VD->getClangNode()) {
457464
if (!Graph->Walker.Options.IncludeClangDocs)
@@ -592,6 +599,7 @@ void Symbol::serialize(llvm::json::OStream &OS) const {
592599
serializeDeclarationFragmentMixin(OS);
593600
serializeAccessLevelMixin(OS);
594601
serializeAvailabilityMixin(OS);
602+
serializeCategoryMixin(OS);
595603
serializeLocationMixin(OS);
596604
serializeSPIMixin(OS);
597605
});

lib/SymbolGraphGen/Symbol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class Symbol {
7272

7373
void serializeAccessLevelMixin(llvm::json::OStream &OS) const;
7474

75+
void serializeCategoryMixin(llvm::json::OStream &OS) const;
76+
7577
void serializeLocationMixin(llvm::json::OStream &OS) const;
7678

7779
void serializeAvailabilityMixin(llvm::json::OStream &OS) const;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -module-name DocumentationCategories -emit-module -emit-module-path %t/
3+
// RUN: %target-swift-symbolgraph-extract -module-name DocumentationCategories -I %t -pretty-print -output-dir %t
4+
// RUN: %FileCheck %s --input-file %t/DocumentationCategories.symbols.json
5+
6+
// CHECK: "category": "cool_stuff"
7+
@_documentation(cool_stuff) public class SomeClass {}
8+

0 commit comments

Comments
 (0)