Microsoft/monaco-editor

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

Open

#2,680 创建于 2021年9月30日

在 GitHub 查看
 (2 评论) (0 反应) (1 负责人)JavaScript (1,283 fork)batch import
help wantedsuggest

仓库指标

Star
 (14,836 star)
PR 合并指标
 (平均合并 6小时 26分钟) (30 天内合并 15 个 PR)

描述

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:

贡献者指南