How to add some known objects to ace editors syntax checker?

霸气de小男生 提交于 2019-12-12 03:22:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!