Issue
I am using a language I made with a similar syntax to python, and I wanted to use python syntax highlighting for my language as well.
The only problem is that my language uses curly brackets rather then : and indents.
So some times when I type return for example it highlights the return in red.
Is there any way I can disable error highlights?
Solution
The decision about what code is valid and what code is invalid is something that's happening inside of the syntax definition (in this case, Python.sublime-syntax
in the Python
package). Any code that it deems is incorrect is scoped as invalid
to convey that, and your color scheme knows to display code that's invalid in a certain way.
As such the best course of action would be to create your own syntax definition for your language so that the structure of the code is considered valid. That said this is a somewhat large undertaking depending on how in depth you want to get with it. It may help to use the existing syntax as a starting point however.
Coming at it from the other angle, instead of modifying the syntax specification to know that the code is valid, you can mask the problem by modifying your color scheme so that it doesn't apply any specific syntax highlighting to the invalid
scope.
For examine, the Monokai.sublime-color-scheme
contains the following rule for making invalid code white on red:
{
"name": "Invalid",
"scope": "invalid",
"foreground": "var(white2)",
"background": "var(red2)"
},
By creating an override on the color scheme and removing or commenting out that rule (or whatever rule matches in the color scheme that you use), invalid code will lose the color highlight you show in your image.
The down side to this is that since the syntax has determined that the code is invalid, the only usable scope
that's applied to it is the invalid
scope; the information that this is a special language keyword has been lost.
That means that in your case return
won't be displayed as invalid, but it also won't be "properly" syntax highlighted and will appear as plain text.
Depending on how much code appears invalid, this may or may not be an acceptable trade off.
Answered By - OdatNurd Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.