Microsoft/monaco-editor

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

Open

#2.680 geöffnet am 30. Sept. 2021

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (1 zugewiesene Person)JavaScript (1.283 Forks)batch import
help wantedsuggest

Repository-Metriken

Stars
 (14.836 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6h 26m) (15 gemergte PRs in 30 T)

Beschreibung

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:

Contributor Guide