Skip to content

ScriptInfo versioning improvements #53001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 1, 2023
  •  
  •  
  •  
13 changes: 6 additions & 7 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ import {
ProjectKind,
ProjectOptions,
ScriptInfo,
ScriptInfoVersion,
ServerHost,
Session,
SetTypings,
Expand Down Expand Up @@ -870,7 +869,7 @@ export class ProjectService {
* it does not reset when creating script info again
* (and could have potentially collided with version where contents mismatch)
*/
private readonly filenameToScriptInfoVersion = new Map<string, ScriptInfoVersion>();
private readonly filenameToScriptInfoVersion = new Map<string, number>();
// Set of all '.js' files ever opened.
private readonly allJsFilesForOpenFileTelemetry = new Map<string, true>();

Expand Down Expand Up @@ -1623,7 +1622,7 @@ export class ProjectService {

private removeProject(project: Project) {
this.logger.info("`remove Project::");
project.print(/*writeProjectFileNames*/ true);
project.print(/*writeProjectFileNames*/ true, /*writeFileExplaination*/ true, /*writeFileVersionAndText*/ false);

project.close();
if (Debug.shouldAssert(AssertionLevel.Normal)) {
Expand Down Expand Up @@ -1812,7 +1811,7 @@ export class ProjectService {

private deleteScriptInfo(info: ScriptInfo) {
this.filenameToScriptInfo.delete(info.path);
this.filenameToScriptInfoVersion.set(info.path, info.getVersion());
this.filenameToScriptInfoVersion.set(info.path, info.textStorage.version);
const realpath = info.getRealpathIfDifferent();
if (realpath) {
this.realpathToScriptInfos!.remove(realpath, info); // TODO: GH#18217
Expand Down Expand Up @@ -3001,7 +3000,7 @@ export class ProjectService {
// Opening closed script info
// either it was created just now, or was part of projects but was closed
this.stopWatchingScriptInfo(info);
info.open(fileContent!);
info.open(fileContent);
if (hasMixedContent) {
info.registerFileUpdate();
}
Expand Down Expand Up @@ -3075,7 +3074,7 @@ export class ProjectService {
const documentPositionMapper = getDocumentPositionMapper(
{ getCanonicalFileName: this.toCanonicalFileName, log: s => this.logger.info(s), getSourceFileLike: f => this.getSourceFileLike(f, projectName, declarationInfo) },
declarationInfo.fileName,
declarationInfo.getLineInfo(),
declarationInfo.textStorage.getLineInfo(),
readMapFile
);
readMapFile = undefined; // Remove ref to project
Expand Down Expand Up @@ -4493,5 +4492,5 @@ export function isConfigFile(config: ScriptInfoOrConfig): config is TsConfigSour
}

function printProjectWithoutFileNames(project: Project) {
project.print(/*writeProjectFileNames*/ false);
project.print(/*writeProjectFileNames*/ false, /*writeFileExplaination*/ false, /*writeFileVersionAndText*/ false);
}
37 changes: 28 additions & 9 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function countEachFileTypes(infos: ScriptInfo[], includeSizes = false): F
deferred: 0, deferredSize: 0,
};
for (const info of infos) {
const fileSize = includeSizes ? info.getTelemetryFileSize() : 0;
const fileSize = includeSizes ? info.textStorage.getTelemetryFileSize() : 0;
switch (info.scriptKind) {
case ScriptKind.JS:
result.js += 1;
Expand Down Expand Up @@ -1461,8 +1461,16 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
const elapsed = timestamp() - start;
this.sendPerformanceEvent("UpdateGraph", elapsed);
this.writeLog(`Finishing updateGraphWorker: Project: ${this.getProjectName()} Version: ${this.getProjectVersion()} structureChanged: ${hasNewProgram}${this.program ? ` structureIsReused:: ${(ts as any).StructureIsReused[this.program.structureIsReused]}` : ""} Elapsed: ${elapsed}ms`);
if (this.hasAddedorRemovedFiles) {
this.print(/*writeProjectFileNames*/ true);
if (this.projectService.logger.isTestLogger) {
if (this.program !== oldProgram) {
this.print(/*writeProjectFileNames*/ true, this.hasAddedorRemovedFiles, /*writeFileVersionAndText*/ true);
}
else {
this.writeLog(`Same program as before`);
}
}
else if (this.hasAddedorRemovedFiles) {
this.print(/*writeProjectFileNames*/ true, /*writeFileExplaination*/ true, /*writeFileVersionAndText*/ false);
}
else if (this.program !== oldProgram) {
this.writeLog(`Different program with same set of files`);
Expand Down Expand Up @@ -1589,27 +1597,38 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
}

filesToString(writeProjectFileNames: boolean) {
return this.filesToStringWorker(writeProjectFileNames, /*writeFileExplaination*/ true, /*writeFileVersionAndText*/ false);
}

/** @internal */
private filesToStringWorker(writeProjectFileNames: boolean, writeFileExplaination: boolean, writeFileVersionAndText: boolean) {
if (this.isInitialLoadPending()) return "\tFiles (0) InitialLoadPending\n";
if (!this.program) return "\tFiles (0) NoProgram\n";
const sourceFiles = this.program.getSourceFiles();
let strBuilder = `\tFiles (${sourceFiles.length})\n`;
if (writeProjectFileNames) {
for (const file of sourceFiles) {
strBuilder += `\t${file.fileName}\n`;
strBuilder += `\t${file.fileName}${writeFileVersionAndText?` ${file.version} ${JSON.stringify(file.text)}` : ""}\n`;
}
if (writeFileExplaination) {
strBuilder += "\n\n";
explainFiles(this.program, s => strBuilder += `\t${s}\n`);
}
strBuilder += "\n\n";
explainFiles(this.program, s => strBuilder += `\t${s}\n`);
}
return strBuilder;
}

/** @internal */
print(writeProjectFileNames: boolean) {
print(writeProjectFileNames: boolean, writeFileExplaination: boolean, writeFileVersionAndText: boolean) {
this.writeLog(`Project '${this.projectName}' (${ProjectKind[this.projectKind]})`);
this.writeLog(this.filesToString(writeProjectFileNames && this.projectService.logger.hasLevel(LogLevel.verbose)));
this.writeLog(this.filesToStringWorker(
writeProjectFileNames && this.projectService.logger.hasLevel(LogLevel.verbose),
writeFileExplaination && this.projectService.logger.hasLevel(LogLevel.verbose),
writeFileVersionAndText && this.projectService.logger.hasLevel(LogLevel.verbose),
));
this.writeLog("-----------------------------------------------");
if (this.autoImportProviderHost) {
this.autoImportProviderHost.print(/*writeProjectFileNames*/ false);
this.autoImportProviderHost.print(/*writeProjectFileNames*/ false, /*writeFileExplaination*/ false, /*writeFileVersionAndText*/ false);
}
}

Expand Down
Loading