Sublime Forum

Mouse clicking a console line and jumping to file

#1

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: :<row_number>: 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?

0 Likes

#2

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:

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:

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.

0 Likes

#3

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?

0 Likes

#4

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.

0 Likes

#5

I made this dummy TextCommand:

[code]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)[/code]

and ran it a ton by running this many times in the console:

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: bochs.info/p/bpczg

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

0 Likes

#6

[quote=“lunixbochs”]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: bochs.info/p/bpczg

This is on OS X 10.9 (Mavericks) with build 3047.[/quote]

I’m not getting a leak with your sample command. I am on build 3054, maybe try upgrading?

0 Likes

#7

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: bochs.info/p/wkq6z
I see this leak pattern in Sublime Text itself: bochs.info/p/j5qtr

0 Likes

#8

[quote=“lunixbochs”]I still see a leak in 3054, and I noticed it’s matched by the Sublime Text process.
[/quote]

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.

0 Likes