-
Notifications
You must be signed in to change notification settings - Fork 192
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
Fix Directive argument name and value ranges on non-first line #79
Conversation
@swift-ci please test |
@@ -201,7 +201,8 @@ public struct DirectiveArgumentText: Equatable { | |||
var line = TrimmedLine(untrimmedText[...], | |||
source: range?.lowerBound.source, | |||
lineNumber: range?.lowerBound.line, | |||
parseIndex: parseIndex) | |||
parseIndex: parseIndex, | |||
startParseIndex: untrimmedText.index(parseIndex, offsetBy: 1 - (range?.lowerBound.column ?? 1))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code again, it seems like there's an existing lineStartIndex
property on this LineSegment
type that should always be populated. Did that not work for this purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Create an argument line segment.
/// - Parameters:
/// - untrimmedText: the segment's untrimmed text from which arguments can be parsed.
/// - lineStartIndex: the index in ``text`` where the line started.
means.
As the documentation says, lineStartIndex
is the index in text
where the line started.
And lineStartIndex
is init as untrimmedText.startIndex
in BlockDirectParser.
eg.
(lldb) po untrimmedText
"hello\n @Options(scope: page"
(lldb) po untrimmedText[lineStartIndex]
"h"
(lldb) po untrimmedText[untrimmedText.index(parseIndex, offsetBy: 1 - (range?.lowerBound.column ?? 1))]
" "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking around the usage of lineStartIndex
. It seems it's currently almost not used in any place.
The bug has been there for some time. Can anyone help continue to review this so that we can merge and solve it? Thanks |
f6d5535
to
fb27a4d
Compare
I looked at this today and as far as I can tell the issue is that /// The original untrimmed text of the line.
let untrimmedText: Substring whereas /// The segment's untrimmed text from which arguments can be parsed.
public var untrimmedText: String
/// The index in ``untrimmedText`` where the line started.
public var lineStartIndex: String.Index Because of this difference, passing the full untrimmed line from the line segment to the trimmed line is probably not the right thing to do. I checked out this branch to continue investigating this issue and two things worth pointing out:
Since the start and end of the line segment's "untrimmedText" is sliced in two different places, it raises a question of which place should be responsible for slicing the line segment's text. I think both of these should be done in one place, so I could imagine two different solutions here:
Looking at the other places that create a Since I had already done most of this locally at this point I opened a PR here with the changes I made. |
Thanks for the follow-up. I'll read and review it later this week. |
Also, update test to verify emoji ranges
Also deprecate `LineSegment.lineStartIndex` Also remove `lineStartIndex` parameter from internal `LineSegment` init
@swift-ci please test |
Do we need a 3rd people to help review this? @d-ronnqvist Maybe you can invite one |
@swift-ci please test |
@d-ronnqvist Would you help give this a final review so that we can merge it? |
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [apple/swift-markdown](https://redirect.github.com/apple/swift-markdown) | minor | `0.4.0` -> `0.5.0` | --- ### Release Notes <details> <summary>apple/swift-markdown (apple/swift-markdown)</summary> ### [`v0.5.0`](https://redirect.github.com/swiftlang/swift-markdown/releases/tag/0.5.0): Swift-Markdown 0.5.0 [Compare Source](https://redirect.github.com/apple/swift-markdown/compare/0.4.0...0.5.0) This release is based on the code that shipped into Swift 6.0. #### What's Changed - Add link title support for commonmark by [@​Kyle-Ye](https://redirect.github.com/Kyle-Ye) in [https://github.com/swiftlang/swift-markdown/pull/140](https://redirect.github.com/swiftlang/swift-markdown/pull/140) - Remove dependency on argument-parser by [@​ethan-kusters](https://redirect.github.com/ethan-kusters) in [https://github.com/swiftlang/swift-markdown/pull/149](https://redirect.github.com/swiftlang/swift-markdown/pull/149) - Fix utf8 decode by [@​zunda-pixel](https://redirect.github.com/zunda-pixel) in [https://github.com/swiftlang/swift-markdown/pull/145](https://redirect.github.com/swiftlang/swift-markdown/pull/145) - Fix multi line symbol link source range issue by [@​Kyle-Ye](https://redirect.github.com/Kyle-Ye) in [https://github.com/swiftlang/swift-markdown/pull/151](https://redirect.github.com/swiftlang/swift-markdown/pull/151) - Fix multiline directive without content parsing range issue by [@​Kyle-Ye](https://redirect.github.com/Kyle-Ye) in [https://github.com/swiftlang/swift-markdown/pull/154](https://redirect.github.com/swiftlang/swift-markdown/pull/154) - build: add a CMake based build by [@​compnerd](https://redirect.github.com/compnerd) in [https://github.com/swiftlang/swift-markdown/pull/141](https://redirect.github.com/swiftlang/swift-markdown/pull/141) - Add 2024 as an accepted year number by [@​Kyle-Ye](https://redirect.github.com/Kyle-Ye) in [https://github.com/swiftlang/swift-markdown/pull/160](https://redirect.github.com/swiftlang/swift-markdown/pull/160) - Fix Directive argument name and value ranges on non-first line by [@​Kyle-Ye](https://redirect.github.com/Kyle-Ye) in [https://github.com/swiftlang/swift-markdown/pull/79](https://redirect.github.com/swiftlang/swift-markdown/pull/79) - Add support for Doxygen discussion/note tags by [@​j-f1](https://redirect.github.com/j-f1) in [https://github.com/swiftlang/swift-markdown/pull/159](https://redirect.github.com/swiftlang/swift-markdown/pull/159) - Add support for formatting the new Doxygen types using MarkupFormatter by [@​j-f1](https://redirect.github.com/j-f1) in [https://github.com/swiftlang/swift-markdown/pull/163](https://redirect.github.com/swiftlang/swift-markdown/pull/163) - Support Windows ARM64 builds by [@​hjyamauchi](https://redirect.github.com/hjyamauchi) in [https://github.com/swiftlang/swift-markdown/pull/164](https://redirect.github.com/swiftlang/swift-markdown/pull/164) - build: silence warning about CMakeLists.txt from SPM by [@​compnerd](https://redirect.github.com/compnerd) in [https://github.com/swiftlang/swift-markdown/pull/167](https://redirect.github.com/swiftlang/swift-markdown/pull/167) #### New Contributors - [@​zunda-pixel](https://redirect.github.com/zunda-pixel) made their first contribution in [https://github.com/swiftlang/swift-markdown/pull/145](https://redirect.github.com/swiftlang/swift-markdown/pull/145) - [@​j-f1](https://redirect.github.com/j-f1) made their first contribution in [https://github.com/swiftlang/swift-markdown/pull/159](https://redirect.github.com/swiftlang/swift-markdown/pull/159) - [@​hjyamauchi](https://redirect.github.com/hjyamauchi) made their first contribution in [https://github.com/swiftlang/swift-markdown/pull/164](https://redirect.github.com/swiftlang/swift-markdown/pull/164) **Full Changelog**: swiftlang/swift-markdown@0.4.0...0.5.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://redirect.github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44OS4xIiwidXBkYXRlZEluVmVyIjoiMzguODkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: cgrindel-self-hosted-renovate[bot] <139595543+cgrindel-self-hosted-renovate[bot]@users.noreply.github.com>
Bug/issue #, if applicable:
Close #71
Summary
Dependencies
None
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeeded