fix --ide-ast when there are errors (#13737)

# Description

This PR fixes #13732. However, I don't think it's a proper fix.
1. It doesn't really show what the problem is.
2. It kind of side-steps the error entirely.

I do think the change in span.rs may be valid because I don't think
span.end should ever be 0. In the example in 13732 the span end was
always 0 and so that made contains_span() return true, which seems like
a false positive.

The `checked_sub()` in ide.rs kind of just stops it from failing
outloud.

I'll leave it to smarter folks than me to land this if they think it's
worthy.
This commit is contained in:
Darren Schroeder 2024-09-05 18:17:40 -05:00 committed by GitHub
parent 92091599ff
commit b2cab3274b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -130,7 +130,7 @@ impl Span {
}
pub fn contains_span(&self, span: Self) -> bool {
self.start <= span.start && span.end <= self.end
self.start <= span.start && span.end <= self.end && span.end != 0
}
/// Point to the space just past this span, useful for missing values

View File

@ -642,8 +642,8 @@ pub fn ast(engine_state: &mut EngineState, file_path: &str) {
{
"type": "ast",
"span": {
"start": span.start - offset,
"end": span.end - offset,
"start": span.start.checked_sub(offset),
"end": span.end.checked_sub(offset),
},
"shape": shape.to_string(),
"content": content // may not be necessary, but helpful for debugging