aggsol
aggsol

Reputation: 2490

How to capture output of ninja build system in Sublime Text 3?

I am tring to set up the ninja build system in Sublime Text 3 that is not supported out the box. I generate my ninja.build file with meson. My build system is configured like this:

{
    "cmd": ["ninja", "-C", "$folder/build/"],
    "keyfiles": ["meson.build", "build.ninja"],
    "file_regex": "^../([^:\n]*):([0-9]+)?.([0-9]+)?(.*):? (.*)$",
}

According to the manual I need to capture 2,3, or 4 groups with the Regex. Example error looks like this:

../src/View/Setup.vala:345.36-345.38: error: The name `loc' does not exist in the context of `View.Setup.setup_storage_location._lambda10_'
                storage_location = loc;
                                   ^^^

I can jump with F4 to the error but the file is not opened even the first group is the file. How can I get all 4 groups (file, line, column, message) even though ninja provide start (line, column) and end (line, column) of the error?

Upvotes: 1

Views: 313

Answers (1)

OdatNurd
OdatNurd

Reputation: 22791

In order to capture all of the parts that Sublime supports (file, row/col and message) you need to craft a file_regex that captures just those parts. In this case that means that you need to match (but not capture) the end ranges so that you can pick up the error message on the end.

That regex might look something like this:

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

Based on your output above, that would capture the filename, the first two values as row and column, then match but otherwise ignore the end range location, picking up everything else as the message.

Note also that the filenames in your output are relative filenames, and as a result Sublime will attempt to open them as such. However the current directory may not be what you expect because Sublime's current directory may be different than where your build is executing.

If you're seeing that even with your current regex the file doesn't seem to open (but a tab is created), this is the reason why that's happening.

To solve that problem you either need all filenames that are displayed in errors to be absolute paths, or you need to add the working_dir key to your build system to specify explicitly what the paths are relative to.

An example of that would be something like the following:

    "working_dir": "${folder:${project_path:${file_path}}}",

This sets the working directory to be the first top level folder in the sidebar, falling back to the location where the current project is stored if there are no folders present, and falling back to the path of the current file if there's also no project.

Upvotes: 2

Related Questions