Microsoft/monaco-editor

suggestWidget doesn't clean suggestion in case for triggerCharacters if this._completionModel.items.length === 0

Open

#2 680 ouverte le 30 sept. 2021

Voir sur GitHub
 (2 commentaires) (0 réactions) (1 assigné)JavaScript (1 283 forks)batch import
help wantedsuggest

Métriques du dépôt

Stars
 (14 836 stars)
Métriques de merge PR
 (Merge moyen 6h 26m) (15 PRs mergées en 30 j)

Description

suggestWidget trigger another completion request in case the character is a triggerCharacter. This is fine, but in case - this._completionModel.items.length === 0 this cause a race condition since the until the language server respond to the completion request the widget is potentially open with a stale data. If the user hits enter it will accept the stale suggestion and override the triggerCharacter.

For example: the completion provider sets "(" as trigger character. User writes

foo

suggestion widget shows foo as suggestion. Now the user writes

foo( --->

another request is sent to the language server. The user hits enter before the language server respond to the completion request and the parenthesis is overwritten with the stale suggestion of "foo" leaving the editor in this state:

foo

I think here it should also retrigger only if this._completionModel.items.length === 0

I have tried this in my local monaco build and it fixed the issue:

this.trigger({ auto: true, shy: false, triggerCharacter: lastChar }, Boolean(this._completionModel) && this._completionModel.items != null && this._completionModel.items.length > 0, supports, existing);

that clear the empty suggestions model UI since the suggestions list is empty after the user type foo( and reopens it after the response from the server for the trigger character returns. Therefore it avoids the race condition in case the user hits enter before the response from the language server returns.

monaco-editor version: 0.22.3 Browser: OS: Playground code that reproduces the issue:

Guide contributeur