Add a new scriptSnapshot and use the shim as a wrapper

This commit is contained in:
Mohamed Hegazy
2015-02-02 20:23:54 -08:00
parent d8fb8a967f
commit f56e7ea743

View File

@@ -1,5 +1,6 @@
/// <reference path='..\services\services.ts' />
/// <reference path='..\services\shims.ts' />
/// <reference path='harness.ts' />
module Harness.LanguageService {
export class ScriptInfo {
@@ -54,15 +55,10 @@ module Harness.LanguageService {
}
}
class ScriptSnapshotShim implements ts.ScriptSnapshotShim {
private lineMap: number[] = null;
private textSnapshot: string;
private version: number;
constructor(private scriptInfo: ScriptInfo) {
this.textSnapshot = scriptInfo.content;
this.version = scriptInfo.version;
}
class ScriptSnapshot implements ts.IScriptSnapshot {
public textSnapshot: string;
public version: number;
constructor(public scriptInfo: ScriptInfo) {
this.textSnapshot = scriptInfo.content;
this.version = scriptInfo.version;
@@ -72,9 +68,28 @@ module Harness.LanguageService {
return this.textSnapshot.substring(start, end);
}
public getLength(): number {
return this.textSnapshot.length;
}
public getChangeRange(oldScript: ts.IScriptSnapshot): ts.TextChangeRange {
var oldShim = <ScriptSnapshot>oldScript;
return this.scriptInfo.getTextChangeRangeBetweenVersions(oldShim.version, this.version);
}
}
class ScriptSnapshotShim implements ts.ScriptSnapshotShim {
constructor(public scriptSnapshot: ScriptSnapshot) {
}
public getText(start: number, end: number): string {
return this.scriptSnapshot.getText(start, end);
}
public getLength(): number {
return this.scriptSnapshot.getLength();
var range = this.scriptInfo.getTextChangeRangeBetweenVersions(oldShim.version, this.version);
}
public getChangeRange(oldScript: ts.ScriptSnapshotShim): string {
var oldShim = <ScriptSnapshotShim>oldScript;
@@ -194,7 +209,7 @@ module Harness.LanguageService {
var fileNames: string[] = [];
ts.forEachKey(this.fileNameToScript,(fileName) => { fileNames.push(fileName); });
return JSON.stringify(fileNames);
return new ScriptSnapshotShim(this.getScriptInfo(fileName));
}
public getScriptSnapshot(fileName: string): ts.ScriptSnapshotShim {
if (this.contains(fileName)) {