fix terminal completion issues with `replacementIndex` (#236728)

fix replacement index weirdness + more
pull/236749/head^2
Megan Rogge 2024-12-20 14:05:31 -06:00 committed by GitHub
parent 5d5976d10c
commit 9ee30e50da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 9 deletions

View File

@ -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 = '';