Smarter JavaScript code completion?

Is there a way to get smarter code completion in IntelliJ IDEA 10? Review the attached file. Even though the variable myVar currently contains a string, the autocompletion suggests methods for other types (like boolean, number and array). IDEA also give me suggestions from libraries I don't use (like Prototype.js).
I'd like the IDE to give me relevant options - a list of 289 suggestions (where most of them will generate an error) really don't help ... Is there a way to change this?
Martin



Attachment(s):
Screen shot 2011-01-03 at 16.48.15.png
0
9 comments

Usually pressing Control + Shift + Space gives less variants
Also check out configuring javascript libraries blog post
http://blogs.jetbrains.com/idea/2010/11/javascript-libraries-in-intellij-idea-10/
, we are especially interested in your feedback in this area

On 03.01.2011 19:05, Martin Lundgren wrote:

Is there a way to get smarter code completion in IntelliJ IDEA 10? Review the attached file. Even though the variable myVar currently contains a string, the autocompletion suggests methods for other types (like boolean, number and array). IDEA also give me suggestions from libraries I don't use (like Prototype.js).
I'd like the IDE to give me relevant options - a list of 289 suggestions (where most of them will generate an error) really don't help ... Is there a way to change this?
Martin

>

---
Original message URL: http://devnet.jetbrains.net/message/5282276#5282276



--
Best regards,
   Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Martin,
by default JavaScript completion works from all files under your project root because there is no explicit indication in JavaScript which library is actually required.  So if your prototype.js library is under the project root, it will be used in completion automatically. To avoid this you may create a library out of Prototoype.js. This will exlude it from completion except those .js files for which it is explictitely specified in library usage scope (Settings/JavaScript/Libraries/Usage Scope). I hope it helps.

0
Avatar
Permanently deleted user

Hello Rustam,
I added a new (empty) module 'js-completion' and selected that in the JS settings as you suggested. Unfortunately it didn't change a thing ... I still get suggestions for Prototype.js etc.
Martin

0

Martin,
I'm afraid you misunderstood me. You need to create a library containing Prototype.js. Go to Project Structure,  select Global Libraries, add a JavaScript library, attach debug and release versions of Prototype.js and click Apply. This will tell Idea that Prototype.js is not just some project file, it's a part of a JavaScript library and therefore shouldn't be used in completion by default.

0
Avatar
Permanently deleted user

Hi Maxim,

Thank you for your answer. I don't think [Ctrl] + [Alt] + [Space] made much of a difference. But maybe it's because I'm on OSX? What is it supposed to do?

I think a more restrictive and accurate list would be prefferable. The setting mentioned by Rustam below is a good feature, but it would be nice if you had the option of 'current file only' or a detailed list over stuff that you want included. It's not offen you want all the other stuff.

I understand it must be more difficult providing acurate info for a loosly typed language like JS, but surly some sort of type checking can be done, right? Something like:
var myVar = 0;
// Later ...
myVar = 'some text';
myVar.
... and then show suggestions for strings rather then numbers. That together with the library directory thing you have would be super!

Martin

0
Avatar
Permanently deleted user

Ok. To me it sounds a bit back words to create a library to exclude the code from code-completion, but I'm going to give it a shot.
Thank you!

0

Martin,
if you have any ideas how to make it better, I'd suggest to submit a feature request (or requests) at http://youtrack.jetbrains.net because that's what eventually drives our development. Thanks for your feedback!

0
Avatar
Permanently deleted user

I tried adding my prototype.js as an external library, but that didn't stop it from showing up in my code-completion options...
Is there another way? Also, is there a way get Idea to understand the type of the variable and display only that?

I've now filed an Issue with improvement suggestions in your YouTrack system.
http://youtrack.jetbrains.net/issue/IDEA-64183?projectKey=IDEA

Martin

0

Please make sure that your prototype library is under "Global libraries". I have attached here a sample screenshot. This really should work.
Another way is just to keep the library out of project scope and attach it to global libraries from a non-project directory but I'm not sure it's a feasible solution for you.



Attachment(s):
js_lib_sample.png
0

Please sign in to leave a comment.