Skip to content
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

ast_parser: able to define start offset for tokens #9487

Closed
Sysix opened this issue Mar 2, 2025 · 1 comment
Closed

ast_parser: able to define start offset for tokens #9487

Sysix opened this issue Mar 2, 2025 · 1 comment
Labels
A-parser Area - Parser C-enhancement Category - New feature or request

Comments

@Sysix
Copy link
Collaborator

Sysix commented Mar 2, 2025

The AST-Parser will parse the source code from the offset 0.
oxc_linter has ParticialLoader which will create multiple source codes for <script> .

At the moment we need to remap the Diagnostic span offset to its original source code offset.
oxc_linter implementation: #9484
oxc_language_server:

fn wrap_diagnostics(
path: &Path,
source_text: &str,
reports: Vec<ErrorReport>,
start: u32,
) -> Vec<ErrorWithPosition> {
let source = Arc::new(NamedSource::new(path.to_string_lossy(), source_text.to_owned()));
reports
.into_iter()
.map(|report| {
ErrorWithPosition::new(
report.error.with_source_code(Arc::clone(&source)),
source_text,
report.fixed_content,
start as usize,
)
})
.collect()
}

I would like to give the ast parser an start offset (default 0) which he uses as a start position to generate the Ast::Kind spans.

@Sysix Sysix added A-parser Area - Parser C-enhancement Category - New feature or request labels Mar 2, 2025
@Boshen
Copy link
Member

Boshen commented Mar 3, 2025

I'm against adding a start offset to the parser - it's actually a lot of work.

Let's see whether we can improve the diagnostic reporter instead. Remember we use a fork https://github.com/oxc-project/oxc-miette

@Sysix Sysix closed this as completed Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area - Parser C-enhancement Category - New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants