Skip to content
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

GraphCollector has limited logic to determine a "main" symbol graph #88

Open
heckj opened this issue Nov 6, 2024 · 0 comments · May be fixed by #89
Open

GraphCollector has limited logic to determine a "main" symbol graph #88

heckj opened this issue Nov 6, 2024 · 0 comments · May be fixed by #89

Comments

@heckj
Copy link
Member

heckj commented Nov 6, 2024

Stemming from debugging swiftlang/swift-docc#1084 -

When GraphCollector.mergeSymbolGraph(_ inputGraph: SymbolGraph, at url: URL, forceLoading: Bool = false) is called (from SymbolGraphLoader in swift-docc in my case), it uses some internal logic to determine if the symbolGraph being added is a primary source for the symbol graph symbols, or an extension.

This logic is contained in the private, static function moduleForName(_:at:), which uses the the logic of the URL having (or not) a @ symbol in it. If it does, then the symbolgraph is an extension - and if not, it's primary.

Unfortunately, this logic doesn't account for the concept of snippets - which have their own symbol graphs, and by this logic show up as "primary" in the collector. This limited logic, combined with a bit of "first one that matches" logic in swift-docc, is the heart of a non-deterministic lookup of the module name when a snippet exists, resulting in the module's isVirtual property being reported as true in the unified symbol graph, and because of that, the relevant files don't get written to disk and the preview fails to work as expected.

I believe the correct logic here would be to look for an '@' symbol, or the existence of snippet in the final path component of the URL string. Add on a double-check to look for the generator metadata of snippet extractor in the symbolgraph itself, and if it both contains snippet and is from the extractor, then report the module as an "extension" instead of "primary". (the metadata check would alleviate the corner case where the module name itself included the string snippet in it's name).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant