Cache the latest source file from document registry so we can keep it alive when script info is orphan

This commit is contained in:
Sheetal Nandi
2018-05-15 17:10:40 -07:00
parent 59d19251cf
commit 81ca6502ea
4 changed files with 60 additions and 8 deletions

View File

@@ -475,7 +475,7 @@ namespace ts.server {
extraFileExtensions: []
};
this.documentRegistry = createDocumentRegistry(this.host.useCaseSensitiveFileNames, this.currentDirectory);
this.documentRegistry = createDocumentRegistryInternal(this.host.useCaseSensitiveFileNames, this.currentDirectory, this);
const watchLogLevel = this.logger.hasLevel(LogLevel.verbose) ? WatchLogLevel.Verbose :
this.logger.loggingEnabled() ? WatchLogLevel.TriggerOnly : WatchLogLevel.None;
const log: (s: string) => void = watchLogLevel !== WatchLogLevel.None ? (s => this.logger.info(s)) : noop;
@@ -496,6 +496,19 @@ namespace ts.server {
return getNormalizedAbsolutePath(fileName, this.host.getCurrentDirectory());
}
/*@internal*/
setDocument(key: DocumentRegistryBucketKey, path: Path, sourceFile: SourceFile) {
const info = this.getScriptInfoForPath(path);
Debug.assert(!!info);
info.cacheSourceFile = { key, sourceFile };
}
/*@internal*/
getDocument(key: DocumentRegistryBucketKey, path: Path) {
const info = this.getScriptInfoForPath(path);
return info && info.cacheSourceFile && info.cacheSourceFile.key === key && info.cacheSourceFile.sourceFile;
}
/* @internal */
ensureInferredProjectsUpToDate_TestOnly() {
this.ensureProjectStructuresUptoDate();

View File

@@ -202,6 +202,12 @@ namespace ts.server {
return fileName[0] === "^" || getBaseFileName(fileName)[0] === "^";
}
/*@internal*/
export interface DocumentRegistrySourceFileCache {
key: DocumentRegistryBucketKey;
sourceFile: SourceFile;
}
export class ScriptInfo {
/**
* All projects that include this file
@@ -221,6 +227,9 @@ namespace ts.server {
/** Set to real path if path is different from info.path */
private realpath: Path | undefined;
/*@internal*/
cacheSourceFile: DocumentRegistrySourceFileCache;
constructor(
private readonly host: ServerHost,
readonly fileName: NormalizedPath,