Skip to content

SpannedError: Store error span#569

Merged
juntyr merged 17 commits into
ron-rs:masterfrom
pfnsec:feat/spanned-error-range
Jun 7, 2025
Merged

SpannedError: Store error span#569
juntyr merged 17 commits into
ron-rs:masterfrom
pfnsec:feat/spanned-error-range

Conversation

@pfnsec

@pfnsec pfnsec commented May 3, 2025

Copy link
Copy Markdown
Contributor
  • I've included my change in CHANGELOG.md

Hi! We're working on basic language server support for RON, both for the core syntax and as a small lib for easily bringing up custom language servers based on custom Rust types. In order to support this, we propose storing the error position in SpannedError as a start and end position, instead of a single position. This PR implements all the necessary logic for this proposal, and fixes all tests to validate correctly against the new SpannedError format.

Here's what our budding language server work looks like with our PR:

image
image
image
image

Note that this PR doesn't include the language server work itself.
In theory, this should make the modified unit tests more robust also, since they now validate against 2 positions instead of just 1.

I think it would be better to merge #567 before this PR if approved, and I'll go in and double check my changes against the new HEAD and make sure all of the tests are still passing.

P.S. thanks for RON, it's great!

Comment thread CHANGELOG.md Outdated
Comment thread src/de/mod.rs Outdated
Comment thread src/de/tests.rs Outdated
Comment thread src/error.rs Outdated
Comment thread src/value/raw.rs Outdated
@juntyr

juntyr commented May 3, 2025

Copy link
Copy Markdown
Member

Thanks @pfnsec for working on this feature! I like the general idea and mostly had some small design questions and thoughts on how we might be able to better test the spans.

@juntyr

juntyr commented May 14, 2025

Copy link
Copy Markdown
Member

@pfnsec #567 has now been merged

pfnsec and others added 2 commits May 15, 2025 20:09
Co-authored-by: Juniper Tyree <50025784+juntyr@users.noreply.github.com>
@pfnsec pfnsec force-pushed the feat/spanned-error-range branch from 2373f64 to ccb2de8 Compare May 15, 2025 12:10
@pfnsec pfnsec force-pushed the feat/spanned-error-range branch from ccb2de8 to c6fbefb Compare May 15, 2025 12:18
@pfnsec

pfnsec commented May 16, 2025

Copy link
Copy Markdown
Contributor Author
rustc-LLVM ERROR: IO failure on output stream: No space left on device
error: could not compile `ron` (test "449_tagged_enum")

egads! :P

@juntyr

juntyr commented May 17, 2025

Copy link
Copy Markdown
Member

@pfnsec Perhaps you could add a cargo clean between each step of the CI check job?

@juntyr

juntyr commented May 17, 2025

Copy link
Copy Markdown
Member

I meant further above, lines 77, 80, and 85 where the check, clippy, and test steps are. Could you add a clean step between those?

@pfnsec pfnsec force-pushed the feat/spanned-error-range branch from 6478a11 to 7eda5b6 Compare May 17, 2025 04:01
@pfnsec

pfnsec commented May 17, 2025

Copy link
Copy Markdown
Contributor Author

Ah, my bad. Like this?

@juntyr juntyr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you so much @pfnsec for adding the extra tests, I only left a few nits

Comment thread Cargo.toml Outdated
Comment thread src/de/tests.rs Outdated
Comment thread src/de/tests.rs Outdated
Comment thread src/de/tests.rs Outdated
Comment thread src/de/tests.rs Outdated
Comment thread src/error.rs Outdated
Comment thread src/error.rs Outdated
Comment thread src/error.rs Outdated
@juntyr

juntyr commented Jun 2, 2025

Copy link
Copy Markdown
Member

@juntyr

juntyr commented Jun 2, 2025

Copy link
Copy Markdown
Member

Functionality-wise, I'm happy with the changes and so now we just need to do a bit of cleanup

@pfnsec

pfnsec commented Jun 2, 2025

Copy link
Copy Markdown
Contributor Author

Hopefully that should fix all the lints. As for the additional span tests you mentioned, we'd have to include unicode-segmentation as a dependency proper as mentioned above. It would be an easy addition if you're fine with the extra dep.

@juntyr

juntyr commented Jun 2, 2025

Copy link
Copy Markdown
Member

Hopefully that should fix all the lints. As for the additional span tests you mentioned, we'd have to include unicode-segmentation as a dependency proper as mentioned above. It would be an easy addition if you're fine with the extra dep.

Since we'd only use it in the tests, would it still not just be a test dependency? If that doesn't work, maybe we could move the span text extraction code into its own module and add the module to those tests as well (using an explicit module path attribute)? It would be a bit of a hack but should be good enough for the three files.

@pfnsec

pfnsec commented Jun 2, 2025

Copy link
Copy Markdown
Contributor Author

Unfortunately integration tests only test the public interface of the library, so gating modules through #[cfg(test)] won't work. We could have a non-default feature, test-span-substring, that triggers an optional dependency on unicode-segmentation and gate every relevant integration test through that, but that may be enough plumbing to warrant a separate PR.

@pfnsec

pfnsec commented Jun 2, 2025

Copy link
Copy Markdown
Contributor Author

Oh, now I follow, you mean doing something like

[#path = "../src/util/span_substr.rs"]
pub mod span_substr;

, right? I'll take a stab at it tomorrow.

@juntyr

juntyr commented Jun 3, 2025

Copy link
Copy Markdown
Member

Oh, now I follow, you mean doing something like

[#path = "../src/util/span_substr.rs"]
pub mod span_substr;

, right? I'll take a stab at it tomorrow.

Yes, if that doesn’t work I’ve opened #571 and we can do it in a separate PR - if it does we can close the issue immediately :)

@pfnsec

pfnsec commented Jun 3, 2025

Copy link
Copy Markdown
Contributor Author

Alas, it doesn't work - by importing it that way with an explicit path we end up implementing a fn for the foreign types ron::de::Position and ron::de::Span, along with other crate:: import path mismatches. I've split it off into a separate module to do the optional-feature plumbing mentioned above. I think it may be the cleanest option.

…d an optional (non-default) feature, include substring Span checks in non-trivial integration tests
@pfnsec pfnsec force-pushed the feat/spanned-error-range branch from dd4970d to 9c7cdab Compare June 3, 2025 11:09
@pfnsec

pfnsec commented Jun 3, 2025

Copy link
Copy Markdown
Contributor Author

Hopefully this is clean enough for our liking :)
unicode-segmentation is retained as a dev dependency for unit tests. It's also no-std friendly, so it shouldn't interfere with the work there. The existing error checking asserts are retained as well along with the feature-gated span checks.

Comment thread Cargo.toml Outdated
@pfnsec

pfnsec commented Jun 3, 2025

Copy link
Copy Markdown
Contributor Author

Hold up, I think I got my wires crossed here with ron::util mod layout. Will fix in the morning...

@pfnsec

pfnsec commented Jun 4, 2025

Copy link
Copy Markdown
Contributor Author

Alas...

System.IO.IOException: No space left on device : '/home/runner/actions-runner/cached/...'

Comment thread .github/workflows/ci.yaml Outdated
Comment thread CHANGELOG.md Outdated
@juntyr juntyr changed the title SpannedError: Store position_start and position_end SpannedError: Store error span Jun 7, 2025
@juntyr

juntyr commented Jun 7, 2025

Copy link
Copy Markdown
Member

@pfnsec I'm happy to merge now unless there's anything else from your end?

@pfnsec

pfnsec commented Jun 7, 2025

Copy link
Copy Markdown
Contributor Author

Nope, nothing else on my end! Thanks :D

@juntyr juntyr merged commit 27a26d6 into ron-rs:master Jun 7, 2025
12 checks passed
@juntyr

juntyr commented Jun 7, 2025

Copy link
Copy Markdown
Member

Thanks @pfnsec for all of your work on this feature!

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