Node.js function metadata for code completion - javascript

So, the core of my problem is that I might not know what the thing I want is called. I think it's called "metadata", but Google doesn't turn up anything.
Anyway when you type a function's name in WebStorm (though I can not imagine this being unique to it) it will sometimes display a tooltip, telling you what the function does and what parameters it takes- this really cuts down the time needed to look stuff up. So, I want to bundle those with the functions I write. How do I do that, or at least what is it properly called?

There isn't one term for it, unfortunately. Microsoft's term is "IntelliSense." Various other terms are listed in this answer on programmers.stackexchange.com:
Auto Code Completion
Code Completion
Code Hinting
Code Assist
I believe the term they use at JetBrains (the people behind WebStorm and IntelliJ and such) is "Code Completion," based on the WebStorm help.
More about WebStorm code completion on their blog. It looks like they'll work from the source code, using JSDoc if they find it.

Related

When hovering/viewing Javascript Documentation in IntelliJ, what are all of the extra symbols?

So I'm trying out IntelliJ and possibly moving away from Eclipse. I see I can hover over Javascript methods and actually see some info, which is great. But how do I find out more about what is being shown to me? In the pic below, what does the "?" mean? Does 'void' mean there is not a 'return' statement?
Is this JSDoc? This is old legacy code, so I know there is not any commenting above the function to give more info, so I'd like to know what's going on here. Is this just IntelliJ extrapolating the function arguments and creating its own interpretation?
I assume there's a guide or legend out there for this. But after searching around for a while I feel like I don't know the right search term to look for. Any help is appreciated.
EDIT: We don't use TypeScript at all in our current app.
Quick documentation is mostly based on comments in code. In this case the information comes from bundled definition files (In this case, a d.ts file which is a TypeScript type defintion file). For the methods defined in the project or in its dependencies, IDEA shows information from the JSDoc comments attached to functions.
Looks as if the function is defined in a d.ts file, because explicit type declarations are used, so ? indicates optional parameter, and void means that the function is not returning a value.

Re-creating a websites javascript function to be used as a stand alone alternative in tampermonkey

I'm looking for a way to do something that may or may not be possible.
On the site http://hitbox.tv/ there is a javascript function I believe that turns text into images.
For example, using:
emotify.emoticons("",{
"emote": ["http://example.com/emote.png", "channel"],
});
in a tampermonkey script or entering it directly into the chrome console would allow all occurrences of "emote" in the chat to be turned into that image.
If I type "emotify" into the chrome console, I'm given:
function (e,f){return f=f||function(h,j,g){return j=(j+", "+g).replace(/"/g,""").replace(/</g,"<"),'<img src="'+h+'" title="'+j+'" alt="" class="smiley"/>'},e.replace(b,function(j,g,m){var k=0,h=m,l=c[m];if(!l){for(;k<d.length&&!d[k].regexp.test(m);)k++;h=d[k].name,l=c[h]}return l?g+f(l[0],l[1],h,m):j})}
and if I type in "emotify.emoticons" I am given:
function (){var k,m,h,o,l=Array.prototype.slice.call(arguments),n="string"==typeof l[0]?l.shift():"",f="boolean"==typeof l[0]?l.shift():!1,g=l[0],j=[];if(g){f&&(c={},d=[]);for(k in g)c[k]=g[k],c[k][0]=n+c[k][0];for(k in c){if(c[k].length>2){for(m=c[k].slice(2).concat(k),h=m.length;h--;)m[h]=m[h].replace(/(\W)/g,"\\$1");o=m.join("|"),d.push({name:k,regexp:new RegExp("^"+o+"$")})}else o=k.replace(/(\W)/g,"\\$1");j.push(o)}b=new RegExp("(^|\\s)("+j.join("|")+")(?=(?:$|\\s))","g")}return c}
So what I'm wondering is, is there a way to use this code in a tampermonkey script somehow so that in the future, if the code is removed from the website, I could still use the emotify.emoticons function to create standalone emotes?
I really hope this makes sense. If you need any more information, fell free to ask. Any help is greatly appreciated!
-Tom
I might be wrong, but my inclination is that no, you can't - because the full behavior for this code is probably actually executed server-side, not in the web browser.
The images would have to get passed to the server to get circulated to the other people in the chatbox anyway
The function you list just returns a function, which does some (somewhat cryptic!) string operations, and little else, indicating the heavy lifting is done elsewhere.
The reason why you can run it using tampermonkey currently is because the function is defined on hitbox.tv. Defining it in tampermonkey probably won't help, because if hitbox removed it, they would also remove everything that uses it, rendering it useless.
You can do more investigation if you feel like it; http://www.hitbox.tv/dist/hitbox-ui.min.js is the link to their (minified) javascript file that runs the website. Running it through http://jsbeautifier.org/ yields a ~55,000 line long file, however, so unless you know what other variable words to search for, it's going to be impractical to comb through by hand.

