do not show no suggestions widget unless it was explicitly invoked (#236505)

pull/236509/head
Megan Rogge 2024-12-18 12:38:58 -06:00 committed by GitHub
parent aaa5982ec9
commit 4fcae8834d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 9 deletions

View File

@ -192,7 +192,7 @@ registerActiveInstanceAction({
weight: KeybindingWeight.WorkbenchContrib + 1,
when: ContextKeyExpr.and(TerminalContextKeys.focus, TerminalContextKeys.terminalShellIntegrationEnabled, ContextKeyExpr.equals(`config.${TerminalSuggestSettingId.Enabled}`, true))
},
run: (activeInstance) => TerminalSuggestContribution.get(activeInstance)?.addon?.requestCompletions()
run: (activeInstance) => TerminalSuggestContribution.get(activeInstance)?.addon?.requestCompletions(true)
});
registerActiveInstanceAction({

View File

@ -129,7 +129,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
}));
}
private async _handleCompletionProviders(terminal: Terminal | undefined, token: CancellationToken, triggerCharacter?: boolean): Promise<void> {
private async _handleCompletionProviders(terminal: Terminal | undefined, token: CancellationToken, explicitlyInvoked?: boolean): Promise<void> {
// Nothing to handle if the terminal is not attached
if (!terminal?.element || !this._enableWidget || !this._promptInputModel) {
return;
@ -156,7 +156,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
await this._extensionService.activateByEvent('onTerminalCompletionsRequested');
}
const providedCompletions = await this._terminalCompletionService.provideCompletions(this._promptInputModel.prefix, this._promptInputModel.cursorIndex, this._shellType, token, triggerCharacter, doNotRequestExtensionCompletions);
const providedCompletions = await this._terminalCompletionService.provideCompletions(this._promptInputModel.prefix, this._promptInputModel.cursorIndex, this._shellType, token, doNotRequestExtensionCompletions);
if (!providedCompletions?.length || token.isCancellationRequested) {
return;
}
@ -220,7 +220,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
if (token.isCancellationRequested) {
return;
}
this._showCompletions(model);
this._showCompletions(model, explicitlyInvoked);
}
setContainerWithOverflow(container: HTMLElement): void {
@ -231,7 +231,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
this._screen = screen;
}
async requestCompletions(triggerCharacter?: boolean): Promise<void> {
async requestCompletions(explicitlyInvoked?: boolean): Promise<void> {
if (!this._promptInputModel) {
return;
}
@ -245,7 +245,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
}
this._cancellationTokenSource = new CancellationTokenSource();
const token = this._cancellationTokenSource.token;
await this._handleCompletionProviders(this._terminal, token, triggerCharacter);
await this._handleCompletionProviders(this._terminal, token, explicitlyInvoked);
}
private _sync(promptInputState: IPromptInputModelState): void {
@ -292,7 +292,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
}
for (const char of provider.triggerCharacters) {
if (prefix?.endsWith(char)) {
this.requestCompletions(true);
this.requestCompletions();
sent = true;
break;
}
@ -359,13 +359,13 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
};
}
private _showCompletions(model: SimpleCompletionModel): void {
private _showCompletions(model: SimpleCompletionModel, explicitlyInvoked?: boolean): void {
if (!this._terminal?.element) {
return;
}
const suggestWidget = this._ensureSuggestWidget(this._terminal);
suggestWidget.setCompletionModel(model);
if (!this._promptInputModel) {
if (!this._promptInputModel || !explicitlyInvoked && model.items.length === 0) {
return;
}
this._model = model;