Ace editor custom error checking - javascript

I created a new language mode in my editor with a few keywords: Ben, Tom, Brian and operands: AND OR ( ). Also, I need a custom error checker. I tried to change json worker which I have been inlcuded in my mode.
Everything I need is this: (Ben AND TOM) OR Brian - this is correct, everything else, like undefined keywords or incorecct syntax like BEN AND AND TOM, or BEN AND OR TOM- should treat as error. Does anyone have some idea?

There is no easy way to do this.
You need to create a parser for your language to detect errors and send locations to ace. There are some libraries that can help you with this. e.g http://lakhin.com/projects/papa-carlo/demo/, but even with that, it's not a trivial task

Related

Visual Studio Code Intellisense Method Definitions Javascript

Apparently no one else has wanted this feature, or I'm missing something. Intellisense works as normal, but I'm wondering if I'm missing a setting somewhere, if there is an extension, or if this functionality just isn't offered in VS Code... I would like to have the purpose of the method display when I start typing it as you can see in Adobe Brackets:
As opposed to how it shows in VS Code(which just shows the parameter requirements):
Is this possible?
VSCode is able to use the typescript language server to infer some information about the javascript that you're writing. The types for window/document etc are provided by the typescript team.
Here's where the type information for elements comes from. Compare that with the types for the document object. Notice that the properties here have comments above them, while the element properties do not. Type document.getElementById in VSCode, you'll see extra info like you do in brackets:
So for this information to appear about properties on Elements, someone would need to go through and add the comments. I have no idea if the typescript team is open to this, though.

is it possible to obfuscate while using soma.js dependency injection?

While looking at how to make JavaScript source code more secure I came upon a lot of 'solutions'. but most people said the same thing; "It's not possible to make your source code 100% secure", "try obfuscation", "run your code server side", etc, etc. After reading a lot posts here on stackoverflow, and other sites I came to the conclusion that a combination of minifying and obfuscating would do the job (for me).
But here is the problem: we are currently using soma.js with dependency injection, and the way we set it up it does not work well with obfuscation. It's basically this:
var session = function(id, sessionModel){
this._sessionmodel = sessionModel;
}
mapping:
injector.mapClass("sessionModel", project.SessionModel, true);
Obfuscation will then rename the sessionModel in the function to for example 'A', but the mapping that was done on SessionModel by the injector still remains 'sessionModel' and not 'A', this then basically breaks the code.
I've read this post which is about the same subject Dependency Injection and Code Obfuscation, but it does not provide a real answer to my problem so I decided to write my own question.
Any tips/hint/suggestions are welcome.
Thanks in advance.
EDIT
It seems you can tell Yuicompressor to exclude certain identifiers by putting in 'hints' into the files like this: "identifier:nomunge, identifier2:nomunge".
var session = function(id, sessionModel){
"sessionModel:nomunge";
this._sessionmodel = sessionModel;
}
I tested this and it works but that means you'll have to put it in yourself which is a lot of work if you have to do that for every script, especially if you have a very big project..
Gonna look into it further, and update this post if anything new pops up
EDIT 2
It's been a while, I only work 1 day a week on this =S.
As said before you can get it working by telling it which identifiers to exclude.
For that I looked into regular expression to get the "mapped classes" programmatically, since doing it by hand is just insane.
What I basically did was instead of putting every hint in by hand, I made a identifier, for example "#nomunge"; and used a simple replaceregexp task to find it and replace it with a string containing all the identifiers. This string is build by loading the script and going through it with a tokenfilter.
<target name="build hints">
<loadfile property="hints" srcFile="${temp.loc}/all.js">
<filterchain>
<tokenfilter delimoutput=":nomunge,">
<ignoreblank/>
<containsregex pattern="${regexp}"/>
</tokenfilter>
</filterchain>
</loadfile>
<echo message="${hints}"/>
</target>
<replaceregexp file="${temp.loc}/all.js"
match="#nomunge"
flags = "g"
replace = "target:nomunge, dispatcher:nomunge, injector:nomunge,${hints}"
/>
This seems to do the job, for now...
I'm behind the soma.js framework, feel free to ask me questions on the google group, happy to help.
This might help a bit more:
https://groups.google.com/forum/#!topic/somajs/noOX2R4K58g
Romu

Eclipse: Type mismatch: cannot convert from String[] to any

Eclipse is complaining about my JavaScript code:
As fas as I can tell, the code is working fine. What do I have to change to get rid of the warning?
The semantic validator (despite it's failings, like this one) actually has a lot of uses. For instance, it can tell you when you've got a variable that's not being used anywhere (eg. because you have a typo in the variable's name).
If you don't want to see that error message, but you still want to keep semantic validation on, you can use this hack:
var textArray = 0 || [ ...
it's a little ugly, and your non-Eclipse-using co-workers may not like it, but at least it gives you a way to ditch the warning and still have the benefits of the validator.
A similar hack (if you don't like the first one, or if you're a big Douglas Crockford fan) that will also work is:
var textArray;
textArray = [ ...
Seems to be a bug of WTP , more specifically of the JS Validator component which is by default configured to "Enable JavaScript semantic validation".
Try to turn off the semantic validation from preferences page.

spellchecking code comments in Textmate

Does anyone know of a plugin I can use to spell check the comments in my code?
I'm always doing things like this
//Retrns porduct name in upercase
function getUpperCaseProductName(){
var productName = Myobj.currentProduct.data.name;
return productName.toUpperCase();
}
I don't know of a textmate plugin, but I'm pretty sure it does this already via Edit → Spelling, which is enabled by default for comments. Start by checking that you don't have this turned off for comments, or set to the wrong language.
It's unlikely that someone will develop a custom plugin to do something that textmate already has as a feature.
BTW, the //Retrns example you give above is joined to the two slashes. No word in the dictionary has two slashes at the start, so it may be missing it for this reason. If this is the problem, file a bug report with the textmate guys, or perhaps consider moving to a more feature-rich editor if it bothers you a lot (PHPStorm picks up that typo just fine, and you can also check the names of variables and functions if you want to be really pernickety).
Try using the Spelling option under Edit in Textmate2.
I think it does not differentiate between code and comment for Spell Check.

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