Skip to content

Commit

Permalink
Update LKG
Browse files Browse the repository at this point in the history
  • Loading branch information
typescript-bot committed Aug 20, 2024
1 parent bbb5faf commit 6212132
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -179399,13 +179399,13 @@ function pasteEditsProvider(targetFile, pastedText, pasteLocations, copiedFrom,
function pasteEdits(targetFile, pastedText, pasteLocations, copiedFrom, host, preferences, formatContext, cancellationToken, changes) {
let actualPastedText;
if (pastedText.length !== pasteLocations.length) {
actualPastedText = pastedText.length === 1 ? pastedText : [pastedText.join("\n")];
actualPastedText = pastedText.length === 1 ? pastedText[0] : pastedText.join(getNewLineOrDefaultFromHost(formatContext.host, formatContext.options));
}
const statements = [];
let newText = targetFile.text;
for (let i = pasteLocations.length - 1; i >= 0; i--) {
const { pos, end } = pasteLocations[i];
newText = actualPastedText ? newText.slice(0, pos) + actualPastedText[0] + newText.slice(end) : newText.slice(0, pos) + pastedText[i] + newText.slice(end);
newText = actualPastedText ? newText.slice(0, pos) + actualPastedText + newText.slice(end) : newText.slice(0, pos) + pastedText[i] + newText.slice(end);
}
let importAdder;
Debug.checkDefined(host.runWithTemporaryFileUpdate).call(host, targetFile.fileName, newText, (updatedProgram, originalProgram, updatedFile) => {
Expand Down Expand Up @@ -179436,22 +179436,37 @@ function pasteEdits(targetFile, pastedText, pasteLocations, copiedFrom, host, pr
preferences,
formatContext
};
forEachChild(updatedFile, function cb(node) {
if (isIdentifier(node) && !(originalProgram == null ? void 0 : originalProgram.getTypeChecker().resolveName(
node.text,
node,
-1 /* All */,
/*excludeGlobals*/
false
))) {
importAdder.addImportForUnresolvedIdentifier(
context,
let offset = 0;
pasteLocations.forEach((location, i) => {
const oldTextLength = location.end - location.pos;
const textToBePasted = actualPastedText ?? pastedText[i];
const startPos = location.pos + offset;
const endPos = startPos + textToBePasted.length;
const range = { pos: startPos, end: endPos };
offset += textToBePasted.length - oldTextLength;
const enclosingNode = findAncestor(
getTokenAtPosition(context.sourceFile, range.pos),
(ancestorNode) => rangeContainsRange(ancestorNode, range)
);
if (!enclosingNode) return;
forEachChild(enclosingNode, function importUnresolvedIdentifiers(node) {
const isImportCandidate = isIdentifier(node) && rangeContainsPosition(range, node.getStart(updatedFile)) && !(updatedProgram == null ? void 0 : updatedProgram.getTypeChecker().resolveName(
node.text,
node,
/*useAutoImportProvider*/
true
);
}
node.forEachChild(cb);
-1 /* All */,
/*excludeGlobals*/
false
));
if (isImportCandidate) {
return importAdder.addImportForUnresolvedIdentifier(
context,
node,
/*useAutoImportProvider*/
true
);
}
node.forEachChild(importUnresolvedIdentifiers);
});
});
}
importAdder.writeFixes(changes, getQuotePreference(copiedFrom ? copiedFrom.file : targetFile, preferences));
Expand All @@ -179463,7 +179478,7 @@ function pasteEdits(targetFile, pastedText, pasteLocations, copiedFrom, host, pr
changes.replaceRangeWithText(
targetFile,
{ pos: paste.pos, end: paste.end },
actualPastedText ? actualPastedText[0] : pastedText[i]
actualPastedText ?? pastedText[i]
);
});
}
Expand Down

0 comments on commit 6212132

Please sign in to comment.