suggestWidget doesn't clean suggestion in case for triggerCharacters if this._completionModel.items.length === 0
#2.680 aberto em 30 de set. de 2021
Métricas do repositório
- Stars
- (14.836 stars)
- Métricas de merge de PR
- (Mesclagem média 6h 26m) (15 fundiu PRs em 30d)
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: