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

Do I need to fill the source content of NamedSource by myself? #271

Closed
BppleMan opened this issue Jun 8, 2023 · 2 comments
Closed

Do I need to fill the source content of NamedSource by myself? #271

BppleMan opened this issue Jun 8, 2023 · 2 comments
Labels
question Further information is requested

Comments

@BppleMan
Copy link

BppleMan commented Jun 8, 2023

In the example in the repo README, the src of the NamedSource is a hardcoded source

let src = "source\n text\n here".to_string();

Does this mean that I need to hardcode some current error context codes for each error, and calculate the offset that needs to be labeled by myself?

I saw the SourceCode in the proc-macro, just got the ident, it seems that there is no step to get the source code file?

@zkat
Copy link
Owner

zkat commented Jun 29, 2023

A SourceCode is anything that implements the SourceCode trait. If you want to work off a file more dynamically, you'll need to write an implementation for it. All you need to be able to do is tell miette how to read a specific span from it: https://github.com/zkat/miette/blob/main/src/protocol.rs#L211-L231

@zkat zkat added the question Further information is requested label Jun 29, 2023
@BppleMan
Copy link
Author

I always thought that miette was a crate like coloreyre. Later I figured out that miette is suitable for some lexical analysis or as a language interpreter. I'm not sure. I always want to let miette capture the context part of the current rs code to use in some fancy output can be displayed when panic, this is probably some misunderstanding of mine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants