add optional 'getProjectVersion' method to perform fast up-to-date checks

This commit is contained in:
Vladimir Matveev 2015-05-12 10:57:55 -07:00
parent eaee9ec600
commit 2252e3045c
2 changed files with 24 additions and 0 deletions

View file

@ -949,6 +949,7 @@ module ts {
export interface LanguageServiceHost {
getCompilationSettings(): CompilerOptions;
getNewLine?(): string;
getProjectVersion?(): string;
getScriptFileNames(): string[];
getScriptVersion(fileName: string): string;
getScriptSnapshot(fileName: string): IScriptSnapshot;
@ -2353,6 +2354,7 @@ module ts {
let syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host);
let ruleProvider: formatting.RulesProvider;
let program: Program;
let lastProjectVersion: string;
let useCaseSensitivefileNames = false;
let cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken());
@ -2392,6 +2394,18 @@ module ts {
}
function synchronizeHostData(): void {
// perform fast check if host supports it
if (host.getProjectVersion) {
let hostProjectVersion = host.getProjectVersion();
if (hostProjectVersion) {
if (lastProjectVersion === hostProjectVersion) {
return;
}
lastProjectVersion = hostProjectVersion;
}
}
// Get a fresh cache of the host information
let hostCache = new HostCache(host, getCanonicalFileName);

View file

@ -55,6 +55,7 @@ module ts {
getCurrentDirectory(): string;
getDefaultLibFileName(options: string): string;
getNewLine?(): string;
getProjectVersion?(): string;
}
/** Public interface of the the of a config service shim instance.*/
@ -260,6 +261,15 @@ module ts {
this.shimHost.error(s);
}
public getProjectVersion(): string {
if (!this.shimHost.getProjectVersion) {
// shimmed host does not support getProjectVersion
return undefined;
}
return this.shimHost.getProjectVersion();
}
public getCompilationSettings(): CompilerOptions {
var settingsJson = this.shimHost.getCompilationSettings();
if (settingsJson == null || settingsJson == "") {