问题
we're using the ACE editor to write javascript code that's interpreted on the server side. So the server has a JavaScript interface and can execute submitted code to accomplish some task from the outside.
The server implements some new objects that are not known by ACE. So ACE shows a warning, if one of this unknown objects is used in code.
What is the correct way to tell ACE, that there are some new objects, variables und functions? I already took a look into worker-javascript.js, but I DON'T want to reimplement this whole stuff (updating ACE would get harder than). Is there any interface I can use?
回答1:
Ace uses jshint, which have an option to set a list of global variables. Ace supports changeOptions call on worker to modify default options it passes to jshint, but doesn't have a way to pass list of gloabals
You can add it by changing line at https://github.com/ajaxorg/ace/blob/v1.1.8/lib/ace/mode/javascript_worker.js#L130
to lint(value, this.options, this.options.globals);
and from your code calling
editor.session.$worker.call("changeOptions", [{
globals: {foo: false, bar: false...},
undef: true, // enable warnings on undefined variables
// other jshint options go here check jshint site for more info
}]);
the change to worker.js#L130 is simple enough and should be accepted if you make a pull request to ace
来源:https://stackoverflow.com/questions/28434455/how-to-add-some-known-objects-to-ace-editors-syntax-checker