How to disable error syntax highlight Sublime Text 3

Question:

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?

Here is an Example:
enter image description here

Asked By: user6516763

||

Answers:

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

In your .sublime-color-scheme file, add a rule block changing the invalid scope background color to have full transparency.

For example, add this to your file, changing the background color as necessary.

// Hide invalid highlighting in markup
{
    "scope": "markup invalid",
    "background": "color(red alpha(0.0))", // 0.0 hides it, 1.0 shows it
},

In the above example, the background color must match the global invalid color found elsewhere in the file.

For example, this was already defined in my .sublime-color-scheme file.

{
    "scope": "invalid",
    "background": "red",
},
Answered By: Jeff
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.