Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use mirror worker for ace editor with ace-builds

Tags:

ace-editor

I am using ace-builds to build my ace editor app with webpack.

I need to use a custom worker for syntax validation. The wiki page here suggests to extend a worker named mirror obtained by following.

var Mirror = require("ace/worker/mirror").Mirror;

But ace-builds does not seem to provide this worker. How do I create a custom worker for syntax validation using ace-builds?

Any other advice on how to build an ace editor app with a custom syntax validating worker (for a custom programming language) is much appreciated. (I cannot use the ace library supposed to be used with require.js, as it uses require.toUrl which webpack does not know about. See github issue)

like image 390
Aruna Herath Avatar asked Feb 26 '17 06:02

Aruna Herath


1 Answers

ace-builds repository provides only built workers, and doesn't have source of ace/worker/mirror in a separate file.

You can use json worker to bootstrap your custom one, since it contains only 200 lines of extra code https://github.com/ajaxorg/ace-builds/blob/master/src/worker-json.js#L1409-L1699

rename that file to "<mymode>_worker.js" and add worker definition at the end.

define("ace/mode/<mymode>_worker",["require","exports","module"], function(require, exports, module) {
"use strict";

var oop = require("../lib/oop");
var Mirror = require("../worker/mirror").Mirror;

...

});
like image 122
a user Avatar answered Nov 05 '22 20:11

a user