mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 11:10:48 +00:00
Adds leftTrim function, fixes bug in inlineCompletionToGhostText.
This commit is contained in:
parent
3a259a7a6a
commit
79048992ef
1 changed files with 23 additions and 11 deletions
|
@ -428,23 +428,35 @@ export interface NormalizedInlineCompletion extends InlineCompletion {
|
||||||
range: Range;
|
range: Range;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function leftTrim(str: string): string {
|
||||||
|
return str.replace(/^\s+/, '');
|
||||||
|
}
|
||||||
|
|
||||||
export function inlineCompletionToGhostText(inlineCompletion: NormalizedInlineCompletion, textModel: ITextModel): GhostText | undefined {
|
export function inlineCompletionToGhostText(inlineCompletion: NormalizedInlineCompletion, textModel: ITextModel): GhostText | undefined {
|
||||||
// This is a single line string
|
// This is a single line string
|
||||||
const valueToBeReplaced = textModel.getValueInRange(inlineCompletion.range);
|
const valueToBeReplaced = textModel.getValueInRange(inlineCompletion.range);
|
||||||
// valueToBeReplaced === ws1 + valueToBeReplacedTrimmed
|
|
||||||
const valueToBeReplacedTrimmed = valueToBeReplaced.trimLeft();
|
let remainingInsertText: string;
|
||||||
// inlineCompletion.text === ws2 + insertTextTrimmed
|
|
||||||
const insertTextTrimmed = inlineCompletion.text.trimLeft();
|
// Consider these cases
|
||||||
if (!insertTextTrimmed.startsWith(valueToBeReplacedTrimmed)) {
|
// valueToBeReplaced -> inlineCompletion.text
|
||||||
// if ws1 === ws2, then inlineCompletion.text does not start with valueToBeReplaced
|
// "\t\tfoo" -> "\t\tfoobar" (+"bar")
|
||||||
return undefined;
|
// "\t" -> "\t\tfoobar" (+"\tfoobar")
|
||||||
|
// "\t\tfoo" -> "\t\t\tfoobar" (+"\t", +"bar")
|
||||||
|
// "\t\tfoo" -> "\tfoobar" (-"\t", +"\bar")
|
||||||
|
|
||||||
|
if (inlineCompletion.text.startsWith(valueToBeReplaced)) {
|
||||||
|
remainingInsertText = inlineCompletion.text.substr(valueToBeReplaced.length);
|
||||||
|
} else {
|
||||||
|
const valueToBeReplacedTrimmed = leftTrim(valueToBeReplaced);
|
||||||
|
const insertTextTrimmed = leftTrim(inlineCompletion.text);
|
||||||
|
if (!insertTextTrimmed.startsWith(valueToBeReplacedTrimmed)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
remainingInsertText = insertTextTrimmed.substr(valueToBeReplacedTrimmed.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
const position = inlineCompletion.range.getEndPosition();
|
const position = inlineCompletion.range.getEndPosition();
|
||||||
const remainingInsertText = insertTextTrimmed.substr(valueToBeReplacedTrimmed.length);
|
|
||||||
// if ws1 === ws2, then
|
|
||||||
// remainingInsertText === (ws2 + insertTextTrimmed).substr(ws1 + valueToBeReplacedTrimmed.length);
|
|
||||||
// === inlineCompletion.text.substr(valueToBeReplaced.length)
|
|
||||||
|
|
||||||
const lines = strings.splitLines(remainingInsertText);
|
const lines = strings.splitLines(remainingInsertText);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue