Rekkonnect / Syndiesis

The most revolutionary syntax visualizer
MIT License
56 stars 5 forks source link

Code editor syntax highlighting #4

Closed Rekkonnect closed 4 months ago

Rekkonnect commented 5 months ago

The code editor can receive a syntax highlighting buff. However, we won't speculatively update the highlighting live until another pass.

While typing, the characters that were already there will preserve their original highlighting until the analysis is performed. The inserted characters will not be highlighted until the pass is done. Removing characters will adjust the highlighting of existing characters correspondingly.

The syntax highlighting can be split into two stages, one syntactic and one semantic. The semantic pass will show more information about identifiers that are not already classified. Declared symbols can be semantically analyzed in the syntactic pass since we already know their classification from their syntax parents.

During both passes, the code editor lines will be invalidated regionally, and the updating will happen by using channels, to reduce the overhead of the semantic analysis.

danipen commented 4 months ago

AvaloniaEdit is a powerful code editor written in Avalonia with quite advances features. It could help with syntax highlight, multi caret, show tabs/white spaces, search and replace... etc. I encourage you to take a look.

Rekkonnect commented 4 months ago

Thanks for the suggestion. My only concern is the syntax highlighting. AvaloniaEdit doesn't seem to provide a way for custom highlighting, or does it? It would however be very nice to avoid having to implement all these features by hand.

danipen commented 4 months ago

As you have all the tokens, probably your best choice is implementing a new custom syntax highlight. You can see an example here: https://github.com/AvaloniaUI/AvaloniaEdit/blob/88625c4491af8ca6fa9127872ae1f1099fd06392/src/AvaloniaEdit.TextMate/GenericLineTransformer.cs#L32

Anyway, coloring lines (background, foreground, text style) is an extensible mechanism, so if you don't want to rewrite the whole syntax highlight you can probably write a new DocumentColorizedTransformer to do your stuff.

Rekkonnect commented 4 months ago

Thanks for the guidance, I'll have a look around