in server/src/session.ts [756:783]
private onDidChangeTextDocument(params: lsp.DidChangeTextDocumentParams): void {
const {contentChanges, textDocument} = params;
const filePath = uriToFilePath(textDocument.uri);
if (!filePath) {
return;
}
this.openFiles.update(filePath);
const scriptInfo = this.projectService.getScriptInfo(filePath);
if (!scriptInfo) {
this.error(`Failed to get script info for ${filePath}`);
return;
}
for (const change of contentChanges) {
if ('range' in change) {
const [start, end] = lspRangeToTsPositions(scriptInfo, change.range);
scriptInfo.editContent(start, end, change.text);
} else {
// New text is considered to be the full content of the document.
scriptInfo.editContent(0, scriptInfo.getSnapshot().getLength(), change.text);
}
}
const project = this.getDefaultProjectForScriptInfo(scriptInfo);
if (!project || !project.languageServiceEnabled) {
return;
}
this.requestDiagnosticsOnOpenOrChangeFile(scriptInfo.fileName, `Changing ${filePath}`);
}