mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-30 17:28:52 -05:00
💄
This commit is contained in:
@@ -35,13 +35,13 @@ export class SuggestWidgetPreviewModel extends BaseGhostTextWidgetModel {
|
||||
super(editor);
|
||||
|
||||
this._register(this.suggestionInlineCompletionSource.onDidChange(() => {
|
||||
this.updateCacheSoon.schedule();
|
||||
|
||||
const suggestWidgetState = this.suggestionInlineCompletionSource.state;
|
||||
if (!suggestWidgetState) {
|
||||
this.minReservedLineCount = 0;
|
||||
}
|
||||
|
||||
this.updateCacheSoon.schedule();
|
||||
|
||||
const newGhostText = this.ghostText;
|
||||
if (newGhostText) {
|
||||
this.minReservedLineCount = Math.max(this.minReservedLineCount, sum(newGhostText.parts.map(p => p.lines.length - 1)));
|
||||
@@ -119,40 +119,6 @@ export class SuggestWidgetPreviewModel extends BaseGhostTextWidgetModel {
|
||||
}
|
||||
|
||||
public override get ghostText(): GhostText | undefined {
|
||||
function lengthOfLongestCommonPrefix(str1: string, str2: string): number {
|
||||
let i = 0;
|
||||
while (i < str1.length && i < str2.length && str1[i] === str2[i]) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
function lengthOfLongestCommonSuffix(str1: string, str2: string): number {
|
||||
let i = 0;
|
||||
while (i < str1.length && i < str2.length && str1[str1.length - i - 1] === str2[str2.length - i - 1]) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
function minimizeInlineCompletion(model: ITextModel, inlineCompletion: NormalizedInlineCompletion | undefined): NormalizedInlineCompletion | undefined {
|
||||
if (!inlineCompletion) {
|
||||
return inlineCompletion;
|
||||
}
|
||||
const valueToReplace = model.getValueInRange(inlineCompletion.range);
|
||||
const commonPrefixLength = lengthOfLongestCommonPrefix(valueToReplace, inlineCompletion.text);
|
||||
const startOffset = model.getOffsetAt(inlineCompletion.range.getStartPosition()) + commonPrefixLength;
|
||||
const start = model.getPositionAt(startOffset);
|
||||
|
||||
const commonSuffixLength = lengthOfLongestCommonSuffix(valueToReplace, inlineCompletion.text);
|
||||
const end = model.getPositionAt(Math.max(startOffset, model.getOffsetAt(inlineCompletion.range.getEndPosition()) - commonSuffixLength));
|
||||
|
||||
return {
|
||||
range: Range.fromPositions(start, end),
|
||||
text: inlineCompletion.text.substr(commonPrefixLength, inlineCompletion.text.length - commonPrefixLength - commonSuffixLength),
|
||||
};
|
||||
}
|
||||
|
||||
const suggestWidgetState = this.suggestionInlineCompletionSource.state;
|
||||
|
||||
const originalInlineCompletion = minimizeInlineCompletion(this.editor.getModel()!, suggestWidgetState?.selectedItemAsInlineCompletion);
|
||||
@@ -189,3 +155,37 @@ export class SuggestWidgetPreviewModel extends BaseGhostTextWidgetModel {
|
||||
function sum(arr: number[]): number {
|
||||
return arr.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
|
||||
function lengthOfLongestCommonPrefix(str1: string, str2: string): number {
|
||||
let i = 0;
|
||||
while (i < str1.length && i < str2.length && str1[i] === str2[i]) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
function lengthOfLongestCommonSuffix(str1: string, str2: string): number {
|
||||
let i = 0;
|
||||
while (i < str1.length && i < str2.length && str1[str1.length - i - 1] === str2[str2.length - i - 1]) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
function minimizeInlineCompletion(model: ITextModel, inlineCompletion: NormalizedInlineCompletion | undefined): NormalizedInlineCompletion | undefined {
|
||||
if (!inlineCompletion) {
|
||||
return inlineCompletion;
|
||||
}
|
||||
const valueToReplace = model.getValueInRange(inlineCompletion.range);
|
||||
const commonPrefixLength = lengthOfLongestCommonPrefix(valueToReplace, inlineCompletion.text);
|
||||
const startOffset = model.getOffsetAt(inlineCompletion.range.getStartPosition()) + commonPrefixLength;
|
||||
const start = model.getPositionAt(startOffset);
|
||||
|
||||
const commonSuffixLength = lengthOfLongestCommonSuffix(valueToReplace, inlineCompletion.text);
|
||||
const end = model.getPositionAt(Math.max(startOffset, model.getOffsetAt(inlineCompletion.range.getEndPosition()) - commonSuffixLength));
|
||||
|
||||
return {
|
||||
range: Range.fromPositions(start, end),
|
||||
text: inlineCompletion.text.substr(commonPrefixLength, inlineCompletion.text.length - commonPrefixLength - commonSuffixLength),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user