-
Notifications
You must be signed in to change notification settings - Fork 26
Support setting syntax highlighters for quasiquotes? #88
Comments
Sorry for the belated reply, I somehow managed to miss this. So, answer to your question is both yes and no. While it's entirely possible to embed other grammars into language-haskell, it comes with its own set of challenges. And it's definitely not configurable on the user-end, at least not without some dark and forbidden magic (which is fragile by definition) So at best, I could eventually add support for TH quasiquotes, since those have rigid syntax definitions. For user-defined quasiquoters, that's just not worth it, IMO -- this would create more problems in the long run than solve, e.g. a flaky third-party grammar can easily break highlighting in Haskell files almost completely. P.S. also, support for user-defined quasiquoters opens a whole another can of worms if it's not configurable on the user-end, which I don't want to even think about. |
I would also like to have this. I understand that the mappings are hard-coded into the grammar and can't be modified by the user, but I still think it would be useful. Something like this would be awesome: I've never made a Textmate/Sublime/Atom grammar before, so I mocked that one up with this simple grammar: name: 'Haskell'
scopeName: 'source.haskell'
fileTypes: [ 'hs' ]
patterns: [
{
begin: '\\[json\\|'
end: '\\|\\]'
patterns: [ include: 'source.json' ]
}
] Obviously that's a bit simplistic. For the Real World ™️, two naive solutions come to mind:
|
I really don't like the idea of hard-coding this stuff, besides this grammar is used to highlight Haskell on GitHub as well, so I wonder if talking about Adding all the "usual suspects" (json, yaml, sql, html, javascript, etc) would be possible in theory, but then it opens a can of worms of "why isn't X included". And with hardcoded prefixes there's another can of worms of "library Y uses prefix X for language Z". I'd personally much rather keep those proverbial cans closed.
Not possible. You'd need to include an external grammar based on what's parsed, and I'm pretty sure Atom's grammar model doesn't support this. I suspect partly because allowing something like that could break stuff really easily, and partly because it would be horribly inefficient (because you can't build a finite automaton if there are potentially infinite states) |
Bummer. For comparison, I feel like a partial solution here is better than nothing at all. Properly syntax highlighting SQL inside a quasi quote is definitely "nice to have"; treating it as a string is obviously okay. In my mind, supporting a couple of languages is a nice bonus rather than a "this needs to allow embedding everything under the sun". |
I came looking for a way to use SQL highlighting with the |
@lierdakil Thanks! I didn't quite get it working, but I'm very excited. Can you spot anything I'm doing wrong? I used Result, still no injected syntax highlighting; I sanity-checked the scopes: I also tried restarting atom, but no change. 😅 |
I can't see anything incorrect in the screenshots. Atom won't usually pick up the grammar injection package without a restart (or two), but usually running |
I can't make it go (I even rebooted), but thanks for looking it over for me. |
@lierdakil blindly modeling after this gist, I switched the injectionSelector: 'quoted.quasiquotes.qq-here.haskell'
scopeName: 'source.sql'
patterns: [ { include: 'source.sql' } ] to injectionSelector: 'quoted.quasiquotes.qq-here.haskell'
scopeName: 'quoted.quasiquotes.qq-here.haskell'
patterns: [ { include: 'source.sql' } ] and that worked for me after a |
Huh. Curious. Thanks for letting me know. |
I often use quasiquoters for things like JSON, SQL queries, JavaScript code, etc. It would be great if there was a way to configure quasiquoters with specific names to syntax highlight for the syntax they implement.
Is such a thing possible now? Is it possible at all with Atom's syntax highlighting support?
The text was updated successfully, but these errors were encountered: