Auto-completion triggered too much

Hey there,

I’m the “maker” of the WordPress functions auto-completion extension. It’s super simple and my knowledge of complex js is limited, so bare with me.

I’m using a simple array of functions that starts like this:

let funcList = [{"title":"_( $string )","snippet":"_( ${0:$string} )"},{"title":"__( $text, $domain )","snippet":"__( ${0:$text}, ${1:$domain = \'default\'} )","desc":"Retrieve the translation of $text."},{"title":"...

I’m then iterating over the array and add the CompletionItems like this:

let item = new CompletionItem( func.title, CompletionItemKind.Function );
if( func.desc !== undefined ) {
    item.documentation = func.desc;
}
if( func.snippet !== undefined ) {
    item.insertText = func.snippet;
    item.insertTextFormat = InsertTextFormat.Snippet;
}

What’s wrong now is that all the CompletionItems are triggered by any character in the snippet, so if I’m e.g. ending a line with a ; I get all kind of suggestions and pressing enter doesn’t create a new line but inserts the first suggestion. Same happens after different other characters like {}

So what I’m running into is a too aggressive auto-completion, that I kind of need to stop by adding stop words? Or tell the AutoCompletion to be triggered only after a space, not right behind any character? Is the range value relevant here?

Sorry if that’s too easy to fix, I’ve pretty much put this together by trial and error :slight_smile:

Thanks in advance for any tips! And thanks for this forum, appreciate all your work for the dev community!

To add to this (slightly related), I had a report that the auto-completion is triggered anywhere within .php files, but it is possible and common to use HTML within PHP files. So a better detection for whether an auto-completion should fire would be to read the <?php tags and only fire inside.

Thanks in advance for any help with this.

I believe we’ve identified this as an issue in Nova 2, as we relaxed the completion behaviors a bit to make it possible to complete on other characters, but this is having unintended side effects. We are planning on addressing this in the next update to Nova (Nova 3) which should be coming (at current schedule) next week.

We will be introducing new extension API to allow extensions to declare specifically which characters (other than identifier characters) are allowed to cause completions to be requested).

@logan This is good to know! Thanks for sharing, as I’m also looking into an issue with how completion triggers changed in Nova 2.

To be a bit annoying, while you’re altering the Completions API, any chance you’ve considered letting us humbly request that the completion list we return not be re-sorted?