Skip to content

don't automatically transfer the child elements' ranges to the parent #202

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

Merged
merged 4 commits into from
Sep 24, 2024

Conversation

QuietMisdreavus
Copy link
Contributor

Bug/issue #, if applicable: rdar://136218537

Summary

The subsitutingChild(_:through:) method on RawMarkup introduced in #196 has the option to preserve the element's original source range. However, this fell back to the new child's range if its parent had no source range. This caused an issue where the assertion in the Aside initializer was being tripped when a BlockQuote had no parsed range, but its inner Paragraph did. This PR removes the fallback and just copies in the parent's source range if the preserveRange option is set.

In a separate commit, i also added a new initializer requirement to BasicBlockContainer that adds an inheritSourceRange option, to allow the new container to inherit the source range of its children even though it's a synthetic wrapper. This method can be used in Swift-DocC when a list item is converted into an aside to propagate that source range up through the new aside.

Dependencies

None

Testing

As this is an API change, the functionality is covered by automated testing.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • Updated documentation if necessary

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

}

/// Default implementation of `init(_:inheritSourceRange:)` that discards the `inheritSourceRange` parameter.
public init<Children: Sequence>(_ children: Children, inheritSourceRange: Bool) where Children.Element == BlockMarkup {
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: you should be able to express the same generic constraint with (unless there's something about the protocol conformance that doesn't allow that)

Suggested change
public init<Children: Sequence>(_ children: Children, inheritSourceRange: Bool) where Children.Element == BlockMarkup {
public init(_ children: some Sequence<BlockMarkup>, inheritSourceRange: Bool) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weren't some and any added in a relatively recent Swift release? What's our minimum supported Swift version for Swift-Markdown?

Copy link
Contributor

@d-ronnqvist d-ronnqvist Sep 19, 2024

Choose a reason for hiding this comment

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

There were many proposals for the some keyword (SE-0328, SE-0341, SE-0360) and any keyword (SE-0335, SE-0352, SE-0353) but AFAICT they're all supported in Swift 5.7 which is the minimum version that Swift-Markdown currently supports.

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 just ran a test using a Swift 5.7 Docker image and it seemed to build just fine, so i went ahead and added it. 🤷‍♀️

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you could do the same in these places as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, the reason this code was written like this was because of the way the original protocol requirement was written. If we want to do this conversion in one place we should do it everywhere. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And now that i'm looking through the rest of the codebase, the same treatment can be applied to BasicInlineContainer, the initializers on the Doxygen elements, and more places that were written before some Protocol was widespread...

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus QuietMisdreavus merged commit 7530dfe into swiftlang:main Sep 24, 2024
2 checks passed
@QuietMisdreavus QuietMisdreavus deleted the range-propagation branch September 24, 2024 18:37
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.

2 participants