How to capture the goto declaration event?


#1

The goto declaration for PHP doesn’t really works, so is there a way to capture that event and handle it by my package?
I mean like when the user clicks goto declaration my callback should be executed and the file it gives should be opened along with the line number and character reference.


#2

@steelbrain I had had a little search around, I think the event that is triggered when you click goto declaration is symbols-view:go-to-declaration, which is defined in the symbols-view package here. Have you already got a package you want to plug this into?

As a rough stab you could subscribe to that event with a callback something like

disposable = atom.commands.add 'atom-text-editor',
  'symbols-view:go-to-declaration': ->
    dosomestuff
    return

and then you can call disposable.dispose() when your done listening to the event. Your also need to access the text editor and get the text thats highlighted. I’m not to sure how to go about that but I’m sure its somewhere in TextEditor.

I don’t know what else Atom does with the event, so there could be other callbacks listening competing with yours. You could alternatively add your own context menu option.

I hope thats usefull @steelbrain :smiley:


#3

I think the best reference on the events API is this one.


#4

@Galadirith , thanks for the info :heart:, but that event gives no apparent information about the editor tab, It gives an atom-text-editor react element in e.target, but I am not sure how to use it to get offset and other info :dizzy_face:

Edit: Nevermind, I can use the active editor :laughing:


#5

@steelbrain :smile: Yeh at least as far as I can tell the event will give you none of that info. If you look here, that is where symbols-view listens to the event, and it certainly doesn’t look for any data the event may have.

If you follow the object trail through its code, then you end up in the the tag-reader object. I’m sure you’ve already figured out how to get the offset etc, but if not that source code may be of some help :smile: