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

Add snippet support #61

Merged
merged 1 commit into from
Jan 21, 2022
Merged

Add snippet support #61

merged 1 commit into from
Jan 21, 2022

Conversation

bitjammer
Copy link
Member

@bitjammer bitjammer commented Dec 16, 2021

Add snippet support

  • Add a @Snippet block directive that takes one argument: the path
    to the snippet as if it were a symbol link.
  • Render a snippet as follows:
    • The snippet explanation
    • For each snippet chunk:
      • The name in bold if present
      • The source code as a code block

Snippets are transmitted to DocC via the Symbol Graph format.

Snippets do not have their own dedicated page as they won't have accompanying
long-form content. Snippets may be collected in a snippet "index" where one can
easily search or browse for them in one place, where they'll be grouped
appropriately.

This requires apple/swift-docc-symbolkit#10 (now merged)

This also requires apple/swift-docc-symbolkit#15.

@bitjammer
Copy link
Member Author

@franklinsch How would you like this tested?

@franklinsch
Copy link
Member

@bitjammer What do you think about the following:

  • Tests for Snippet.swift, to verify that we can parse the directive and emit the right diagnostics (we do the same for the other directives)
  • Integration-style test like the ones in SemaToRenderNodeTests, to verify the parsing -> render JSON emissions flow. We could add some snippets to one of the test bundles.

@bitjammer bitjammer force-pushed the acgarland/snippets branch 4 times, most recently from 550c0f0 to 4eaabc1 Compare January 13, 2022 01:34
@bitjammer
Copy link
Member Author

Tests added.

@bitjammer
Copy link
Member Author

@swift-ci Please test

@bitjammer
Copy link
Member Author

@swift-ci Please test Linux Platform

@bitjammer bitjammer removed the request for review from franklinsch January 13, 2022 04:20
@bitjammer bitjammer changed the title Add snippet support [WIP] Add snippet support Jan 18, 2022
@bitjammer
Copy link
Member Author

@swift-ci Please test

@bitjammer
Copy link
Member Author

Not sure if this repo supports building with other PRs – it needs apple/swift-docc-symbolkit#15. Temporarily edited Package.{swift,resolved} for the time being.

@bitjammer
Copy link
Member Author

@swift-ci Please test

@bitjammer
Copy link
Member Author

bitjammer commented Jan 19, 2022

replace_acceptable_years in check_source really needs another look at some point. I've updated check_source to work with 2022 to keep going on this PR.

@bitjammer
Copy link
Member Author

@swift-ci Please test

@bitjammer
Copy link
Member Author

@swift-ci Please test macOS Platform

@bitjammer
Copy link
Member Author

Okay @franklinsch ready for review when you have a moment. Thanks!

@bitjammer
Copy link
Member Author

@swift-ci Please test

@bitjammer bitjammer changed the title [WIP] Add snippet support Add snippet support Jan 20, 2022
guard !context.onlyHasSnippetRelatedChildren(for: documentationNode.reference),
documentationNode.kind != .snippet,
documentationNode.kind != .snippetGroup else {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Since knownPages already filter out pages with only snippet related content, would it make sense to fail the test if there's an unexpected snippet page?

Copy link
Member Author

Choose a reason for hiding this comment

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

Snippets don’t get their own page but are in the topic graph (for linking), so the fake module page would be empty. That knownPages filter is to keep those empty module topics from getting registered as a top level page. So snippets are expected in this test.

return []
}

let docCommentContent = snippetEntity.markup.children.flatMap { self.visit($0) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Have I understood correctly that this comes from the snippet's doc comment? If so, does that mean that snippets support styled inline content (e.g. strong and emphasis)?

If that's supported, would it be worth adding some styling to the test data?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right, you can write styled markdown in those comments. I'm not convinced that it needs its own test case since it's just a call to visit and those methods are already tested independently, but let me know if you feel strongly about it.

var elements = [RenderContent]()

if let chunkName = chunk.name {
elements.append(RenderBlockContent.paragraph(inlineContent: [
Copy link
Contributor

Choose a reason for hiding this comment

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

This code path isn't taken in the tests. I think that it'd be good to add a name to the snippet in the test data to be able to assert that that content is processed as expected.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

As an aside, chunk names aren't yet authorable but I can add some more test cases once that's implemented on the SwiftPM side if that's all right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. That sounds good to me.

Copy link
Contributor

@d-ronnqvist d-ronnqvist left a comment

Choose a reason for hiding this comment

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

This looks good to me. The Test Bundle displays the snipped like how I would expect.

I left two comments about potential cases that could also be tested but I don't feel that either of those is a required changes.

@bitjammer
Copy link
Member Author

Updated the Package.resolved now that I've merged apple/swift-docc-symbolkit#15.

@swift-ci Please test

- Add a `@Snippet` block directive that takes one argument: the path
to the snippet as if it were a symbol link.
- Render a snippet as follows:
  - The snippet explanation
  - For each snippet chunk:
    - The name in bold if present
    - The source code as a code block

Snippets do not have their own dedicated page as they won't have accompanying
long-form content. Snippets may be collected in a snippet "index" where one can
easily search or browse for them in one place, where they'll be grouped
appropriately.
@bitjammer
Copy link
Member Author

@swift-ci Please test

@bitjammer bitjammer merged commit 041bc6c into apple:main Jan 21, 2022
@bitjammer bitjammer deleted the acgarland/snippets branch January 21, 2022 03:50
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 this pull request may close these issues.

None yet

3 participants