ajaxorg / ace

Ace (Ajax.org Cloud9 Editor)
https://ace.c9.io
Other
26.76k stars 5.29k forks source link

Live autocomplete adding extra characters if xquery and/or jsoniq modes have been included but aren't active #2212

Closed mwoc closed 10 years ago

mwoc commented 10 years ago

We're using Ace by including the original source code - so not the built version - by including all files we might need with require.js.

The modes xquery and jsoniq are giving some unwanted behaviour when including them - but not having them active - and then enabling live autocompletion in completely different modes such as ace/mode/ini.

The following code from jsoniq.js throws a TypeError, even though the jsoniq mode isn't active, during typing:

   LanguageTools.addCompleter({
        getCompletions: function(editor, session, pos, prefix, callback) {
            session.$worker.emit("complete", { data: { pos: pos, prefix: prefix } });
            session.$worker.on("complete", function(e){
                callback(null, e.data);
            });
        }
    });

The error is: "Uncaught TypeError: Cannot read property 'emit' of null"

When that happens, unwanted characters are added to the output.

I presume it's related to the mode having a worker, as I can't reproduce it on .php which does have a worker.

Some implementation details - the files are included with require.js before they're actually needed:

define([
    'ace/ace',
    'ace/theme/tomorrow',
    'ace/mode/ini',
    'ace/mode/jsoniq',
    'ace/ext/language_tools',
    'ace/ext/searchbox',
    'ace/ext/settings_menu',
    'ace/incremental_search',
    'ace/worker/worker'
], function (ace) {
....
});

And then in the ' function' block above, these commands are run at some point:

editor.getSession().setMode('ace/mode/ini');

editor.setOptions({
    enableBasicAutocompletion: true,
    enableLiveAutocompletion: true
});
nightwing commented 10 years ago

Good catch! modes shouldn't use LanguageTools or editor, jsoniq and xqery modes need some reworking apparently.

nightwing commented 10 years ago

was fixed in https://github.com/ajaxorg/ace/pull/2222

mwoc commented 10 years ago

Excellent, thanks!