The TODO still missing:
class GotoDefinition(sublime_plugin.WindowCommand):
def select_entry(self, locations, idx, orig_view, orig_sel):
if idx >= 0:
self.goto_location(locations[idx])
else:
# TODO: restore sel
if orig_view:
self.window.focus_view(orig_view)
This is my implementation:
def select_entry(self, locations, idx, orig_view, orig_sel):
if idx >= 0:
self.goto_location(locations[idx])
else:
if orig_view:
orig_view.sel().clear()
orig_view.sel().add_all(orig_sel)
self.window.focus_view(orig_view)
orig_view.show(orig_sel[0])
In addition, I’ve modified the run method to highlight by default the second item of the list if the first is the current one.
This way if a symbol appear 2 times in a file, the default highlighted item is not the current one:
[code] def run(self, symbol = None):
…
defindex = 0
if len(locations) > 1:
fname, _, rowcol = locations[0]
if os.path.normpath(fname) == os.path.normpath("\" + v.file_name().replace(":", “”)):
if v.rowcol(v.sel()[0].begin())[0] == rowcol[0]-1:
defindex = 1
if len(locations) == 0:
sublime.status_message("Unable to find " + symbol)
elif len(locations) == 1:
self.goto_location(locations[0])
else:
self.window.show_quick_panel(
[self.format_location(l) for l in locations],
lambda x: self.select_entry(locations, x, v, orig_sel),
selected_index = defindex,
on_highlight = lambda x: self.highlight_entry(locations, x))[/code]
A little bit hacky, as the path returning from lookup_symbol() is not usable out of the box (at least on Windows), you have to convert it manually.
A method in the API to convert lookup_symbol() path to OS path would be useful.
Thanks.