From 9ee30e50da91f818e60c1c3ccf156f64c097bff1 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Fri, 20 Dec 2024 14:05:31 -0600 Subject: [PATCH] fix terminal completion issues with `replacementIndex` (#236728) fix replacement index weirdness + more --- .../suggest/browser/terminalSuggestAddon.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts b/src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts index f750d76f089..52d7c1b8c37 100644 --- a/src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts +++ b/src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts @@ -64,7 +64,6 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest private _leadingLineContent?: string; private _cursorIndexDelta: number = 0; private _requestedCompletionsIndex: number = 0; - private _providerReplacementIndex: number = 0; private _lastUserData?: string; static lastAcceptedCompletionTimestamp: number = 0; @@ -171,11 +170,6 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest } this._onDidReceiveCompletions.fire(); - // ATM, the two providers calculate the same replacement index / prefix, so we can just take the first one - // TODO: figure out if we can add support for multiple replacement indices - const replacementIndices = [...new Set(providedCompletions.map(c => c.replacementIndex))]; - const replacementIndex = replacementIndices.length === 1 ? replacementIndices[0] : 0; - this._providerReplacementIndex = replacementIndex; this._requestedCompletionsIndex = this._promptInputModel.cursorIndex; this._currentPromptInputState = { @@ -186,7 +180,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest ghostTextIndex: this._promptInputModel.ghostTextIndex }; - this._leadingLineContent = this._currentPromptInputState.prefix.substring(replacementIndex, replacementIndex + this._promptInputModel.cursorIndex + this._cursorIndexDelta); + this._leadingLineContent = this._currentPromptInputState.prefix.substring(0, this._requestedCompletionsIndex + this._cursorIndexDelta); const completions = providedCompletions.flat(); if (!completions?.length) { @@ -339,7 +333,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest if (this._terminalSuggestWidgetVisibleContextKey.get()) { this._cursorIndexDelta = this._currentPromptInputState.cursorIndex - (this._requestedCompletionsIndex); - let normalizedLeadingLineContent = this._currentPromptInputState.value.substring(this._providerReplacementIndex, this._requestedCompletionsIndex + this._cursorIndexDelta); + let normalizedLeadingLineContent = this._currentPromptInputState.value.substring(0, this._requestedCompletionsIndex + this._cursorIndexDelta); if (this._isFilteringDirectories) { normalizedLeadingLineContent = normalizePathSeparator(normalizedLeadingLineContent, this._pathSeparator); } @@ -458,7 +452,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest // The replacement text is any text after the replacement index for the completions, this // includes any text that was there before the completions were requested and any text added // since to refine the completion. - const replacementText = currentPromptInputState.value.substring(suggestion.item.completion.replacementIndex ?? this._providerReplacementIndex, currentPromptInputState.cursorIndex); + const replacementText = currentPromptInputState.value.substring(suggestion.item.completion.replacementIndex, currentPromptInputState.cursorIndex); // Right side of replacement text in the same word let rightSideReplacementText = '';