Skip to content

Commit 6212132

Browse files
Update LKG
1 parent bbb5faf commit 6212132

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

lib/typescript.js

+33-18
Original file line numberDiff line numberDiff line change
@@ -179399,13 +179399,13 @@ function pasteEditsProvider(targetFile, pastedText, pasteLocations, copiedFrom,
179399179399
function pasteEdits(targetFile, pastedText, pasteLocations, copiedFrom, host, preferences, formatContext, cancellationToken, changes) {
179400179400
let actualPastedText;
179401179401
if (pastedText.length !== pasteLocations.length) {
179402-
actualPastedText = pastedText.length === 1 ? pastedText : [pastedText.join("\n")];
179402+
actualPastedText = pastedText.length === 1 ? pastedText[0] : pastedText.join(getNewLineOrDefaultFromHost(formatContext.host, formatContext.options));
179403179403
}
179404179404
const statements = [];
179405179405
let newText = targetFile.text;
179406179406
for (let i = pasteLocations.length - 1; i >= 0; i--) {
179407179407
const { pos, end } = pasteLocations[i];
179408-
newText = actualPastedText ? newText.slice(0, pos) + actualPastedText[0] + newText.slice(end) : newText.slice(0, pos) + pastedText[i] + newText.slice(end);
179408+
newText = actualPastedText ? newText.slice(0, pos) + actualPastedText + newText.slice(end) : newText.slice(0, pos) + pastedText[i] + newText.slice(end);
179409179409
}
179410179410
let importAdder;
179411179411
Debug.checkDefined(host.runWithTemporaryFileUpdate).call(host, targetFile.fileName, newText, (updatedProgram, originalProgram, updatedFile) => {
@@ -179436,22 +179436,37 @@ function pasteEdits(targetFile, pastedText, pasteLocations, copiedFrom, host, pr
179436179436
preferences,
179437179437
formatContext
179438179438
};
179439-
forEachChild(updatedFile, function cb(node) {
179440-
if (isIdentifier(node) && !(originalProgram == null ? void 0 : originalProgram.getTypeChecker().resolveName(
179441-
node.text,
179442-
node,
179443-
-1 /* All */,
179444-
/*excludeGlobals*/
179445-
false
179446-
))) {
179447-
importAdder.addImportForUnresolvedIdentifier(
179448-
context,
179439+
let offset = 0;
179440+
pasteLocations.forEach((location, i) => {
179441+
const oldTextLength = location.end - location.pos;
179442+
const textToBePasted = actualPastedText ?? pastedText[i];
179443+
const startPos = location.pos + offset;
179444+
const endPos = startPos + textToBePasted.length;
179445+
const range = { pos: startPos, end: endPos };
179446+
offset += textToBePasted.length - oldTextLength;
179447+
const enclosingNode = findAncestor(
179448+
getTokenAtPosition(context.sourceFile, range.pos),
179449+
(ancestorNode) => rangeContainsRange(ancestorNode, range)
179450+
);
179451+
if (!enclosingNode) return;
179452+
forEachChild(enclosingNode, function importUnresolvedIdentifiers(node) {
179453+
const isImportCandidate = isIdentifier(node) && rangeContainsPosition(range, node.getStart(updatedFile)) && !(updatedProgram == null ? void 0 : updatedProgram.getTypeChecker().resolveName(
179454+
node.text,
179449179455
node,
179450-
/*useAutoImportProvider*/
179451-
true
179452-
);
179453-
}
179454-
node.forEachChild(cb);
179456+
-1 /* All */,
179457+
/*excludeGlobals*/
179458+
false
179459+
));
179460+
if (isImportCandidate) {
179461+
return importAdder.addImportForUnresolvedIdentifier(
179462+
context,
179463+
node,
179464+
/*useAutoImportProvider*/
179465+
true
179466+
);
179467+
}
179468+
node.forEachChild(importUnresolvedIdentifiers);
179469+
});
179455179470
});
179456179471
}
179457179472
importAdder.writeFixes(changes, getQuotePreference(copiedFrom ? copiedFrom.file : targetFile, preferences));
@@ -179463,7 +179478,7 @@ function pasteEdits(targetFile, pastedText, pasteLocations, copiedFrom, host, pr
179463179478
changes.replaceRangeWithText(
179464179479
targetFile,
179465179480
{ pos: paste.pos, end: paste.end },
179466-
actualPastedText ? actualPastedText[0] : pastedText[i]
179481+
actualPastedText ?? pastedText[i]
179467179482
);
179468179483
});
179469179484
}

0 commit comments

Comments
 (0)