Just to be more explicit, the file_regex
should have 4 captures in it which capture, in order:
- filename
- line number
- column number
- message
The only one that’s strictly needed from a usefulness perspective is the first one, the filename. Without that, Sublime can’t at least navigate you to the file that had the problem.
If you also capture a line number, then when the file is opened, it can also open it to the line that had the problem, and by extension can potentially annotate the line with the failure reason.
If you ALSO capture the column number, then the cursor can be placed more directly at the error point in the line instead of just at the start of the line, and any annotation can potentially be targetted directly at the error location (e.g. in ST3 the error bubble can point directly at the error).
If you ALSO capture the error message, then the message is used in the annotation so that when you browse to the error you can see what the actual problem was.
All that said, the captures are always interpreted in the order that is outlined above, so if the error output doesn’t have all of the parts, you may need to inject an empty capture in to “skip” it.
For example, if the error output is:
my_filename:52 This was a really bad error
With no column number, your regex is:
([^:]+):(\d+)()\s*(.*)
To say:
- Everything that is not a colon, up until we see a colon, is the filename portion
- There must then be a literal colon in the output
- Following the literal colon, there must be a sequence of 1 or more digits, which will be the line number
- Since there is no column number, but there is an error message, an empty capture captures “nothing” to take up the capture slot for the column
- The remainder of the line is the message, after skipping an arbitrary and optional amount of whitespace
The above regex presumes a non-windows file system where colons aren’t allowed to be in files. For your particular output, I would probably use something like the following instead:
([^(]+)\((\d+)\)():\s*(.*)
This works the same way but treats everything up to but not including the first (
character as the filename instead, like in your output sample above.
This however presumes that you’re not the kind of person that includes (
characters in your filenames; otherwise it will go wrong.
Also, none of these regex examples are JSON quoted (but you could for example test them against the expected output by using the Find/Replace panel or via regex101.