Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'show build results only on a failed build' feature #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jonwingfield
Copy link

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.


if build_finished:
errors = self.output_view.find('Error', 0)
if errors == None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at Packages/Default/exec.py, a more robust way to do the error check would be:

errs = self.output_view.find_all_results()
if len(errs) == 0:

@jwheare
Copy link

jwheare commented Oct 30, 2012

Also from the looks of exec.py, it looks like there are on_finished events you may be able to hook into now.

@jonwingfield
Copy link
Author

@jwheare Thanks. It's been a while since I've touched this, but I'll have a look in a bit.

@gregglind
Copy link

I would like this feature as well!

@LeonB
Copy link

LeonB commented Dec 6, 2012

Would be awesome!

@albertosantini
Copy link

(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.

@niksy
Copy link

niksy commented Aug 21, 2013

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.

@albertosantini
Copy link

@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

@albertosantini
Copy link

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})

@alexnj
Copy link
Owner

alexnj commented Feb 8, 2015

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. 🙏

@albertosantini
Copy link

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.

@albertosantini
Copy link

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.

@alexnj
Copy link
Owner

alexnj commented Feb 8, 2015

@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.

@albertosantini
Copy link

@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.

@albertosantini
Copy link

In ST3 3070 on_post_window_command issue is fixed.

From the changelog:

API: Fixed on_post_window_command() not getting called

@thomasklein
Copy link

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.

@stealzy
Copy link

stealzy commented Nov 12, 2015

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.

if build_finished:
errors = self.output_view.find('Error', 0)
if errors == None:
view.window().run_command("hide_panel", {"panel": "output.exec"})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I believe the panel argument to hide_panel is a no-op, unlike to its sibling show_panel. I just tried it out in ST2 and ST3 with the 'find' panel open; the above hide_panel call would still close the find panel even though the output.exec panel was specified. Seems https://sublimetext.userecho.com/topics/1930-add-panel-param-to-hide_panel-command/ is still open. @wbond, correct?

@JeremyBernier
Copy link

Can we get this feature implemented?

@stevenvachon
Copy link

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.