Home Download Buy Blog Forum Support

Mouse clicking a console line and jumping to file

Mouse clicking a console line and jumping to file

Postby Scam on Wed Oct 30, 2013 4:18 pm

I am interested in creating a kind of stack trace functionality to console. My system uses TCP to communicate with server (a sort rapid development environment). All output from server is printed to console. If I send a code that is not working the server returns a stack trace, which is one or more lines with the following syntax: <filename>:<row_number>: <error message> What I'd like to do is double-click that line, parse file name and row number, and then jump to that file and row.

Is this kind of functionality possible to implement? If it is, I would like to have some pointers where and how I should start. Probably I need to edit sublime-mousemap and do some regex magic?
Scam
 
Posts: 12
Joined: Fri Oct 25, 2013 1:15 pm

Re: Mouse clicking a console line and jumping to file

Postby lunixbochs on Thu Oct 31, 2013 5:14 am

This is definitely doable. Sublime Text already does something similar with the Find Results page.

Remember, the console is just a view that you can easily show/hide. It's the default debug output of pretty much everything and a bit overloaded. You might consider using a view for this instead of a console:

Code: Select all
output = sublime.active_window().new_file()
output.set_read_only(True)
output.set_scratch(True)
output.set_name('Server Output View')
output.settings().set('server_output', True)


By setting an arbitrary setting like 'server_output' to True on your output view, you can check if the current view has this setting when determining whether to act on an event.

You can easily insert text into this output view using my Edit class:

Code: Select all
from .edit import Edit
with Edit(output) as edit:
    edit.append('new line of stuff\n')


I implemented a double-click action in SublimeXiki:
Plugin Code
sublime-mousemap

It manages to not break double-click-drag using a bit of hackery.
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm

Re: Mouse clicking a console line and jumping to file

Postby Scam on Thu Nov 07, 2013 3:21 pm

Thanks for your answer lunixbochs! I implemented the functionality discussed above and I am using Edit class to show the output in a view.

Now I've run into another problem. When I am printing enough lines to output view the plugin_host.exe crashes. Whenever I append text to output view the memory consumption of the plugin_host.exe increases but I do not have any way to release it. Erasing the whole text or shutting down the view does not release the memory thus after running my plugin some time it eventually crashes sooner or later.

Have you experienced this behavior and if, do you have any solution for this?
Scam
 
Posts: 12
Joined: Fri Oct 25, 2013 1:15 pm

Re: Mouse clicking a console line and jumping to file

Postby lunixbochs on Fri Nov 08, 2013 10:46 pm

How many lines are you talking?

I see it too if I use SublimeXiki and just print hundreds of thousands of lines.

It looks like this is not a memory leak on the Python side. According to the gc module, I'm not getting past 512 objects before it collects down to 12 or so. I'll see if I have any obvious leaks of internal Sublime objects.
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm

Re: Mouse clicking a console line and jumping to file

Postby lunixbochs on Fri Nov 08, 2013 10:53 pm

I made this dummy TextCommand:
Code: Select all
import sublime
import sublime_plugin


class DummyCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        view = self.view
        if view.size() > 1024:
            view.erase(edit, sublime.Region(0, view.size()))
        view.insert(edit, 0, 'ajklsdf\n' * 5)


and ran it a ton by running this many times in the console:
Code: Select all
exec("for i in range(10000):\n\tview.run_command('dummy')")

My plugin_host memory usage is now over 500mb from a fresh Sublime start. gc.get_count() is reliably between 0-512.

Smells like a leak in plugin_host to me. The OS X `leaks` command shows me a ton of 528-byte structs in the heap with data like this: http://bochs.info/p/bpczg

This is on OS X 10.9 (Mavericks) with build 3047.
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm

Re: Mouse clicking a console line and jumping to file

Postby sapphirehamster on Sat Nov 09, 2013 12:09 am

lunixbochs wrote:I made this dummy TextCommand:

Smells like a leak in plugin_host to me. The OS X `leaks` command shows me a ton of 528-byte structs in the heap with data like this: http://bochs.info/p/bpczg

This is on OS X 10.9 (Mavericks) with build 3047.


I'm not getting a leak with your sample command. I am on build 3054, maybe try upgrading?
sapphirehamster
 
Posts: 83
Joined: Sun Jul 01, 2012 11:19 pm

Re: Mouse clicking a console line and jumping to file

Postby lunixbochs on Sat Nov 09, 2013 5:30 am

I still see a leak in 3054, and I noticed it's matched by the Sublime Text process.

I see the same 528-byte sections in plugin_host: http://bochs.info/p/wkq6z
I see this leak pattern in Sublime Text itself: http://bochs.info/p/j5qtr
lunixbochs
 
Posts: 91
Joined: Fri Oct 08, 2010 10:18 pm

Re: Mouse clicking a console line and jumping to file

Postby sapphirehamster on Sat Nov 09, 2013 10:11 pm

lunixbochs wrote:I still see a leak in 3054, and I noticed it's matched by the Sublime Text process.


Ah, sorry, for some reason I didn't see it increase in size in Activity Monitor, but now I clearly do. I probably just wasn't waiting long enough for it to update the display (didn't realize the default was 5 seconds). I would expect a small increase in the sublime process size to contain the undo information, but the memory is never released. Looks clearly like a bug in sublime.
sapphirehamster
 
Posts: 83
Joined: Sun Jul 01, 2012 11:19 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 9 guests