Sublime Forum

Not able to show errors messages inline for my custom build system

#1

Hi, I would like improve my build system to display the errors messages inline on the file, when user click in the error message in the results console, using Phantom API, as showed in the post: https://www.sublimetext.com/blog/articles/sublime-text-3-build-3124
But for now it is not working. It’s open a new file with name ‘C’ and display all error messages on it.
So, I almost sure that my error is my regex expressions for “file_regex” and “line_regex”.
Here is a example of the result message when I run the build command:

C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5 : information: Checking 'TradeControl.mq5' C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(25,5) : error 256: 'abc' - undeclared identifier C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(27,4) : error 152: 'OrdersPrev' - some operator expected C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(88,16) : warning 43: possible loss of data due to type conversion C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(96,22) : warning 43: possible loss of data due to type conversion C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(147,22) : warning 43: possible loss of data due to type conversion C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(202,22) : warning 43: possible loss of data due to type conversion : information: Result 2 error(s), 4 warning(s) [Finished in 2.7s]

There is typically 3 types of messages: information, warning and error.
The (25,5), for example, is the line and columm for the error “‘abc’ - undeclared identifier”.
And here is my build file:

{ "selector": "source.mq5", "cmd": ["C:\\Users\\User\\AppData\\Roaming\\Sublime Text 3\\Packages\\User\\sublime_mql5\\makeMQL5.bat", "$file_path", "$file_base_name", "$file_extension"], "file_regex": "^(...*?)", "line_regex": "^(...*?) : error", "working_dir": "$file_path", "variants": [ { "name": "Syntax Check", "cmd": ["C:\\Users\\User\\AppData\\Roaming\\Sublime Text 3\\Packages\\User\\sublime_mql5\\checkMQL5.bat", "$file_path", "$file_base_name", "$file_extension"] } ] }

So, how can I get the file name and line error correctly?
Thank you.

0 Likes

#2

Properly write a regex to catch the desired information using Capture Groups.

See the http://www.rexegg.com/regex-quickstart.html table for properly know the regex identifiers.
Also see the default Sublime Text Built-in regex’es files on the default build systems to start learning.

For you case, this regex should work: https://regex101.com/r/V3FhML/1

    ^.*\((\d*),(\d*)\)\s*:\s*(.*)

If does not work, you may play/fix it on the link just above.
See also the explanation on the link:

0 Likes

Build New Syntax Highlight
#3

Hi @addons_zz. I changed the regex expression in my build file, but it still open and show the errors messages in a new file, instead of inline in the file pointed by the error.
Anything else that I need to do?

0 Likes

#4

I do not understando what does this mean. The regex I provided is to parse the error output you show here:

C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5 : information: Checking 'TradeControl.mq5'
C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(25,5) : error 256: 'abc' - undeclared identifier
C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(27,4) : error 152: 'OrdersPrev' - some operator expected
C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(88,16) : warning 43: possible loss of data due to type conversion
C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(96,22) : warning 43: possible loss of data due to type conversion
C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(147,22) : warning 43: possible loss of data due to type conversion
C:\Users\User\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\TradeControl.mq5(202,22) : warning 43: possible loss of data due to type conversion
: information: Result 2 error(s), 4 warning(s)
[Finished in 2.7s]

Anyways I actually forgot the capture the file name. Learn by yourself how to do it:

  1. https://www.google.com/search?q=regex+tutorial
  2. https://regex101.com/r/V3FhML/1
  3. https://www.google.com/search?q=sublime+build+system+file_regex+tutorial
  4. http://stackoverflow.com/questions/17407895/how-to-configure-sublimes-build-system-to-capture-file-and-line-from-such-error
  5. http://sublime-text-unofficial-documentation.readthedocs.io/en/stable/reference/build_systems.html
  6. http://docs.sublimetext.info/en/latest/reference/build_systems.html
  7. http://docs.sublimetext.info/en/latest/file_processing/build_systems.html
  8. http://www.rexegg.com/regex-quickstart.html
0 Likes

#5

Thank you @addons_zz.
I’m able to display the messages now. I changed the regex and now the file name is matching.
"file_regex": "^.*(^.*)\\((\\d*),(\\d*)\\)\\s*:\\s*(.*)", "line_regex": "^.*\\((\\d*),(\\d*)\\)\\s*:\\s*(.*)",

I have 3 more questions:
How to configure to display messages box inline with different colors in the file?
Is possible to display custom output messages with “color under-line” (error, warning, info), like the image bellow?
Is possible the user configure the level of information that is displayed in the result build process message, like “only errors”, “errors and warnings” and “all”?

0 Likes

#6

Sorry, I do not know anything about colors with my experience for now.

Do you want the error, warning etc get colored?
For the build output panel you may write your own sublime-syntax and to apply them when on the build panel text. But to get colored the inline error phantom I do not now how. May be it is configurable by the theme file or syntax file. If not them you may open a feature request on the Sublime Text Core issues:

  1. https://github.com/SublimeTextIssues/Core/issues
0 Likes

#7

The phantoms used for build errors are applied by Packages/Default/exec.py and they don’t look to be configurable, at least at the level where there could be multiple colors used. So in all likelihood you would need to have an enhanced version of exec.py that applies a slightly different style depending on the status of the message.

As @addons_zz mentioned, your build system can specify a syntax to use to highlight the build output (the default is Packages/Default/Plain text.tmLanguage). I’m not familiar enough with syntax highlighting to know if it’s capable of applying underlines instead of just colors, but assuming it is not I think you would also need some custom code to apply the appropriate region status to the affected areas (the syntax could apply a scope and then the code would just apply regions to the scopes).

The same exec.py as above is what is used to execute the build command, so you would probably want it to also apply the regions as needed after the build is completed, while the phantoms are being inserted into the code.

As defined in exec.py, the build results panel displays only what the build command outputs, so in order to get it to display only certain kinds of messages, you would either have to modify whatever you use to build to do that, or you would need to add extra handling to it to do that sort of filtering for you. Making Sublime do it would be complicated by the fact that every build system can output different things in different ways, though.

3 Likes

#8

Imo it would be reasonable to have three different types of output results (error, warning, info) and a pair of file and line regex matches for each. Then color them differently.

I was just asked yesterday on IRC whether it was possible to only browse to errors with F4 (and not warnings). Granted, there are higher priorities.

4 Likes

Is there a way to adjust output console's result?