Skip to content

Populate symbol kind in external render nodes #1251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ public class OutOfProcessReferenceResolver: ExternalDocumentationSource, GlobalE
imageReferences: (resolvedInformation.references ?? []).compactMap { $0 as? ImageReference }
)

return LinkResolver.ExternalEntity(topicRenderReference: renderReference, renderReferenceDependencies: dependencies, sourceLanguages: resolvedInformation.availableLanguages)
return LinkResolver.ExternalEntity(
topicRenderReference: renderReference,
renderReferenceDependencies: dependencies,
sourceLanguages: resolvedInformation.availableLanguages,
documentationKind: resolvedInformation.kind
)
}

// MARK: Implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ final class ExternalPathHierarchyResolver {
return .init(
topicRenderReference: resolvedInformation.topicRenderReference(),
renderReferenceDependencies: dependencies,
sourceLanguages: resolvedInformation.availableLanguages
sourceLanguages: resolvedInformation.availableLanguages,
documentationKind: resolvedInformation.kind
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ public class LinkResolver {
/// - topicRenderReference: The render reference for this external topic.
/// - renderReferenceDependencies: Any dependencies for the render reference.
/// - sourceLanguages: The different source languages for which this page is available.
/// - documentationKind: The kind of external content that's being referenced.
@_spi(ExternalLinks)
public init(topicRenderReference: TopicRenderReference, renderReferenceDependencies: RenderReferenceDependencies, sourceLanguages: Set<SourceLanguage>) {
public init(topicRenderReference: TopicRenderReference, renderReferenceDependencies: RenderReferenceDependencies, sourceLanguages: Set<SourceLanguage>, documentationKind: DocumentationNode.Kind) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a public API, shouldn't we deprecate it and create a new initializer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do this because it's experimental API and comes with a warning:

@_spi(ExternalLinks) // This isn't stable API yet.
public struct ExternalEntity {

WDYT? Happy to do as you suggested.

self.topicRenderReference = topicRenderReference
self.renderReferenceDependencies = renderReferenceDependencies
self.sourceLanguages = sourceLanguages
self.documentationKind = documentationKind
}

/// The render reference for this external topic.
Expand All @@ -63,7 +65,11 @@ public class LinkResolver {
var renderReferenceDependencies: RenderReferenceDependencies
/// The different source languages for which this page is available.
var sourceLanguages: Set<SourceLanguage>

/// The kind of external content that's being referenced.
///
/// For example, the navigator requires specific knowledge about what type of external symbol is being linked to.
var documentationKind: DocumentationNode.Kind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to store a DocumentationNode.Kind if we only need to access the symbol identifier that's derived from it?


/// Creates a pre-render new topic content value to be added to a render context's reference store.
func topicContent() -> RenderReferenceStore.TopicContent {
return .init(
Expand Down
3 changes: 2 additions & 1 deletion Tests/SwiftDocCTests/Benchmark/ExternalTopicsHashTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class ExternalTopicsGraphHashTests: XCTestCase {
estimatedTime: nil
),
renderReferenceDependencies: .init(),
sourceLanguages: [.swift]
sourceLanguages: [.swift],
documentationKind: .class
)
return (reference, entity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class ExternalReferenceResolverTests: XCTestCase {
}
),
renderReferenceDependencies: RenderReferenceDependencies(),
sourceLanguages: [resolvedEntityLanguage]
sourceLanguages: [resolvedEntityLanguage],
documentationKind: resolvedEntityKind
)
}
}
Expand Down Expand Up @@ -707,7 +708,8 @@ class ExternalReferenceResolverTests: XCTestCase {
estimatedTime: nil
),
renderReferenceDependencies: RenderReferenceDependencies(),
sourceLanguages: [.swift]
sourceLanguages: [.swift],
documentationKind: .instanceProperty
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class TestMultiResultExternalReferenceResolver: ExternalDocumentationSource {
images: entityInfo.topicImages?.map(\.0) ?? []
),
renderReferenceDependencies: dependencies,
sourceLanguages: [entityInfo.language]
sourceLanguages: [entityInfo.language],
documentationKind: entityInfo.kind
)
}
}
6 changes: 4 additions & 2 deletions Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,8 @@ class SemaToRenderNodeTests: XCTestCase {
estimatedTime: nil
),
renderReferenceDependencies: .init(),
sourceLanguages: [.objectiveC]
sourceLanguages: [.objectiveC],
documentationKind: .class
)
return (reference, entity)
}
Expand Down Expand Up @@ -1218,7 +1219,8 @@ class SemaToRenderNodeTests: XCTestCase {
estimatedTime: nil
),
renderReferenceDependencies: .init(),
sourceLanguages: [.swift]
sourceLanguages: [.swift],
documentationKind: .collection
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class OutOfProcessReferenceResolverTests: XCTestCase {
} else {
XCTFail("Unexpected fragments variant patch")
}

XCTAssertEqual(entity.documentationKind, .init(name: "Kind Name", id: "com.test.kind.id", isSymbol: true))
}

func testResolvingTopicLinkProcess() throws {
Expand Down