fixing failing tests

This commit is contained in:
Aiday Marlen Kyzy 2024-02-12 09:31:33 +01:00
parent 92143ea2dd
commit c7335f45ec
No known key found for this signature in database
GPG key ID: 24A8B53DBD26FF4E
2 changed files with 4 additions and 47 deletions

View file

@ -479,64 +479,23 @@ function getEndPositionsAfterApplying(edits: readonly SingleTextEdit[]): Positio
export function getSecondaryEdits(textModel: ITextModel, positions: readonly Position[], primaryEdit: SingleTextEdit): SingleTextEdit[] {
const primaryPosition = positions[0];
const secondaryPositions = positions.slice(1);
console.log('positions : ', JSON.stringify(positions));
// replaced text is not calculated correctly
// only works if primary edit line number
// Need to take all the that is replaced in the primary edit range
const replacedTextAfterPrimaryCursor = textModel.getValueInRange(Range.fromPositions(primaryPosition, primaryEdit.range.getEndPosition()));
console.log('replacedTextAfterPrimaryCursor : ', JSON.stringify(replacedTextAfterPrimaryCursor));
console.log('primaryEdit : ', JSON.stringify(primaryEdit));
// There is an error below too, the secondary edit text is the text after the cursor to the right of it, that needs to be added
// in the test case we would want to add ') {\n\treturn 0;\n}' because we already have fib( written.
// Before it worked because we would have the cursor at the end of function fib(, now the cursor is on the line below it
// Or at the very least, we should insert 'return 0;\n}' because this is to the right of the cursor at the primary cursor position
// So need to find the primary position within the edit, and find all the text to the right of it. The primary position will not necessarily be on the first
// line of the edit text.
// We suppose that the primaryEdit.range always touches the primaryPosition in some manner
// could find the offset of primary position, the offset of the primary edit start and find thus the secondary edit text
// const _offsetPrimaryPosition = textModel.getOffsetAt(primaryPosition);
// const _offsetPrimaryEditStart = textModel.getOffsetAt(primaryEdit.range.getStartPosition());
// console.log('_offsetPrimaryPosition : ', _offsetPrimaryPosition);
// console.log('_offsetPrimaryEditStart : ', _offsetPrimaryEditStart);
// Find offset in a different way
// Split the lines of the text, place it in the context of the whole text
// Find the position in the text where the initial position would be, exactly as is, find the offset, and take the substring
const newCol = primaryPosition.lineNumber - primaryEdit.range.startLineNumber;
const newLine = newCol === 0 ? primaryPosition.column - primaryEdit.range.startColumn : primaryPosition.column;
const newLine = primaryPosition.lineNumber - primaryEdit.range.startLineNumber;
const newCol = newLine === 0 ? primaryPosition.column - primaryEdit.range.startColumn + 1 : primaryPosition.column;
let text = '';
const _splitLines = splitLines(primaryEdit.text);
for (let i = newLine; i < _splitLines.length; i++) {
if (i === newLine) {
text += _splitLines[i].substring(newCol) + '\n';
text += _splitLines[i].substring(newCol - 1) + (i === _splitLines.length - 1 ? '' : '\n');
} else {
text += _splitLines[i] + '\n';
text += _splitLines[i] + (i === _splitLines.length - 1 ? '' : '\n');
}
}
console.log('text : ', text);
const secondaryEditText = text;
// primaryEdit.text.substring(primaryPosition.column - primaryEdit.range.startColumn);
// console.log('secondaryEditText : ', JSON.stringify(secondaryEditText));
return secondaryPositions.map(pos => {
console.log('pos : ', JSON.stringify(pos));
// Maybe taking the substring on the line content specifically is not enough, so we need to actually take it until the range end, because that is the text we would replace
// the range end is not necessarily on the end of that line either
// const textAfterSecondaryCursor = textModel
// .getLineContent(pos.lineNumber)
// .substring(pos.column - 1);
const textAfterSecondaryCursor = textModel.getValueInRange(Range.fromPositions(pos, primaryEdit.range.getEndPosition()));
console.log('textAfterSecondaryCursor : ', textAfterSecondaryCursor);
const l = commonPrefixLength(replacedTextAfterPrimaryCursor, textAfterSecondaryCursor);
console.log('l : ', l);
const range = Range.fromPositions(pos, pos.delta(0, l));
console.log('range : ', JSON.stringify(range));
return new SingleTextEdit(range, secondaryEditText);
});
}

View file

@ -57,7 +57,6 @@ suite('inlineCompletionModel', () => {
'}'
].join('\n')
)]);
console.log('secondaryEdits : ', JSON.stringify(secondaryEdits));
textModel.dispose();
});
@ -88,7 +87,6 @@ suite('inlineCompletionModel', () => {
'}'
].join('\n')
)]);
console.log('secondaryEdits : ', JSON.stringify(secondaryEdits));
textModel.dispose();
});
});