Skip to content

Add index range hints for syntax errors/warnings in eval_string#8472

Open
isuffix wants to merge 1 commit into
typst:mainfrom
isuffix:eval-index-range-hints
Open

Add index range hints for syntax errors/warnings in eval_string#8472
isuffix wants to merge 1 commit into
typst:mainfrom
isuffix:eval-index-range-hints

Conversation

@isuffix

@isuffix isuffix commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

When using the eval function, we set a synthetic span on the evaluated string, but this overrides the spans for error and warning diagnostics and leads to a pessimistic range on diagnostics. Improving these ranges would require a lot of effort, and is not even feasible at all in the general case, but there are some simpler improvements we can make.

This PR takes the step of adding a hint to syntax errors and warnings containing the original index range of the diagnostic. This does not apply to evaluation errors like undefined variables, but is a step in the right direction.

This is an improvement for #7799, but is not a complete fix.

CC @JeppeKlitgaard

@isuffix isuffix force-pushed the eval-index-range-hints branch from 4ff6319 to ce5ce7b Compare June 9, 2026 21:16
@isuffix isuffix added the diagnostics Improvements to compiler errors label Jun 9, 2026
Comment on lines 384 to 390
fn synthesize_with(
&mut self,
mut offset: usize,
map_span: &impl Fn(usize, usize) -> Span,
update_sub_range: &impl Fn(usize, &mut Option<SubRange>),
add_hint: &impl Fn(usize, usize) -> Option<EcoString>,
) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This signature is starting to get unwieldy, but it would probably be more effort to duplicate it since the behaviors of synthesize and synthesize_mapped are still very similar.

@isuffix isuffix force-pushed the eval-index-range-hints branch from ce5ce7b to 635dc32 Compare June 9, 2026 21:21
@laurmaedje laurmaedje added the waiting-on-review This PR is waiting to be reviewed. label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Improvements to compiler errors waiting-on-review This PR is waiting to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants