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

Possible syntax highlighting collaboration #39

Open
mattmassicotte opened this issue May 2, 2023 · 2 comments
Open

Possible syntax highlighting collaboration #39

mattmassicotte opened this issue May 2, 2023 · 2 comments

Comments

@mattmassicotte
Copy link

mattmassicotte commented May 2, 2023

I literally just finished watching the presentation of DeckUI at Deep Dish, and one part really spoke to me. I've worked a bunch with syntax highlighting, and in fact maintain a number of Swift packages that could potentially be useful. Now the stuff I do may not be a perfect fit, because it is all built to back a general-purpose text editing system. However, it can definitely still do static text.

Neon (https://github.com/chimeHQ/Neon) is a highlighting system.
SwiftTreeSitter (https://github.com/chimeHQ/SwiftTreeSitter) is the component that pulls out the syntactic info needed for highlighting.

I think the largest issue is probably with how the tree-sitter works, specifically how you support a language grammar. Each language requires its own Swift package. I've been (very slowly) SPM-ifying the language grammars themselves, but it isn't that hard and there's almost certainly tree-sitter support for whatever language might be of interest.

I figured I'd open up an issue first to talk about it, because in some ways this could be a great collaboration. Also, I’m not sure how this could be more of an over-engineered solution, so seemed appropriate.

@mattmassicotte mattmassicotte changed the title Possible syntax hjighlighting collaboration Possible syntax highlighting collaboration May 3, 2023
@mattmassicotte
Copy link
Author

Ok, so I've thought on this some more. I'm now no longer sure Neon is even needed in the static highlighting case. So really, what this could look like is:

  • Add SwiftTreeSitter as a dependency
  • Read out the language annotation from the markdown code block
  • Hunt for a grammar bundle matching that that (SwiftTreeSitter can kinda do this now)
  • Load the language or spit out a warning saying you need to add the per-language SPM package (yes this kinda sucks)
  • Run the highlights query to get semantic info about the tokens/ranges
  • Apply a theme*

All this really isn't too much work, except for the stupid theme part. Tree-sitter pulls out semantic information, but doesn't actually apply colors. This is actually a problem I've wanted to address for a while, so I put together a new repo that I think can bridge the gap between token labels and string attributes. However, it is totally non-functional at the moment.

https://github.com/ChimeHQ/ThemePark

@mattmassicotte
Copy link
Author

Just following up here, its been a while now! That ThemePark library is now completely functional and supports Xcode, TextMate, and BBEdit theme formats to various degrees.

So, this is now completely implemenatable!

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

No branches or pull requests

1 participant