Cannot get custom suggestions (autocomplete) after doc has changed

I have custom completion source added to javascript extension:

javascript(),
javascriptLanguage.data.of({autocomplete: javascriptCompletionSource})

Context: I have some panel created with ViewPlugin.fromClass. This panel contains autocompletions list. In update method I get completions and add them into container (default suggestions work properly):

if (!update.docChanged) {
  return
}

const tokens = currentCompletions(update.state)

tokensContainerElement.innerHTML = tokens.map(createTokenElement)

The problem I’m facing: suggestions from javascriptCompletionSource are not returned from currentCompletions, moreover, logic inside javascriptCompletionSource has been triggered after currentCompletions gets called. Default suggestions coming from javascript() extension work properly.

CompletionSource successfully matched in javascriptCompletionSource, so I expected it to be returned from currentCompletions, but it’s not.

I wondered if this problem related to some delaying issue (tasks queue), so I tried to get autocompletions with timeout ~250ms. I managed to make javascriptCompletionSource being called and return its completions earlier, than currentCompletions, but still got nothing…

I also tried to play around with interactionDelay config field (higher delay), tried to call startCompletion before currentCompletions, didn’t help.

Did anyone meet this problem?

Completions are update asynchronously, yes. But there will be another view update fired when they do change. I’m not sure what you mean when you say that you are adding the completions to a container. Showing them a second time?

Not second time, I disabled default completions preview and using my own custom container placed in the bottom (for mobile editing). I get completions from currentCompletions and create html out of those completions, and append to my html container

Then I guess instead of checking for docChanged you want to check whether currentCompletions changed.

Can you point me in the right direction, please? Is there any specific way to do it in the cm6 or is it about implementing own subscriber?

The plugin you already have just needs to stop looking at docChanged and compare currentCompletions(state) to the array it is currently displaying, and update if they differ.