user6033608
user6033608

Reputation: 93

How to match line & error in Sublime Text 3?

How can I match this error in the build with regex to locate line and file with result_line_regex & result_file_regex?

project4.dpr(9) Hint: H2164 Variable 'I' is declared but never used in 'Project3'

I have tried this but it won't work.

    "result_file_regex": "^.*\\(.*)/.?(.*)$",
    "result_line_regex": "^([^\\]*)\.(\w+)$",

Upvotes: 4

Views: 840

Answers (1)

Simon Hänisch
Simon Hänisch

Reputation: 4968

As already mentioned in the comments, file_regex is the setting that gets passed to result_line_regex (have a look at the run() method signature of class ExecCommand in Packages/Default/exec.py).

A good regex in your case would be ^([\w-]+\.\w+)\((\d+)\). The first group captures something like my-file.ext and the second one the digit(s) in parentheses.

In order to set that expression in a string in the json file you need to escape each backslash with another backslash (\ is the escape character in strings), so it becomes:

"file_regex": "^([\\w-]+\\.\\w+)\\((\\d+)\\)"

Notice that the matched file has to be in the path of the file that is active when triggering the build system. If you want it to be relative to a certain path no matter where you trigger the build, you can also pass a working directory like:

"working_dir": "/path/to/my/source"

This will be set as result_base_dir in the output view.

Upvotes: 2

Related Questions