Use completion text always instead of label

Fixes #221953
This commit is contained in:
Daniel Imms
2024-07-17 08:31:34 -07:00
parent 62ddf0aa3c
commit 47366d3ced
3 changed files with 10 additions and 19 deletions
@@ -383,7 +383,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
this._leadingLineContent = completions[0].completion.label.slice(0, replacementLength);
const model = new SimpleCompletionModel(completions, new LineContext(this._leadingLineContent, replacementIndex), replacementIndex, replacementLength);
if (completions.length === 1) {
const insertText = (completions[0].completion.completionText ?? completions[0].completion.label).substring(replacementLength);
const insertText = completions[0].completion.label.substring(replacementLength);
if (insertText.length === 0) {
this._onBell.fire();
return;
@@ -477,8 +477,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
const initialInput = initialPromptInputState.value.substring(0, (this._leadingLineContent?.length ?? 0));
const lastSpaceIndex = initialInput.lastIndexOf(' ');
const completion = suggestion.item.completion;
const completionText = completion.completionText ?? completion.label;
const finalCompletionRightSide = completionText.substring((this._leadingLineContent?.length ?? 0) - (lastSpaceIndex === -1 ? 0 : lastSpaceIndex + 1));
const finalCompletionRightSide = completion.label.substring((this._leadingLineContent?.length ?? 0) - (lastSpaceIndex === -1 ? 0 : lastSpaceIndex + 1));
// Hide the widget if there is no change
if (finalCompletionRightSide === additionalInput) {
@@ -488,7 +487,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
// Get the final completion on the right side of the cursor if it differs from the initial
// propmt input state
let finalCompletionLeftSide = completionText.substring(0, (this._leadingLineContent?.length ?? 0) - (lastSpaceIndex === -1 ? 0 : lastSpaceIndex + 1));
let finalCompletionLeftSide = completion.label.substring(0, (this._leadingLineContent?.length ?? 0) - (lastSpaceIndex === -1 ? 0 : lastSpaceIndex + 1));
if (initialInput.endsWith(finalCompletionLeftSide)) {
finalCompletionLeftSide = '';
}
@@ -552,8 +551,7 @@ export function parseCompletionsFromShell(rawCompletions: PwshCompletion | PwshC
}
if (!Array.isArray(rawCompletions)) {
return [rawCompletions].map(e => (new SimpleCompletionItem({
completionText: e.CompletionText,
label: e.ListItemText,
label: e.CompletionText, // e.ListItemText,
icon: pwshTypeToIconMap[e.ResultType],
detail: e.ToolTip
})));
@@ -563,23 +561,20 @@ export function parseCompletionsFromShell(rawCompletions: PwshCompletion | PwshC
}
if (typeof rawCompletions[0] === 'string') {
return [rawCompletions as CompressedPwshCompletion].map(e => (new SimpleCompletionItem({
completionText: e[0],
label: e[1],
label: e[0], // e[1],
icon: pwshTypeToIconMap[e[2]],
detail: e[3]
})));
}
if (Array.isArray(rawCompletions[0])) {
return (rawCompletions as CompressedPwshCompletion[]).map(e => (new SimpleCompletionItem({
completionText: e[0],
label: e[1],
label: e[0], // e[1],
icon: pwshTypeToIconMap[e[2]],
detail: e[3]
})));
}
return (rawCompletions as PwshCompletion[]).map(e => (new SimpleCompletionItem({
completionText: e.CompletionText,
label: e.ListItemText,
label: e.CompletionText, // e.ListItemText,
icon: pwshTypeToIconMap[e.ResultType],
detail: e.ToolTip
})));
@@ -19,10 +19,6 @@ export interface ISimpleCompletion {
* The completion's detail which appears on the right of the list.
*/
detail?: string;
/**
* The completion's completion text which is used to actually insert the completion.
*/
completionText?: string;
}
export class SimpleCompletionItem {
@@ -38,6 +34,6 @@ export class SimpleCompletionItem {
readonly completion: ISimpleCompletion
) {
// ensure lower-variants (perf)
this.labelLow = (this.completion.completionText ?? this.completion.label).toLowerCase();
this.labelLow = this.completion.label.toLowerCase();
}
}
@@ -165,7 +165,7 @@ export class SimpleCompletionModel {
} else {
// by default match `word` against the `label`
const match = scoreFn(word, wordLow, wordPos, item.completion.completionText ?? item.completion.label, item.labelLow, 0, this._fuzzyScoreOptions);
const match = scoreFn(word, wordLow, wordPos, item.completion.label, item.labelLow, 0, this._fuzzyScoreOptions);
if (!match) {
continue; // NO match
}
@@ -177,7 +177,7 @@ export class SimpleCompletionModel {
target.push(item);
// update stats
labelLengths.push((item.completion.completionText ?? item.completion.label).length);
labelLengths.push(item.completion.label.length);
}
this._filteredItems = target.sort((a, b) => b.score[0] - a.score[0]);