mattboehm / vim-unstack

Vim plugin for parsing stack traces and opening the files
286 stars 15 forks source link

Feature: unstack from "* #17

Closed elzibubble closed 10 years ago

elzibubble commented 10 years ago

Maybe I'm just being dumb here, but it seems a needless pain to paste a stacktrace into a Vim buffer before unstacking. How about adding a shortcut to read the stack straight out of "* (star buffer, IE clipboard)?

mattboehm commented 10 years ago

Good idea! I'll look into adding an UnstackFromClipboard or UnstackFromRegister command.

mattboehm commented 10 years ago

I added an :UnstackFromClipboard command. let me know if you have any issues with it.

elzibubble commented 10 years ago

Hi Matt, thanks for adding this so fast, amazing! There is a little problem though; I set verbose=15:

line 5: unlet! b:keymap_name
line 6:   if (g:unstack_showsigns)
line 7:     sign define errline text=>> linehl=Error texthl=Error
line 8:     "sign ID's should be unique. If you open a stack trace with 5 levels,
line 9:     "you'd have to wait 5 seconds before opening another or risk signs
line 10:     "colliding.
line 11:     let signId = localtime()
line 12:     let t:unstack_tabId = signId
line 13:     let s:unstack_signs[t:unstack_tabId] = []
line 14:   endif
line 15:   for [filepath, lineno] in a:files
Error detected while processing function unstack#UnstackFromText..unstack#OpenStackTrace:
line   15:
E714: List required
line 16:     execute "edit" filepath
line 17:     "move line with error to top then show 5 lines of context above
line 18:     setl scrolloff=5
line 19:     execute "normal!" lineno."z+"
line 20:     if (g:unstack_showsigns)
line 21:       execute "sign place" signId "line=".lineno "name=errline" "buffer=".bufnr('%')
line 22:       "store the signs so they can be removed later
line 23:       call add(s:unstack_signs[t:unstack_tabId], signId)
line 24:       let signId += 1
line 25:     endif
line 26:     call unstack#SplitWindow()
line 27:   endfor

Here's the stacktrace I'm using, probably not relevant but just in case:

File "/home/lealexis/w/os-nova/nova/tests/compute/test_resource_tracker.py", line 1010, in test_dupe_filter
  self.tracker.update_available_resource(self.context)
File "/home/lealexis/w/os-nova/nova/openstack/common/lockutils.py", line 249, in inner
  return f(*args, **kwargs)
File "/home/lealexis/w/os-nova/nova/compute/resource_tracker.py", line 380, in update_available_resource
  self._update_usage_from_migrations(context, resources, migrations)
File "/home/lealexis/w/os-nova/nova/compute/resource_tracker.py", line 618, in _update_usage_from_migrations
  if not self._instance_in_resize_state(instance):
File "/home/lealexis/w/os-nova/nova/compute/resource_tracker.py", line 95, in decorated_function
  args[ix] = _load_instance(args[ix])
File "/home/lealexis/w/os-nova/nova/compute/resource_tracker.py", line 84, in _load_instance
  expected_attrs=metas)
File "/home/lealexis/w/os-nova/nova/objects/instance.py", line 260, in _from_db_object
  instance['metadata'] = utils.instance_meta(db_inst)
File "/home/lealexis/w/os-nova/nova/utils.py", line 893, in instance_meta
  return metadata_to_dict(instance['metadata'])
File "/home/lealexis/w/os-nova/nova/utils.py", line 876, in metadata_to_dict
  for item in metadata:
mattboehm commented 10 years ago

I'll look into it

mattboehm commented 10 years ago

This error got thrown because unstack did not find any files in the text in your clipboard, but when I copied the text above, it worked fine. My guess is that the text was not copied to your system clipboard properly. To see what's in your clipboard you can hit "+p to paste its contents.

If you're using the stock vim provided with most linux distros, it probably wasn't compiled with clipboard support. You can test this by running :version and seeing if it says +clipboard (good) or -clipboard (bad). If you don't have clipboard support, the easiest way to fix this is to install vim-gtk with aptitude/yum.

In the meantime, I improved the error message that gets displayed.

elzibubble commented 10 years ago

Oops, I was trying to ":UnstackFromText @" rather than ":call unstack#UnstackFromText(@)". All sorted now, thanks again.

mattboehm commented 10 years ago

Ah gotcha. I think I made some mistakes in the documentation of this new feature and will reopen this to remind myself to fix them.

mattboehm commented 10 years ago

I fixed the bug with :UnstackFromText (so now :UnstackFromText @* works) and also added a command called :UnstackFromSelection that does this as well.

elzibubble commented 10 years ago

Thanks Matt! Very convenient.