SublimeOnSaveBuild
SublimeOnSaveBuild copied to clipboard
Add 'show build results only on a failed build' feature
This was a request from Issue #1 that I went ahead and implemented.
One decision I made was to not show the build output at all if the build was successful. I'm not sure if this is ideal, and would be happy to do the reverse (hide the window once the build succeeds).
Feel free to complain and tell me to rewrite, change, etc.
Also from the looks of exec.py, it looks like there are on_finished events you may be able to hook into now.
@jwheare Thanks. It's been a while since I've touched this, but I'll have a look in a bit.
I would like this feature as well!
Would be awesome!
(In ST3) I tried
def post_window_command(self, window, command_name, args):
# print(command_name, args)
if command_name == 'build':
output_panel = window.get_output_panel('exec')
errs = output_panel.find_all_results()
# print('Errors: ' + str(len(errs)))
if len(errs) == 0:
output_panel.run_command('hide_panel', {'panel': 'output.exec'})
but it seems the event is not called.
on_window_command
is called, but it is too early.
I’ve managed to get this working by setting errors = self.output_view.find('Error', 0, sublime.IGNORECASE)
, but can this be placed inside main repository? This functionality is really useful.
@niksy The problem is not to check if there are errors, but the event, on_post_text_command
, is not called.
See also Sublime Text forum: Post command event listener - http://www.sublimetext.com/forum/viewtopic.php?f=6&t=13780
I resolved with the following snippet (for instance, Packges/User/z.py
):
import Default
class ExecCommand(Default.exec.ExecCommand):
def on_finished(self, proc):
super(ExecCommand, self).on_finished(proc)
errs = self.output_view.find_all_results()
if len(errs) == 0:
self.window.run_command("hide_panel", {"cancel": True})
Trying to knock this down with some free time at hand. I've based on @albertosantini's snippet and tried to build this feature based on exit code, at branch SublimeOnSaveBuild/autohide. Would one of you be able to pull the branch and see if it works for you?
PS: Apologies for not being able to spend much time on this project in the past. Hope to provide it better care in future. :pray:
Thanks for the branch.
I tested it, but the exit code is not enough (at least in my use cases).
import Default
class ExecCommand(Default.exec.ExecCommand):
def on_finished(self, proc):
super(ExecCommand, self).on_finished(proc)
exit_code = proc.exit_code()
errors_len = len(self.output_view.find_all_results())
if (exit_code != None and exit_code != 0) or errors_len > 0:
self.window.run_command("show_panel", {"panel": "output.exec"})
else:
self.window.run_command("hide_panel", {"panel": "output.exec"})
I added a test if it is displayed some error in the output view.
Another thought.
There are build systems with no errors, but the user wants the output panel opened. What if in this case?
Indeed in Build Next plugin I added a preference per build system.
@albertosantini, I'm curious to know if you are able to get any output from the function self.output_view.find_all_results()
. In my tests, under both OSX and Windows, this function returns an empty array every time. I tested by directing output to both stdout
and stderr
, but no luck. I plugged in a print(errs)
to Default/exec.py
, and surprised to see the same results — an empty array for a build that's failed with error messages.
Other than the reference to this function in the bundled exec.py
(which doesn't seem to have any effect at the moment), I could not find any documentation on what to expect out of this function. I'm looking forward to hearing how this function is working for you.
@alexnj for instance, a few details using an eslint build.
I added in the snippet above the following lines:
...
print(exit_code)
print(self.output_view.find_all_results())
...
The messages in the console:
Running eslint.cmd --format compact C:\My\Dev\snippets\000\p.js
None
[('/C/My/Dev/snippets/000/p.js', 17, 47)]
The build output:
C:\My\Dev\snippets\000\p.js: line 17, col 47, Error - Missing semicolon. (semi)
1 problem
[Finished in 0.5s with exit code 1]
[cmd: ['eslint.cmd', '--format', 'compact', 'C:\\My\\Dev\\snippets\\000\\p.js']]
...
This is eslint build:
{
"selector": "source.js",
"cmd": ["eslint", "--format", "compact", "$file"],
"shell": true,
"file_regex": "^(.*): line (\\d+), col (\\d+), (.+)$",
"windows":
{
"cmd": ["eslint.cmd", "--format", "compact", "$file"]
},
"env":
{
"ST_BUILD_ADJUST_COLUMNERROR": "1"
}
}
Please, ignore ST_BUILD_ADJUST_COLUMNERROR
env.
You need to install node and eslint to reproduce the context.
Notice the exit code of the command is 1, but exit code in the snippet is None.
In ST3 3070 on_post_window_command issue is fixed.
From the changelog:
API: Fixed on_post_window_command() not getting called
Hi guys, I would find this option also very useful. Any progress on this?
My use case: I have a Jade->HTML build system. I would only want to see resulting log on error.
I found, that exit code not always match with real. I wish use stdout for analyze. Is there a simple way to get content of the build panel into variable? https://github.com/rctay/sublime-text-2-buildview - it can, but I don't understand how.
Can we get this feature implemented?
...