Sublime Forum

Build system regex improvement

#1

I have build 3126.

Currently, the file_regex only matches the file name and line number. When it does, it puts the full path and filename and line number in red into my source file window where the error is instead of the actual error.

This is very much redundant and unnecessary. I would much rather see the actual error message instead of the file name and line number. I already know the filename and line number just by looking at the message. Is there a setting to enable this or can this be the next important feature.

Thanks!

1 Like

Multiple file_regex per build system
Build system regex improvement 2
Linking files (C++) using build system
#2

Maybe I can put this more succinctly:

In build systems, file_regex allows you to extract the file and line number from the output, but not the actual error text, as a result the inline messages contain pointless and redundant path and line number information.

So this is really a request to match error message text in file_regex. I agree this is a very important change, and almost trivial to implement.

0 Likes

#3

Actually, file_regex allows you to capture four pieces of information from an output line: file, line, column and error text, so this is already possible.

For example, the C++\C++ Single File.sublime-build system includes this one for capturing the output of g++:

    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",

An example of it in operation:

That said, depending on the output of the build system itself, it may be tricky to come up with a regex that captures all of the data (e.g. if it doesn’t appear on the same line), which is an issue unto itself.

1 Like

#4

Wow… if only that were documented somewhere, or at least somewhere I would find it. Thanks for that!

If it really was that hard to lex the output it would be pretty easy to write a pre-processor. I already have a grep on the output of Apple’s amazingly verbose Swift compiler.

Edit: It’s documented here: http://sublimetext.info/docs/en/reference/build_systems.html

0 Likes

#6

It’s mentioned in this page of the Unofficial Documentation which, if you haven’t read it, is definitely worth a look-see. It fills the gaps in the official documentation pretty well, I find. I think it’s my most used bookmark. :slightly_smiling:

0 Likes

#7

You just beat me to it.

I actually did read it when I wrote my build system fields, many moons ago, but I only needed the first two fields since column isn’t output and I don’t know if error message was added more recently or if I just ignored it becuase it wasn’t used anywhere at the time.

0 Likes

#8

I think error messages were shown on the status bar when traversing the build results with F4 (and shift+f4), but yeah, they were effectively a non-factor before inline error display.

0 Likes

#9

They do get shown on the status line! But then disappear after a few seconds.

0 Likes

#10

So, I just saw on the blog page (https://sublimetext.com/blog/) that inline error support got enabled in build 3124. I have build 3126, so technically it should be working for me except that its not. I ran my regex through a regex checker. It says in the blog that this new Phantom API functionality is accessible through a plugin, so maybe I need the right plugin. If you got it to work for C, did you use a plugin and if so which one?

0 Likes

#11

The result I posted above is from a build system that ships with Sublime itself, so it just works, no extra plugin needed.

Not all of the build systems that ship with Sublime support this particular option, though. For example, the default Python build system doesn’t support it, likely due to the way that the error message appears a couple of lines away from the line where the error file is reported.

The show_errors_inline setting needs to be turned on for this to work, although it’s enabled by default so that is probably not the issue.

0 Likes

#12

I got this to work on a single line without any additional plugins using the following regex:

"^[ ]*\"(.*?)\", line ([0-9]*)():(.*):"

This puts the error number inline error #20.

My ultimate goal however is to have the actual error text. This is complicated by the fact that its a multi-line error message. Below is an example of this error message and the regex I tried with it but unsuccessfully. It puts a single space instead of the error message, but seems to work fine in regexpal.

"file_regex": "^[ ]*\"(.*?)\", line ([0-9]*)():.*:[ \r\n]+(.*)"
----------------------- start ------------------------------
"C:\Users\myself\my_view_my_code\MY_CODE\My_Libs\libraries\sub_libs\source\SomeSource.c", line 241: error #20: 


          identifier "bytes_written" is undefined


          bytes_written = fwrite(pData, 1U, fsize, pFileWrite);


          ^





---------------------------------- end --------------------------------
0 Likes

#13

Yes. I never had to tweak the show_errors_inline setting – it was enabled.

0 Likes

#14

You might try experimenting with a (?s) prefix which causes regex to match newlines with the dot operator.

So

"file_regex": "(?s)^[ ]*\"(.*?)\", line ([0-9]*)():.*:[ \r\n]+(.*)\^"

should return a multiline error message. Note that I added the trailing caret to terminate the matching according to your example.

0 Likes

#15

Remember to double-escape your backslashes because the regular expression is inside a JSON string.

1 Like

#16

Is there a simple way to make the inline error appear at the end of the line of the error instead of below? IN my case I have no column information.

I’m guessing I’m going to have to hack my theme file.

0 Likes

#17

For those interested in how to do this, you can do a quick and dirty hack to your exec.py file:

  • change line 438 to sublime.Region(view.line(pt).end(), view.line(pt).end()),
  • change line 444 to sublime.LAYOUT_INLINE,

I also changed the phantomCss key in my theme file so that the inline errors looked the way I wanted them to, in particular I added display: inline; to div.error so that the inline fit within the source line.

0 Likes

#18

This seems to rely on the error string containing the information in a certain order. How do you handle error messages that contain the information in a different order? Or that have a different format depending on whether it’s a warning or an error?

0 Likes

#19

The obvious solution would be using named groups, but is anyone actually having this problem?

0 Likes

#20

You either translate the error messages to something that build results regexps can work with, or you don’t.
What I’m saying is that you need a custom build system and modify the output from your executable. I’m doing this in CSScheme.

Related:

1 Like

#21

Yes, I am having this problem with a particular hardware simulation tool. A related problem is that the tool in question has at least 3 different formats for error messages, but I’ve managed to work around that one with some regex sophistry.

0 Likes