Vim Javascript autocompletion picks comments as suggestions

I have the following line in my vimrc to enable Javascript completion:
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
The problem is that if I'm working on a JS file that contains a lot of comments, for example:
// draws the map and the pieces depending on the state of the game
Vim picks words from those comments, such as draws, map, etc.; and considers them as acceptable code suggestions, which they are clearly not. How can I filter them out?
Vim has a number of completion mechanism suited for different needs: keyword completion, file name completion… and omni completion, the kind of completion most suited to programming.
Omni completion is usually initiated by pressing <C-x><C-o> and will certainly never pick a suggestion from the comments in your file. Are you sure you are using omni completion and not something else? <C-n> or <C-p>, maybe? See :h ins-completion for the full list.
Also, that line is totally useless. Supposing you have filetype plugin indent on in your ~/.vimrc, it's completely unnecessary to tell Vim to use JS completion in JS file.
JS autocompletion requires dynamic type inference, which is difficult for non-IDE text editors.(JS has no static class, you know!) Vim probably just implement a fuzzy matching algorithm to make completion. (I just guess, because I don't use vim personally). I think Vim also takes comments into consideration because it probably does not interpret js!
You can try the new Ternjs plugin for Vim. You need node.JS. Make sure your Vim has Python support.
Online demo is on http://ternjs.net/
Generally, javascript autocompletion is difficult to accomplish due to the dynamic nature of that language. Ternjs makes type inference like javascript engine, and thus makes autocompletion better.
(Personally I have tried tern in SublimeText. Great Experience except initial loading and no builtin function such as document.body.appendChild)

Strange Javascript/vbscript behavior when opening file from browser

An old web application I recently have to work with is having an issue. There is an input element that contains the following:
onClick="javascript:Run('**SomeFilePath.mdb**');"
What this is supposed to do is open a users respective .mdb file.
First off, there is no javascript Run function defined anywhere. I searched online because I thought maybe it's an old javascript built-in, but I couldn't find anything.
Second off, there IS a vbscript Run() function, that implements the described behavior, defined in the source code, but as far as I know javascript can't call that other than via ajax, which as you can see isn't what is happening.
The strange part is this works for some users!
If anyone could shed some light as to why I'd appreciate it!
EDIT: The only browser I'm dealing with is IE. I know there is an active-x way to open a file, which is what the vbscript Run() function I mentioned above is using.
Update: So after more investigation/research, it would seem like when IE doesn't find the javascript Run() function it defaults to the vbscript Run() function that IS defined. However this only occurs on some versions of IE. Can anyone confirm this behavior?
Research links:
Comment referring to how IE defaults w/ scripting
Msdn article about using both script types in same page
Yes, you can run vbscript from javascript and vice-versa, i do it sometimes when one language doesn't support something the other does.
You can indicate in your script which is the default language in case you don't specify it like .
You can also specify it while calling the function like vbscript:functionname("..") or javascript:functionname("..")
As you noticed there are cases where the browser gets confused and doesn't find the function because he searches/executes the function in the wrong language.
This behavior is influenced i suppose by version also but surely by in which order the logic flows in your script, if the browser first executes a javascript he tends to go further in this language in case of doubt.
So to evade this
don't mix the two unless realy necessary, translate your vbscript function in javascript)
try to always use javascript, vbscript is less good at handling DOM etc
in case they are mixed, specify the correct scriptlanguage when you call a function
when opening a script tag, also give the correct language like or
So, specific, to solve your problem translate the vbsripts function to javascript and if not possible, call your function like onClick="vbscript:Run('**SomeFilePath.mdb**')"

How to find functions/operators/methods in JS files quickly and easily

I'm looking for an app or a command line tool that can help me quickly find a defined function in a file. The file in question here is the EXT-debug.js file. I want to override some methods(in this case onRender) however I need to figure out the signature of said functions.
I've yet to try Eclipse or Aptana; I'm looking for a more lightweight solution.
I use agent ransack. It's able to search for files as well as content. I also like the fact that you can run it on demand as it does not use an invasive, indexing service.
Agent Ransack
Visual Studio is not exactly a lightweight solution, but I have to recommend it. It's come a long way towards becoming an excellent JavaScript editor.
Visual Studio's IntelliSense is able to infer JavaScript types and give you a dropdown of the functions and values in your object (works pretty well).
Of course, I always have my handy little muscle memory spasm: double-click-select -> Ctrl-C -> Ctrl-Shift-F -> Ctrl-V -> ENTER
And here's a plugin that pre-searches for exact string matches in your entire solution and highlights them for you, so jumping to a function definition is instantaneous. Whole Tomato's Visual Assist X

Categories