ACE-Editor autocomplete whole sentences

672 views
Skip to first unread message

Simon Schneider

unread,
Mar 10, 2015, 1:51:27 PM3/10/15
to ace-d...@googlegroups.com

I'm trying to get the ACE editor to show auto suggestions for BDD (Gherkin) based stories. Assuming that I have a way to generate a list of snippets in the form

snippet Given a certain precondition with a parameter $aParam is fullfilled
     Given a certain precondition with a parameter ${1:aParam} is fullfilled

I do get a nice list of auto suggestions when entering one of words of the first line, however, spaces do stop the auto completion and it restarts with the next word.

Is there a way to get the autocompletion to consider the entire line, except just one word at a time?

Harutyun Amirjanyan

unread,
Mar 10, 2015, 5:44:34 PM3/10/15
to ace-d...@googlegroups.com
> I do get a nice list of auto suggestions when entering one of words of the first line, however, spaces do stop the auto completion and it restarts with the next word.
> Is there a way to get the autocompletion to consider the entire line, except just one word at a time?
Ace doesn't have support for this yet, but this looks like something that will be easy to add
Could you show the code with which you get nice list of suggestions​?
Or maybe make a demo on http://plnkr.co/ or jsbin so that we have a nice starting point.

Simon Schneider

unread,
Mar 11, 2015, 7:10:49 AM3/11/15
to ace-d...@googlegroups.com
With "a nice list of auto suggestions" I mean that ace already provides me with that list of suggestions. The only thing needed for this is adding the above snippet (and possibly similar ones) to the snippets file of an existing ace mode and off you go. However, as I said, suggestions stop after a "space" character. I identified this behavior to come from the autocomplete.js file where in the commands section it says:

"Space": function(editor) { editor.completer.detach(); editor.insert(" ");}

Commenting out the detach() call works as expected, yet the auto suggestion still behaves a little bit weird, as for example it works nice, until I make the first backspace. Also editing one of the sentences later on starts all my suggestions at the point where I start typing and not using the whole existing sentence.

Harutyun Amirjanyan

unread,
Mar 24, 2015, 6:56:54 AM3/24/15
to ace-d...@googlegroups.com
I've removed this keybinding for space. It was a leftover from old code which didn't handle filtering of the list properly.
But for handling the case of starting to type in the middle of the sentence we might need to create a new completer.
Snippet completer looks for non word character to find the start of completion prefix, but for full sentences finding the start is much harder, especially if sentences can be on multiple lines or have more than one space between words.


Reply all
Reply to author
Forward
0 new messages