How to fix SublimeText Lua(Solar2D) Colour Highlighting Bugs?

There are two highlight bugs specific to the ‘Solar2D syntax package aka Lua(Solar2D)’ for sublime text I want to fix. The colour scheme I’m using is not the problem, and it corrects these bugs when I swap to any other lua syntax package. Searching google for ‘how to edit sublime syntax package highlight’ has been an absolute rabbit hole.
Does anyone ‘know specifically’ how to make such fixes so the highlight works again? Please no untested responses, but even just how to access AND edit the right file would be helpful. The bugs which break highlighting, // denotes comments, are these:
require"test" //requires brackets OR space to work
function () --() //comments cant have a closed or unclosed )

I don’t know if @personalnadir is still active to answer your question but we might try :slight_smile:

That’s the Github repo if you want to make changes:

You’ll need to duplicate line 69 of the syntax file and change it so that for require the regex also accepts all the valid quotation marks. For the second one you want to look at line 19 you’ll need to change the regex to look for the first closing ‘)’ rather than the last.

Your best bet will be to find the syntax file for the working Lua file and then copy them over and see what works and what breaks. A diff program is going to be your friend.

1 Like

turns out require[[test]] is also valid. The syntactic sugar that allows for brackets to be omitted inconsistently is a mistake in my opinion:

> print "1"
1
> print 1
stdin:1: '=' expected near '1'
> print(1)
1
> print{1}
table: 0x600001118300

and

> assert[[bah]]
> assert '1'
> assert 1
stdin:1: '=' expected near '1'

Weird that it will break if the argument is a number but handle everything else.

