From 8eb2c50967a594b9ba1ba0b6d9a4906e427b20fa Mon Sep 17 00:00:00 2001 From: Victoria Mitchell Date: Mon, 13 Feb 2023 15:15:57 -0700 Subject: [PATCH 1/2] don't split attribute fragments with a separate typeIdentifier fragment rdar://104930571 --- lib/SymbolGraphGen/DeclarationFragmentPrinter.cpp | 3 ++- .../Mixins/DeclarationFragments/Full/CustomAttr.swift | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/SymbolGraphGen/DeclarationFragmentPrinter.cpp b/lib/SymbolGraphGen/DeclarationFragmentPrinter.cpp index ae9e83a708aca..f1b2de647b9f1 100644 --- a/lib/SymbolGraphGen/DeclarationFragmentPrinter.cpp +++ b/lib/SymbolGraphGen/DeclarationFragmentPrinter.cpp @@ -136,7 +136,8 @@ void DeclarationFragmentPrinter::printStructurePre(PrintStructureKind Kind, void DeclarationFragmentPrinter::printTypeRef(Type T, const TypeDecl *RefTo, Identifier Name, PrintNameContext NameContext) { - openFragment(FragmentKind::TypeIdentifier); + if (Kind != FragmentKind::Attribute) + openFragment(FragmentKind::TypeIdentifier); printText(Name.str()); USR.clear(); diff --git a/test/SymbolGraph/Symbols/Mixins/DeclarationFragments/Full/CustomAttr.swift b/test/SymbolGraph/Symbols/Mixins/DeclarationFragments/Full/CustomAttr.swift index 88259dddadd7c..68c4b907fc140 100644 --- a/test/SymbolGraph/Symbols/Mixins/DeclarationFragments/Full/CustomAttr.swift +++ b/test/SymbolGraph/Symbols/Mixins/DeclarationFragments/Full/CustomAttr.swift @@ -32,11 +32,7 @@ public func wrapped(@SomeWrapper arg: Int) {} // CHECK-NEXT: }, // CHECK-NEXT: { // CHECK-NEXT: "kind": "attribute", -// CHECK-NEXT: "spelling": "@" -// CHECK-NEXT: }, -// CHECK-NEXT: { -// CHECK-NEXT: "kind": "typeIdentifier", -// CHECK-NEXT: "spelling": "SomeWrapper", +// CHECK-NEXT: "spelling": "@SomeWrapper", // CHECK-NEXT: "preciseIdentifier": "s:10CustomAttr11SomeWrapperV" // CHECK-NEXT: }, // CHECK-NEXT: { From aafa4182901b0c5f511a9bd257abd5f30b3ec98c Mon Sep 17 00:00:00 2001 From: Victoria Mitchell Date: Wed, 15 Feb 2023 14:21:38 -0700 Subject: [PATCH 2/2] review: break the attribute name into its own fragment again --- lib/SymbolGraphGen/DeclarationFragmentPrinter.cpp | 7 ++++++- .../Mixins/DeclarationFragments/Full/CustomAttr.swift | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/SymbolGraphGen/DeclarationFragmentPrinter.cpp b/lib/SymbolGraphGen/DeclarationFragmentPrinter.cpp index f1b2de647b9f1..f31c6541a2fcd 100644 --- a/lib/SymbolGraphGen/DeclarationFragmentPrinter.cpp +++ b/lib/SymbolGraphGen/DeclarationFragmentPrinter.cpp @@ -136,8 +136,13 @@ void DeclarationFragmentPrinter::printStructurePre(PrintStructureKind Kind, void DeclarationFragmentPrinter::printTypeRef(Type T, const TypeDecl *RefTo, Identifier Name, PrintNameContext NameContext) { - if (Kind != FragmentKind::Attribute) + if (Kind != FragmentKind::Attribute) { openFragment(FragmentKind::TypeIdentifier); + } else { + // create a separate fragment so that only the attribute name is linkable + closeFragment(); + openFragment(FragmentKind::Attribute); + } printText(Name.str()); USR.clear(); diff --git a/test/SymbolGraph/Symbols/Mixins/DeclarationFragments/Full/CustomAttr.swift b/test/SymbolGraph/Symbols/Mixins/DeclarationFragments/Full/CustomAttr.swift index 68c4b907fc140..2ceb623647d1c 100644 --- a/test/SymbolGraph/Symbols/Mixins/DeclarationFragments/Full/CustomAttr.swift +++ b/test/SymbolGraph/Symbols/Mixins/DeclarationFragments/Full/CustomAttr.swift @@ -32,7 +32,11 @@ public func wrapped(@SomeWrapper arg: Int) {} // CHECK-NEXT: }, // CHECK-NEXT: { // CHECK-NEXT: "kind": "attribute", -// CHECK-NEXT: "spelling": "@SomeWrapper", +// CHECK-NEXT: "spelling": "@" +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "kind": "attribute", +// CHECK-NEXT: "spelling": "SomeWrapper", // CHECK-NEXT: "preciseIdentifier": "s:10CustomAttr11SomeWrapperV" // CHECK-NEXT: }, // CHECK-NEXT: {