Skip to content

Commit 9ee30e5

Browse files
authored
fix terminal completion issues with replacementIndex (microsoft#236728)
fix replacement index weirdness + more
1 parent 5d5976d commit 9ee30e5

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
6464
private _leadingLineContent?: string;
6565
private _cursorIndexDelta: number = 0;
6666
private _requestedCompletionsIndex: number = 0;
67-
private _providerReplacementIndex: number = 0;
6867

6968
private _lastUserData?: string;
7069
static lastAcceptedCompletionTimestamp: number = 0;
@@ -171,11 +170,6 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
171170
}
172171
this._onDidReceiveCompletions.fire();
173172

174-
// ATM, the two providers calculate the same replacement index / prefix, so we can just take the first one
175-
// TODO: figure out if we can add support for multiple replacement indices
176-
const replacementIndices = [...new Set(providedCompletions.map(c => c.replacementIndex))];
177-
const replacementIndex = replacementIndices.length === 1 ? replacementIndices[0] : 0;
178-
this._providerReplacementIndex = replacementIndex;
179173
this._requestedCompletionsIndex = this._promptInputModel.cursorIndex;
180174

181175
this._currentPromptInputState = {
@@ -186,7 +180,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
186180
ghostTextIndex: this._promptInputModel.ghostTextIndex
187181
};
188182

189-
this._leadingLineContent = this._currentPromptInputState.prefix.substring(replacementIndex, replacementIndex + this._promptInputModel.cursorIndex + this._cursorIndexDelta);
183+
this._leadingLineContent = this._currentPromptInputState.prefix.substring(0, this._requestedCompletionsIndex + this._cursorIndexDelta);
190184

191185
const completions = providedCompletions.flat();
192186
if (!completions?.length) {
@@ -339,7 +333,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
339333

340334
if (this._terminalSuggestWidgetVisibleContextKey.get()) {
341335
this._cursorIndexDelta = this._currentPromptInputState.cursorIndex - (this._requestedCompletionsIndex);
342-
let normalizedLeadingLineContent = this._currentPromptInputState.value.substring(this._providerReplacementIndex, this._requestedCompletionsIndex + this._cursorIndexDelta);
336+
let normalizedLeadingLineContent = this._currentPromptInputState.value.substring(0, this._requestedCompletionsIndex + this._cursorIndexDelta);
343337
if (this._isFilteringDirectories) {
344338
normalizedLeadingLineContent = normalizePathSeparator(normalizedLeadingLineContent, this._pathSeparator);
345339
}
@@ -458,7 +452,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
458452
// The replacement text is any text after the replacement index for the completions, this
459453
// includes any text that was there before the completions were requested and any text added
460454
// since to refine the completion.
461-
const replacementText = currentPromptInputState.value.substring(suggestion.item.completion.replacementIndex ?? this._providerReplacementIndex, currentPromptInputState.cursorIndex);
455+
const replacementText = currentPromptInputState.value.substring(suggestion.item.completion.replacementIndex, currentPromptInputState.cursorIndex);
462456

463457
// Right side of replacement text in the same word
464458
let rightSideReplacementText = '';

0 commit comments

Comments
 (0)