Based on the above you don’t need to duplicate line 69, you just need to edit it to accept [[, ', " in addition to the existing space, ( and {

1 Like

I’m stuck trying to find where the file is. I installed from package control on windows.
The likely area:
…\AppData\Roaming\Sublime Text\Packages\Corona Editor
There’s only a menu file though, an unwritable sublime menu file.
In sublime package control I can run “view package file” and it brings up the syntax file successfully but doesn’t allow edits…and the path of the file is that same path above where there’s only a menu-file and nothing else. So I’m confused what to do. I could find and edit the syntax file of the neighboring luaLove folder.
I don’t know how to manually install from the github page I only see instructions for package control.

*edit: I downloaded the zip and transferred the syntax-file from that zip into the existing folder and now when I search it via package control it brings up that file I can now edit…I don’t understand that but okay.

Following the instructions below the quoted part, you can fork and redirect to your version where you can edit the code as you want:

If you want to help test the latest development version of Solar2D Editor you can configure Package Control to grab it instead of the official release version by following these steps:

So to make require"composer"/require’composer’/require[[composer]] work, you download the sublime-syntax file from git and toss it into the corona package file under windows roaming. And then package control: viewPackageFile now allows u to open and edit that syntax file. You go to line 69 and remove the quotes around the match regex and change the end from (?=[( {]) to (?=[( {"’[])

I don’t know what the quotes around the match regex are there for I couldn’t find explanation in the docs, is that just syntax sugar that can be removed? Cause not removing them breaks the file when I try to fix require’composer’. Was there a ’ " kind of exception character that sublime and its regex both respect so you don’t have to remove the quotes?

And the other problem of:
function() --)
Actually also extends to situations like this as well:
function() function()
On line 19. The solution I cameup with was changing…
- match: '(\w+)?(?:\s*=\s*)*(function\s*)(\w+\s*[:.]+)*(?:\s+)*(\w+)*\s*(\()(.*)(\))'
to…
- match: '(\w+)?(?:\s*=\s*)*(function\s*)(\w+\s*[:.]+)*(?:\s+)*(\w+)*\s*(\()[^)]*\)'
So changing the ending of
(.*)(\))
to
[^)]*\)

I assumed sublime had the most support since they advertised it with the stellar dracula theme in nice pictures on the front page, and sublime with this package as their rather joyful top recommendation in the docs.
I didn’t question some of the oddities since I was just learning the engine, but looking at it now, I have to say it doesn’t make any sense to me that parameters are uncoloured and function calls are uncoloured and various lua things are included in the engine yet left out of the colouring.

I really think this should be addressed. Is the dev team using lua(solar2d)? Shouldn’t they mostly be if they are recommending+advertising it as their top…? Do they mostly use the other official IDE syntax packages? Do those also use the same highlighting as the Sublime one? Can they explain these highlighting choices?
The solution of simply “just use normal lua or love2d or whatever then” isn’t fair when you are just learning the engine and how things work…Just loadup the tutorial game and swap from lua to lua(solar2d), the colouring is terribly disjointed all over the place. What does everyone reading this use?
I also don’t get why the auto-complete has alot of the same cmds listed and they generate things u don’t want or expect when u tab into them. Like display.newText vs display.newImageRect…u get two options for each completely different from eachother but named the same and display.newText’s two options are something not in the api newText(?) and the undesired display.newText(options)

I’m sorry to hear about your experience. I use Sublime Text as my daily driver but looking at your reaction, I guess I’m just used to it.

I didn’t understand what you are struggling with at the moment. Can you give me an example piece of code that’s causing you the problem? I’d really like it if you can use preformatted text button above so I can easily understand what that is and try it myself to understand the problem.

About display.newText() and some other APIs, that’s because there are multiple ways to call those functions. You can either use the basic/legacy mode and enter all the parameters that’s shown or pass a table including the options to create that object. Both are shown as both are valid.

Can you or someone help me get function parameters colourized?

The code I made:

 -match: (?<=function\s*[\w_.:]*[\('"{])[\w, ]*(?=[\)'"}]) 
  scope: variable.parameter.function.lua

Worked in https://regexr.com/, grabbing function name(x,y,z) and colourize the x,y,z. But variable length characters * ? + don’t work inside (?<=) in sublime apparently and the solution of using \K…doesn’t seems to work either…cause it’s not doing anything in sublime. And even if all that got sorted there is overlap with the existing -match definitions preventing it from showing up.

I cameup with the simpler code

- match: (?<=\()[\w, ]*(?=\))
scope: variable.parameter.function.lua

to just grab based on (x,y,z)

I thought you could piggyback off the existing scope definitions of functions the syntax file seems to define, but I can’t figure it out and the official doc entry on these syntax files I find to be very confusing (the only other doc I found was the ‘unofficial doc’ entry which barely covered anything). And I couldn’t figureout how to take the code of the existing lua syntax files with this highlighting and copy it into the existing syntax.

I got the functions colourized, opting to generalize the definitions since most of the things you misspell with the vanilla syntax file maintain their colour anyways. If anyone wants that it’s below, just replace the -match lines for the scopes support.function.lua and support.function.library.corona like:

- match: \b([\w_.:]*)(?=[("'{].*[)"'}])(?<!function)       
scope: support.function.lua
- match: '\b(ads|analytics|audio|composer|credits|crypto|display|easing|facebook|gameNetwork|global|graphics|io|json|lfs|licensing|math|mime|media|native|network|os|package|physics|socket|sprite|sqlite3|store|storyboard|string|syntax|system|table|timer|transition|widget)\.[a-zA-Z0-9]+\b'
scope: support.function.library.corona

The second match is kept for clauses like display.contentCenterY where there are no (). There’s some redundancy, so you can go through each keyword i.e. ads|analytics etc and weed it down. Similarly if u only want the exact spellings to be highlighted. I don’t find any of this straightforward so please forgive any overstating of the obvious.

I think the regex in the Sublime syntax definitions need to be inside single quotes, going off of the existing file, but I could be wrong.

You can test the regex in the standard Sublime find command panel if you enable the regex option. It uses the same matching it does for syntax.

Something I didn’t know: you can’t use anything that would make a variable length string in a lookbehind (?<= … ). If you use the https://regex101.com/ site, you can see that highlighted as a regex error.

However if you look at the existing syntax file, you can see that it is already detecting parameters (lines 19-29). It is just assigning them to ‘variable’. Perhaps you just need to change line 28?