-
-
Notifications
You must be signed in to change notification settings - Fork 133
feat(highlighting): implement syntax highlighting for unnamed source codes #425
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
@zkat sure, I can do that. I'll simply create the |
} | ||
fn line_count(&self) -> usize { | ||
self.line_count | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
Currently, both
name
andlanguage
are part of theSpanContents
abstraction, which comes from theNamedSource
struct. It would make more semantic sense if those were part of theSourceCode
abstraction instead. This would allow us to use syntax highlighting in unnamed source codes, which is not currently possible. This PR proposes this.Changes
NamedSource
toMietteSourceCode
, addinglanguage
to it.name()
andlanguage()
fromSpanContents
trait toSourceCode
trait.name
andlanguage
fromMietteSpanContents
struct toMietteSourceCode
struct.This is a breaking change because it refactors public APIs.
Before
After