- normalizing paths used as snapshot cache keys (#6)

This commit is contained in:
ezolenko 2017-04-02 22:40:09 -06:00
parent f4cd9b488e
commit 65fb8834ed
4 changed files with 24 additions and 1 deletions

View File

@ -127,12 +127,14 @@ var LanguageServiceHost = (function () {
this.versions = {};
};
LanguageServiceHost.prototype.setSnapshot = function (fileName, data) {
fileName = this.normalize(fileName);
var snapshot = ts.ScriptSnapshot.fromString(data);
this.snapshots[fileName] = snapshot;
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
return snapshot;
};
LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) {
fileName = this.normalize(fileName);
if (_.has(this.snapshots, fileName))
return this.snapshots[fileName];
if (fs.existsSync(fileName)) {
@ -146,6 +148,7 @@ var LanguageServiceHost = (function () {
return this.cwd;
};
LanguageServiceHost.prototype.getScriptVersion = function (fileName) {
fileName = this.normalize(fileName);
return (this.versions[fileName] || 0).toString();
};
LanguageServiceHost.prototype.getScriptFileNames = function () {
@ -157,6 +160,9 @@ var LanguageServiceHost = (function () {
LanguageServiceHost.prototype.getDefaultLibFileName = function (opts) {
return ts.getDefaultLibFilePath(opts);
};
LanguageServiceHost.prototype.normalize = function (fileName) {
return fileName.split("\\").join("/");
};
return LanguageServiceHost;
}());

View File

@ -133,12 +133,14 @@ var LanguageServiceHost = (function () {
this.versions = {};
};
LanguageServiceHost.prototype.setSnapshot = function (fileName, data) {
fileName = this.normalize(fileName);
var snapshot = ScriptSnapshot.fromString(data);
this.snapshots[fileName] = snapshot;
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
return snapshot;
};
LanguageServiceHost.prototype.getScriptSnapshot = function (fileName) {
fileName = this.normalize(fileName);
if (has(this.snapshots, fileName))
return this.snapshots[fileName];
if (existsSync(fileName)) {
@ -152,6 +154,7 @@ var LanguageServiceHost = (function () {
return this.cwd;
};
LanguageServiceHost.prototype.getScriptVersion = function (fileName) {
fileName = this.normalize(fileName);
return (this.versions[fileName] || 0).toString();
};
LanguageServiceHost.prototype.getScriptFileNames = function () {
@ -163,6 +166,9 @@ var LanguageServiceHost = (function () {
LanguageServiceHost.prototype.getDefaultLibFileName = function (opts) {
return getDefaultLibFilePath(opts);
};
LanguageServiceHost.prototype.normalize = function (fileName) {
return fileName.split("\\").join("/");
};
return LanguageServiceHost;
}());

View File

@ -20,6 +20,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost
public setSnapshot(fileName: string, data: string): ts.IScriptSnapshot
{
fileName = this.normalize(fileName);
let snapshot = ts.ScriptSnapshot.fromString(data);
this.snapshots[fileName] = snapshot;
this.versions[fileName] = (this.versions[fileName] || 0) + 1;
@ -28,6 +30,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost
public getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined
{
fileName = this.normalize(fileName);
if (_.has(this.snapshots, fileName))
return this.snapshots[fileName];
@ -48,6 +52,8 @@ export class LanguageServiceHost implements ts.LanguageServiceHost
public getScriptVersion(fileName: string)
{
fileName = this.normalize(fileName);
return (this.versions[fileName] || 0).toString();
}
@ -65,4 +71,9 @@ export class LanguageServiceHost implements ts.LanguageServiceHost
{
return ts.getDefaultLibFilePath(opts);
}
private normalize(fileName: string)
{
return fileName.split("\\").join("/");
}
}

View File

@ -11,7 +11,7 @@
"listFiles": true,
"pretty": true,
"moduleResolution": "node",
"noEmitOnError": true,
"noEmitOnError": false,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true