Skip to content

feat: add mut LabelSpan.set_span_offset#62

Merged
Boshen merged 1 commit intomainfrom
07-29-feat_add_mut_labelspan.set_span_offset_
Jul 30, 2025
Merged

feat: add mut LabelSpan.set_span_offset#62
Boshen merged 1 commit intomainfrom
07-29-feat_add_mut_labelspan.set_span_offset_

Conversation

@Sysix
Copy link
Copy Markdown
Member

@Sysix Sysix commented Jul 29, 2025

For partial linter source text, we need to modify the offset of the span.

ATM this is how the oxlint does it:
https://github.com/oxc-project/oxc/blob/f9cbe844f207c0f578285204e6ecb8d650974165/crates/oxc_diagnostics/src/service.rs#L118-L168

In this function, it converts the function to a generic Error miette object. This is not wanted for the langauge server and the tester.

The language server does it when creating the MessageWithPosition:
https://github.com/oxc-project/oxc/blob/f9cbe844f207c0f578285204e6ecb8d650974165/crates/oxc_linter/src/service/runtime.rs#L645-L676

Currently, the tester does not fix the offset for partial source texts:
oxc-project/oxc#12545 (comment)


The goal:

Create a Message impl: https://github.com/oxc-project/oxc/blob/f9cbe844f207c0f578285204e6ecb8d650974165/crates/oxc_linter/src/fixer/mod.rs#L276-L294

So the offset adjustment can be done in one simple place and shared for all 3 inputs.

POC: https://github.com/oxc-project/oxc/pull/12594/files

    pub fn with_offset(&mut self, offset: u32) -> &mut Self {
        if offset == 0 {
            return self;
        }

        self.span =
            Span::new(self.span.start.saturating_add(offset), self.span.end.saturating_add(offset));

        if let Some(labels) = &mut self.error.labels {
            for label in labels {
                label.set_span_offset(label.offset().saturating_add(offset as usize));
            }
        }

        self
    }

Copy link
Copy Markdown
Member Author

Sysix commented Jul 29, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Sysix Sysix marked this pull request as ready for review July 29, 2025 20:32
@Boshen Boshen merged commit 9224275 into main Jul 30, 2025
14 checks passed
@Boshen Boshen deleted the 07-29-feat_add_mut_labelspan.set_span_offset_ branch July 30, 2025 01:13
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