mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SymbolGraph] Use identifier for type name fragments
In the cases where we specialize the presentation of type declarations in a subheading or navigator setting, make sure to use the `identifier` fragment kind instead of `typeIdentifier` to keep it consistent with the normal or "full" setting. rdar://62953144
This commit is contained in:
@@ -148,38 +148,36 @@ void DeclarationFragmentPrinter::printText(StringRef Text) {
|
|||||||
Spelling.append(Text);
|
Spelling.append(Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeclarationFragmentPrinter::printAbridgedType(const GenericTypeDecl *TD) {
|
void DeclarationFragmentPrinter::printAbridgedType(const GenericTypeDecl *TD,
|
||||||
// Subheadings for types are abridged, omitting generics and inheritance.
|
bool PrintKeyword) {
|
||||||
openFragment(DeclarationFragmentPrinter::FragmentKind::Keyword);
|
if (PrintKeyword) {
|
||||||
switch (TD->getKind()) {
|
openFragment(DeclarationFragmentPrinter::FragmentKind::Keyword);
|
||||||
case DeclKind::Struct:
|
switch (TD->getKind()) {
|
||||||
printText(getTokenText(tok::kw_struct));
|
case DeclKind::Struct:
|
||||||
break;
|
printText(getTokenText(tok::kw_struct));
|
||||||
case DeclKind::Enum:
|
break;
|
||||||
printText(getTokenText(tok::kw_enum));
|
case DeclKind::Enum:
|
||||||
break;
|
printText(getTokenText(tok::kw_enum));
|
||||||
case DeclKind::Protocol:
|
break;
|
||||||
printText(getTokenText(tok::kw_protocol));
|
case DeclKind::Protocol:
|
||||||
break;
|
printText(getTokenText(tok::kw_protocol));
|
||||||
case DeclKind::Class:
|
break;
|
||||||
printText(getTokenText(tok::kw_class));
|
case DeclKind::Class:
|
||||||
break;
|
printText(getTokenText(tok::kw_class));
|
||||||
case DeclKind::TypeAlias:
|
break;
|
||||||
printText(getTokenText(tok::kw_typealias));
|
case DeclKind::TypeAlias:
|
||||||
break;
|
printText(getTokenText(tok::kw_typealias));
|
||||||
case DeclKind::OpaqueType:
|
break;
|
||||||
llvm_unreachable("OpaqueType should not be in symbol graphs!");
|
case DeclKind::OpaqueType:
|
||||||
default:
|
llvm_unreachable("OpaqueType should not be in symbol graphs!");
|
||||||
llvm_unreachable("GenericTypeDecl kind not handled in DeclarationFragmentPrinter!");
|
default:
|
||||||
|
llvm_unreachable("GenericTypeDecl kind not handled in DeclarationFragmentPrinter!");
|
||||||
|
}
|
||||||
|
|
||||||
|
openFragment(DeclarationFragmentPrinter::FragmentKind::Text);
|
||||||
|
printText(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
openFragment(DeclarationFragmentPrinter::FragmentKind::Text);
|
openFragment(DeclarationFragmentPrinter::FragmentKind::Identifier);
|
||||||
printText(" ");
|
|
||||||
|
|
||||||
openFragment(DeclarationFragmentPrinter::FragmentKind::TypeIdentifier);
|
|
||||||
printText(TD->getNameStr());
|
printText(TD->getNameStr());
|
||||||
|
|
||||||
USR.clear();
|
|
||||||
llvm::raw_svector_ostream USROS(USR);
|
|
||||||
ide::printDeclUSR(TD, USROS);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,10 @@ public:
|
|||||||
///
|
///
|
||||||
/// Subheadings for types don't include the complete declaration line
|
/// Subheadings for types don't include the complete declaration line
|
||||||
/// including generics and inheritance.
|
/// including generics and inheritance.
|
||||||
void printAbridgedType(const GenericTypeDecl *TD);
|
///
|
||||||
|
/// \param TD The type declaration to print.
|
||||||
|
/// \param PrintKeyword Print the corresponding keyword introducer if `true`.
|
||||||
|
void printAbridgedType(const GenericTypeDecl *TD, bool PrintKeyword);
|
||||||
|
|
||||||
void printDeclLoc(const Decl *D) override;
|
void printDeclLoc(const Decl *D) override;
|
||||||
|
|
||||||
|
|||||||
@@ -522,15 +522,14 @@ SymbolGraph::serializeNavigatorDeclarationFragments(StringRef Key,
|
|||||||
DeclarationFragmentPrinter Printer(OS, Key);
|
DeclarationFragmentPrinter Printer(OS, Key);
|
||||||
|
|
||||||
if (const auto *TD = dyn_cast<GenericTypeDecl>(S.getSymbolDecl())) {
|
if (const auto *TD = dyn_cast<GenericTypeDecl>(S.getSymbolDecl())) {
|
||||||
Printer.printTypeRef(TD->getInterfaceType(), TD, TD->getName(),
|
Printer.printAbridgedType(TD, /*PrintKeyword=*/false);
|
||||||
PrintNameContext::Normal);
|
} else {
|
||||||
return;
|
auto Options = getSubHeadingDeclarationFragmentsPrintOptions();
|
||||||
|
if (S.getSynthesizedBaseType()) {
|
||||||
|
Options.setBaseType(S.getSynthesizedBaseType());
|
||||||
|
}
|
||||||
|
S.getSymbolDecl()->print(Printer, Options);
|
||||||
}
|
}
|
||||||
auto Options = getSubHeadingDeclarationFragmentsPrintOptions();
|
|
||||||
if (S.getSynthesizedBaseType()) {
|
|
||||||
Options.setBaseType(S.getSynthesizedBaseType());
|
|
||||||
}
|
|
||||||
S.getSymbolDecl()->print(Printer, Options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -540,7 +539,7 @@ SymbolGraph::serializeSubheadingDeclarationFragments(StringRef Key,
|
|||||||
DeclarationFragmentPrinter Printer(OS, Key);
|
DeclarationFragmentPrinter Printer(OS, Key);
|
||||||
|
|
||||||
if (const auto *TD = dyn_cast<GenericTypeDecl>(S.getSymbolDecl())) {
|
if (const auto *TD = dyn_cast<GenericTypeDecl>(S.getSymbolDecl())) {
|
||||||
Printer.printAbridgedType(TD);
|
Printer.printAbridgedType(TD, /*PrintKeyword=*/true);
|
||||||
} else {
|
} else {
|
||||||
auto Options = getSubHeadingDeclarationFragmentsPrintOptions();
|
auto Options = getSubHeadingDeclarationFragmentsPrintOptions();
|
||||||
if (S.getSynthesizedBaseType()) {
|
if (S.getSynthesizedBaseType()) {
|
||||||
|
|||||||
@@ -17,9 +17,8 @@ public struct MyStruct<S> { public var x: S
|
|||||||
// MYSTRUCT-NEXT: "title": "MyStruct",
|
// MYSTRUCT-NEXT: "title": "MyStruct",
|
||||||
// MYSTRUCT-NEXT: "navigator": [
|
// MYSTRUCT-NEXT: "navigator": [
|
||||||
// MYSTRUCT-NEXT: {
|
// MYSTRUCT-NEXT: {
|
||||||
// MYSTRUCT-NEXT: "kind": "typeIdentifier"
|
// MYSTRUCT-NEXT: "kind": "identifier"
|
||||||
// MYSTRUCT-NEXT: "spelling": "MyStruct"
|
// MYSTRUCT-NEXT: "spelling": "MyStruct"
|
||||||
// MYSTRUCT-NEXT: "preciseIdentifier": "s:9Navigator8MyStructV"
|
|
||||||
// MYSTRUCT-NEXT: }
|
// MYSTRUCT-NEXT: }
|
||||||
// MYSTRUCT-NEXT: ]
|
// MYSTRUCT-NEXT: ]
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,8 @@
|
|||||||
// STRUCT-NEXT "spelling": " "
|
// STRUCT-NEXT "spelling": " "
|
||||||
// STRUCT-NEXT }
|
// STRUCT-NEXT }
|
||||||
// STRUCT-NEXT {
|
// STRUCT-NEXT {
|
||||||
// STRUCT-NEXT "kind": "typeIdentifier",
|
// STRUCT-NEXT "kind": "identifier",
|
||||||
// STRUCT-NEXT "spelling": "Struct",
|
// STRUCT-NEXT "spelling": "Struct"
|
||||||
// STRUCT-NEXT "preciseIdentifier": "s:35SubheadingDeclarationFragmentsTypes6StructV"
|
|
||||||
// STRUCT-NEXT }
|
// STRUCT-NEXT }
|
||||||
public struct Struct<T> where T: Sequence {}
|
public struct Struct<T> where T: Sequence {}
|
||||||
|
|
||||||
@@ -35,9 +34,8 @@ public struct Struct<T> where T: Sequence {}
|
|||||||
// ENUM-NEXT: "spelling": " "
|
// ENUM-NEXT: "spelling": " "
|
||||||
// ENUM-NEXT: }
|
// ENUM-NEXT: }
|
||||||
// ENUM-NEXT: {
|
// ENUM-NEXT: {
|
||||||
// ENUM-NEXT: "kind": "typeIdentifier",
|
// ENUM-NEXT: "kind": "identifier",
|
||||||
// ENUM-NEXT: "spelling": "Enum",
|
// ENUM-NEXT: "spelling": "Enum"
|
||||||
// ENUM-NEXT: "preciseIdentifier": "s:35SubheadingDeclarationFragmentsTypes4EnumO"
|
|
||||||
// ENUM-NEXT: }
|
// ENUM-NEXT: }
|
||||||
public enum Enum<T> where T: Sequence {}
|
public enum Enum<T> where T: Sequence {}
|
||||||
|
|
||||||
@@ -52,9 +50,8 @@ public enum Enum<T> where T: Sequence {}
|
|||||||
// PROTOCOL-NEXT: "spelling": " "
|
// PROTOCOL-NEXT: "spelling": " "
|
||||||
// PROTOCOL-NEXT: }
|
// PROTOCOL-NEXT: }
|
||||||
// PROTOCOL-NEXT: {
|
// PROTOCOL-NEXT: {
|
||||||
// PROTOCOL-NEXT: "kind": "typeIdentifier",
|
// PROTOCOL-NEXT: "kind": "identifier",
|
||||||
// PROTOCOL-NEXT: "spelling": "Protocol",
|
// PROTOCOL-NEXT: "spelling": "Protocol"
|
||||||
// PROTOCOL-NEXT: "preciseIdentifier": "s:35SubheadingDeclarationFragmentsTypes8ProtocolP"
|
|
||||||
// PROTOCOL-NEXT: }
|
// PROTOCOL-NEXT: }
|
||||||
public protocol Protocol where T: Sequence {
|
public protocol Protocol where T: Sequence {
|
||||||
associatedtype T
|
associatedtype T
|
||||||
@@ -71,9 +68,8 @@ public protocol Protocol where T: Sequence {
|
|||||||
// CLASS-NEXT "spelling": " "
|
// CLASS-NEXT "spelling": " "
|
||||||
// CLASS-NEXT },
|
// CLASS-NEXT },
|
||||||
// CLASS-NEXT {
|
// CLASS-NEXT {
|
||||||
// CLASS-NEXT "kind": "typeIdentifier",
|
// CLASS-NEXT "kind": "identifier",
|
||||||
// CLASS-NEXT "spelling": "Class",
|
// CLASS-NEXT "spelling": "Class"
|
||||||
// CLASS-NEXT "preciseIdentifier": "s:35SubheadingDeclarationFragmentsTypes5ClassC"
|
|
||||||
// CLASS-NEXT }
|
// CLASS-NEXT }
|
||||||
public class Class<T> where T: Sequence {}
|
public class Class<T> where T: Sequence {}
|
||||||
|
|
||||||
@@ -88,9 +84,8 @@ public class Class<T> where T: Sequence {}
|
|||||||
// TYPEALIAS-NEXT: "spelling": " "
|
// TYPEALIAS-NEXT: "spelling": " "
|
||||||
// TYPEALIAS-NEXT: },
|
// TYPEALIAS-NEXT: },
|
||||||
// TYPEALIAS-NEXT: {
|
// TYPEALIAS-NEXT: {
|
||||||
// TYPEALIAS-NEXT: "kind": "typeIdentifier",
|
// TYPEALIAS-NEXT: "kind": "identifier",
|
||||||
// TYPEALIAS-NEXT: "spelling": "TypeAlias",
|
// TYPEALIAS-NEXT: "spelling": "TypeAlias"
|
||||||
// TYPEALIAS-NEXT: "preciseIdentifier": "s:35SubheadingDeclarationFragmentsTypes9TypeAliasa"
|
|
||||||
// TYPEALIAS-NEXT: }
|
// TYPEALIAS-NEXT: }
|
||||||
public typealias TypeAlias<T> = Struct<T> where T: Collection
|
public typealias TypeAlias<T> = Struct<T> where T: Collection
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user