Feature Request: Lexer-/Parser-Based Syntax highlighting
I think migrating to treesitter (Maybe using a modified Java implementation? Would need to modify the Languages class and build.py to support GLSL though) based syntax highlighting could be worthwhile.
Reasons:
- It is fast for big files
- It potentially supports changes in source code without recreating all the spans
- Potential for future semantic highlighting / analysis for autocompletion
Treesitter looks really interesting! I'll give it a try for sure! Since fragment shaders are usually quite short (of course I know this is not always the case 😉), the current solution is/was good enough for most cases. But it sure has it's shortcomings, and that the editor is getting slower when the code gets bigger has plagued this app for while now.
The Java implementation is flawed IMO, but there also is android-tree-sitter, which is a simple dependency for Gradle. This is already used in their IDE AndroidIDE to highlight XML and Java. They (obviously) don't have GLSL grammar, but this might be a simple task as the developer kindly outlined the steps in an issue I opened. Having tried a simple example using the Java grammar (com.itsaky.androidide:tree-sitter-java:3.0.1), it seems to "just work". There also already is an official (at least linked on the official site) grammar for GLSL: theHamsta/tree-sitter-glsl.
Hello again!
I think I have now implemented a syntax highlighting solution that works quite fast. The lag now comes from the EditText and not the (separate) SyntaxEditor View. I have also moved the line numbers into its own view, however this has one side effect: when the EditText changes size vertically (i.e. a new line), the phone scrolls to put the cursor at the far left of the screen. I will look into MovementMethod to see if this can be fixed. Maybe this is not that big of a problem? Also I have increased the API level temporarily to use android/trace, this will be reverted. Of course I will open several pull requests for the various changes. You can look at the changed version here: c-highlight branch