Fixing range for primary edit (#59369)

This commit is contained in:
navya9singh
2024-07-22 17:14:35 -07:00
committed by GitHub
parent 8a0e47e242
commit b04c8a0edd
3 changed files with 367 additions and 2 deletions

View File

@@ -2319,7 +2319,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
runWithTemporaryFileUpdate(rootFile: string, updatedText: string, cb: (updatedProgram: Program, originalProgram: Program | undefined, updatedFile: SourceFile) => void) {
const originalProgram = this.program;
const rootSourceFile = Debug.checkDefined(this.program?.getSourceFile(rootFile), "Expected file to be part of program");
const originalText = Debug.checkDefined(rootSourceFile.getText());
const originalText = Debug.checkDefined(rootSourceFile.getFullText());
this.getScriptInfo(rootFile)?.editContent(0, originalText.length, updatedText);
this.updateGraph();
@@ -2327,7 +2327,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
cb(this.program!, originalProgram, (this.program?.getSourceFile(rootFile))!);
}
finally {
this.getScriptInfo(rootFile)?.editContent(0, this.program!.getSourceFile(rootFile)!.getText().length, originalText);
this.getScriptInfo(rootFile)?.editContent(0, updatedText.length, originalText);
}
}