ternjs / tern_for_sublime

Sublime Text package adding Tern support
MIT License
803 stars 54 forks source link

"Jump to definition" does not work with RequireJS modules #28

Closed OliverJAsh closed 10 years ago

OliverJAsh commented 10 years ago

I am using the RequireJS plugin that comes with Tern. Although autocomplete is working for AMD dependencies, I cannot jump to the AMD definition. It simply takes me to the function parameter that references the dependency in the current module.

Not sure if this is an issue with this package or something more. Please advise.

marijnh commented 10 years ago

That is how jump-to-def always works for local variables -- it takes you to the variable's definition. In this case, the parameter. I guess there's a case to be made for having a mode where it tries to go to the definition of the type of the variable, but that doesn't always apply (and as far as most of Tern is concerned, the arguments to a define or requirejs call body are normal parameters).

OliverJAsh commented 10 years ago

That makes sense. Just realised that jump-to-def will work if your AMD module is an object with properties defined on it. When you jump to those, then it will take you to the AMD definition.

I half expected it to take me to the AMD definition when using jump-to-def on the function parameter, but I understand why it doesn't. Is there any other way this could be achieved?

Thanks for your amazing work.

marijnh commented 10 years ago

If you remove the if (!span) part on line 691 in lib/tern.js, it'll behave the way you want in this situation—but it'll behave badly in other situations, so I don't want to simply make that change. You could add an option to the definition request that puts it into this mode (prefer the type's location over the variable's location), and add a binding in the sublime plugin that looks for a definition using this mode.

OliverJAsh commented 10 years ago

I don't think I'm going to add this feature seeing as I now realise how it's supposed to work, but thanks for explaining. :-)