Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1169

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176
8000 feat(highlighting): implement syntax highlighting for unnamed source codes by glevco · Pull Request #425 · zkat/miette · GitHub
Nothing Special   »   [go: up one dir, main page]

Skip to content

Conversation

glevco
Copy link
Contributor
@glevco glevco commented Feb 19, 2025

Currently, both name and language are part of the SpanContents abstraction, which comes from the NamedSource struct. It would make more semantic sense if those were part of the SourceCode abstraction instead. This would allow us to use syntax highlighting in unnamed source codes, which is not currently possible. This PR proposes this.

Changes

  • Rename NamedSource to MietteSourceCode, adding language to it.
  • Move name() and language() from SpanContents trait to SourceCode trait.
  • Move name and language from MietteSpanContents struct to MietteSourceCode struct.

This is a breaking change because it refactors public APIs.

Before

let src = NamedSource::new("bad_file", "fn hello() {}").with_language("Rust");
let report = miette!("oops!").with_source_code(src);

After

let src = MietteSourceCode::new("fn hello() {}").with_name("bad_file").with_language("Rust");
let report = miette!("oops!").with_source_code(src);

// unnamed with language, not possible before!
let src = MietteSourceCode::new("fn hello() {}").with_language("Rust");
let report = miette!("oops!").with_source_code(src);

@zkat zkat added the breaking A semver-major breaking change label Mar 2, 2025
Copy link
Owner
@zkat zkat left a comment

Choose a reason for hiding this comment

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

I generally like this, but I'm gonna have to think more about moving those specific things around. I think there might be other things to be done about the struct to-be-formerly-known-as-NamedSource but I'll try and remember what else I thought might be nice.

I also don't know when I'll want to have a breaking release of miette. I try to keep them very very sparse, so if you 8000 can think of a way to do this without the breaking change, even if we eventually do the "nice" version, then that'll get unnamed source code highlighting working sooner for the community.

@glevco
Copy link
Contributor Author
glevco commented Mar 5, 2025

@zkat sure, I can do that. I'll simply create the MietteSourceCode like in this PR, but as a new struct instead of replacing the NamedSource with it. Then you can deprecate NamedSource and eventually remove it.

}
fn line_count(&self) -> usize {
self.line_count
}
Copy link
Contributor
@cgettys-microsoft cgettys-microsoft Sep 25, 2025

Choose a reason for hiding this comment

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

I'm not sure this is optimal to move off of SpanContents for reasons I noted in #450.

Specifically, today, the interface could handle fun scenarios like markdown like this:

# An introduction to Rust
Here's a Rust program!
```rust
fn hello_world()
{
   println!("hello world")
}
\```

(the \ is because I can't get GitHub to quite handle markdown inside its markdown with a code block inside it... unsurprisingly)

A markdown aware parser could go "right, this span is inside a code block, let's grab the bit after the backticks and use that as the language". The filename would remain whatever.md, but the language for that span would be whatever that is (in this case Rust).

Language being a property of SpanContents, IMO, thus makes sense. you can have multiple languages in one SourceCode
If you don't like the example of markdown, consider Razor/Blazor stuff, HTML, JavaScript, and CSS frequently living together, and so on and so on. Yes, the new interface could do this too, but it'd require representing those parts of the file as separate SourceCode.

I do see that there could be a more convenient interface; but I'm not (personally, for whatever little my opinion might be worth) sure this new interface is better.

Copy link
Contributor
@cgettys-microsoft cgettys-microsoft Sep 25, 2025

Choose a reason for hiding this comment

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

And SpanContents already can be used to provide language without name; both via your own struct implementing the trait and via MietteSpanContents::new; is there something I'm missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking A semver-major breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0