Possible enhancement to JavaScript support JB?

I was just wondering if it would be possible to implement the Find Usages and GoTo Declaration functionality for JavaScript variables?

Basically I would like to be able to CTRL-B on a JavaScript variable and go to the point in my code where it was first declared. I also would like to be able to click on a variable from anywhere in the code (or even just from the declaration line) to show me everywhere that variable has been used.

I'm not sure if I am just missing this functionality and it is there but its something I have been looking for.

6 comments

By the way, I forgot to mention. I realse these things are on the features list for 5.0 but for some reason I don't seem to be able to get them to work.

I guess what I'm really asking is if they are broken or not.

0

Ctrl+B and find usages only works for those variables indeed defined with
var statement like

var x;
x = 4;


"Lazy" definition is not supported

-


Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

By the way, I forgot to mention. I realse these things are on the
features list for 5.0 but for some reason I don't seem to be able to
get them to work.

I guess what I'm really asking is if they are broken or not.



0

Just ignore me. For some reason it is now working. I've been trying to use it for three days now on one project and I just tried creating a dummy project and putting in a few variables and it works. Must've been a bug in my project.

One thing I did notice though was that it marks the code below as a duplicate declaration:

var test;
function test(){}

Shouldn't IDEA know the difference between a variable declaration and a function one?

0

Rob Bradley wrote:

Just ignore me. For some reason it is now working. I've been trying to use it for three days now on one project and I just tried creating a dummy project and putting in a few variables and it works. Must've been a bug in my project.

One thing I did notice though was that it marks the code below as a duplicate declaration:

var test;
function test(){}

Shouldn't IDEA know the difference between a variable declaration and a function one?


There is no difference in Javascript between a function declaration and a
variable declaration. Functions are objects, which are stored in variables like
any other object.

0

The Javascript Find Usages and Goto Declaration is very
limited in current form. Find Usages only shows usages
within the same file (JSP, JS, HTML). It won't show
usages of a function called from javascript in another file,
e.g. a JSP or HTML calling a javascript function defined in
library.js file.

In a JSP file, if you attempt Find Usages on a name of a
javascript function, it gives you an error message.

Here are some bugs already filed on the limited Javascript
Find Usages support. Add your vote...

IDEADEV-832 Find usage doesn't work between javascript and xhtml files
http://www.jetbrains.net/jira/browse/IDEADEV-832

http://www.jetbrains.net/jira/browse/IDEADEV-2353
IDEADEV-2353 Javascript Find Usages problem

IDEA-4312 JavaScript context is way too limited
http://www.jetbrains.net/jira/browse/IDEA-4312


My own example. I have a javascript function activateTab()
defined in library.js.

Then in a JSP file I refer to the activateTab() in two places:

#1 within head content
function activateFirstTab() { var tabs = document.getElementsByName("anchorTab"); var firstTab = tabs[0]; activateTab(firstTab); window.top.bsmcontent.location.replace(firstTab.href); } #2 within body content ]]>


If I goto library.js and invoke Find Usages on the activeTab
function, it will not show me these usages in my JSP file.

Considering that JetBrains is listing "Full-spectrum HTML, CSS
and JavaScript at your fingertips" as their #1 reason to upgrade
on http://www.jetbrains.com/idea/upgrade/top_reasons.html, the
Javascript support should be more complete and functional.

As it stands today, I continue my 4.5 habit of using Find In Path
search to find all usages of a javascript function. This habit
has actually been reinforced by 5.0 because Find In Path is so
damn fast (if you check words only). Almost instantaneous results
for about 750k locs.



0

Thanks Alex, I have added my votes and will be watching these issues. The JS functionality is fundamental to the projects I am currently working on, it was the main reason I could persuade my new company to let me continue using IDEA instead of their standard VS.NET environment.

0

Please sign in to leave a comment.