Skip to content

Commit f8dd19e

Browse files
Resurrect the post edit invariants checking for fourslash.
1 parent 7b528dd commit f8dd19e

3 files changed

Lines changed: 51 additions & 52 deletions

File tree

src/harness/fourslash.ts

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,44 +1415,42 @@ module FourSlash {
14151415
}
14161416

14171417
private checkPostEditInvariants() {
1418-
return;
1419-
1420-
/// TODO: reimplement this section
1421-
//if (this.editValidation === IncrementalEditValidation.None) {
1422-
// return;
1423-
//}
1424-
1425-
//// Get syntactic errors (to force a refresh)
1426-
//var incrSyntaxErrs = JSON.stringify(this.languageService.getSyntacticDiagnostics(this.activeFile.fileName));
1427-
1428-
//// Check syntactic structure
1429-
//var snapshot = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName);
1430-
//var content = snapshot.getText(0, snapshot.getLength());
1431-
//var refSyntaxTree = TypeScript.Parser.parse(this.activeFile.fileName, TypeScript.SimpleText.fromString(content), ts.ScriptTarget.ES5, TypeScript.isDTSFile(this.activeFile.fileName));
1432-
//var fullSyntaxErrs = JSON.stringify(refSyntaxTree.diagnostics());
1433-
1434-
//if (incrSyntaxErrs !== fullSyntaxErrs) {
1435-
// this.raiseError('Mismatched incremental/full syntactic errors for file ' + this.activeFile.fileName + '.\n=== Incremental errors ===\n' + incrSyntaxErrs + '\n=== Full Errors ===\n' + fullSyntaxErrs);
1436-
//}
1437-
1438-
// if (this.editValidation !== IncrementalEditValidation.SyntacticOnly) {
1439-
// var compiler = new TypeScript.TypeScriptCompiler();
1440-
// for (var i = 0; i < this.testData.files.length; i++) {
1441-
// snapshot = this.languageServiceShimHost.getScriptSnapshot(this.testData.files[i].fileName);
1442-
// compiler.addFile(this.testData.files[i].fileName, TypeScript.ScriptSnapshot.fromString(snapshot.getText(0, snapshot.getLength())), ts.ByteOrderMark.None, 0, true);
1443-
// }
1444-
1445-
// compiler.addFile('lib.d.ts', TypeScript.ScriptSnapshot.fromString(Harness.Compiler.libTextMinimal), ts.ByteOrderMark.None, 0, true);
1446-
1447-
// for (var i = 0; i < this.testData.files.length; i++) {
1448-
// var refSemanticErrs = JSON.stringify(compiler.getSemanticDiagnostics(this.testData.files[i].fileName));
1449-
// var incrSemanticErrs = JSON.stringify(this.languageService.getSemanticDiagnostics(this.testData.files[i].fileName));
1450-
1451-
// if (incrSemanticErrs !== refSemanticErrs) {
1452-
// this.raiseError('Mismatched incremental/full semantic errors for file ' + this.testData.files[i].fileName + '\n=== Incremental errors ===\n' + incrSemanticErrs + '\n=== Full Errors ===\n' + refSemanticErrs);
1453-
// }
1454-
// }
1455-
// }
1418+
if (this.editValidation === IncrementalEditValidation.None) {
1419+
return;
1420+
}
1421+
1422+
// Get syntactic errors (to force a refresh)
1423+
var incrSyntaxErrs = JSON.stringify(Utils.convertDiagnostics(this.languageService.getSyntacticDiagnostics(this.activeFile.fileName)));
1424+
1425+
// Check syntactic structure
1426+
var snapshot = this.languageServiceShimHost.getScriptSnapshot(this.activeFile.fileName);
1427+
var content = snapshot.getText(0, snapshot.getLength());
1428+
var refSyntaxTree = ts.createLanguageServiceSourceFile(
1429+
this.activeFile.fileName, createScriptSnapShot(content), ts.ScriptTarget.Latest, /*version:*/ "0", /*isOpen:*/ false, /*setNodeParents:*/ false);
1430+
var fullSyntaxErrs = JSON.stringify(Utils.convertDiagnostics(refSyntaxTree.getSyntacticDiagnostics()));
1431+
1432+
if (incrSyntaxErrs !== fullSyntaxErrs) {
1433+
this.raiseError('Mismatched incremental/full syntactic errors for file ' + this.activeFile.fileName + '.\n=== Incremental errors ===\n' + incrSyntaxErrs + '\n=== Full Errors ===\n' + fullSyntaxErrs);
1434+
}
1435+
1436+
//if (this.editValidation !== IncrementalEditValidation.SyntacticOnly) {
1437+
// var compiler = new TypeScript.TypeScriptCompiler();
1438+
// for (var i = 0; i < this.testData.files.length; i++) {
1439+
// snapshot = this.languageServiceShimHost.getScriptSnapshot(this.testData.files[i].fileName);
1440+
// compiler.addFile(this.testData.files[i].fileName, TypeScript.ScriptSnapshot.fromString(snapshot.getText(0, snapshot.getLength())), ts.ByteOrderMark.None, 0, true);
1441+
// }
1442+
1443+
// compiler.addFile('lib.d.ts', TypeScript.ScriptSnapshot.fromString(Harness.Compiler.libTextMinimal), ts.ByteOrderMark.None, 0, true);
1444+
1445+
// for (var i = 0; i < this.testData.files.length; i++) {
1446+
// var refSemanticErrs = JSON.stringify(compiler.getSemanticDiagnostics(this.testData.files[i].fileName));
1447+
// var incrSemanticErrs = JSON.stringify(this.languageService.getSemanticDiagnostics(this.testData.files[i].fileName));
1448+
1449+
// if (incrSemanticErrs !== refSemanticErrs) {
1450+
// this.raiseError('Mismatched incremental/full semantic errors for file ' + this.testData.files[i].fileName + '\n=== Incremental errors ===\n' + incrSemanticErrs + '\n=== Full Errors ===\n' + refSemanticErrs);
1451+
// }
1452+
// }
1453+
//}
14561454
}
14571455

14581456
private fixCaretPosition() {

src/harness/harness.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ module Utils {
175175
function isNodeOrArray(a: any): boolean {
176176
return a !== undefined && typeof a.pos === "number";
177177
}
178+
179+
export function convertDiagnostics(diagnostics: ts.Diagnostic[]) {
180+
return diagnostics.map(convertDiagnostic);
181+
}
182+
183+
function convertDiagnostic(diagnostic: ts.Diagnostic) {
184+
return {
185+
start: diagnostic.start,
186+
length: diagnostic.length,
187+
messageText: diagnostic.messageText,
188+
category: (<any>ts).DiagnosticCategory[diagnostic.category],
189+
code: diagnostic.code
190+
};
191+
}
178192
}
179193

180194
module Harness.Path {

src/harness/test262Runner.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,6 @@ class Test262BaselineRunner extends RunnerBase {
5252

5353
function getNodeFlagName(f: number) { return getFlagName((<any>ts).NodeFlags, f); }
5454
function getParserContextFlagName(f: number) { return getFlagName((<any>ts).ParserContextFlags, f); }
55-
function convertDiagnostics(diagnostics: ts.Diagnostic[]) {
56-
return diagnostics.map(convertDiagnostic);
57-
}
58-
59-
function convertDiagnostic(diagnostic: ts.Diagnostic): any {
60-
return {
61-
start: diagnostic.start,
62-
length: diagnostic.length,
63-
messageText: diagnostic.messageText,
64-
category: (<any>ts).DiagnosticCategory[diagnostic.category],
65-
code: diagnostic.code
66-
};
67-
}
6855

6956
function serializeNode(n: ts.Node): any {
7057
var o: any = { kind: getKindName(n.kind) };
@@ -97,7 +84,7 @@ class Test262BaselineRunner extends RunnerBase {
9784
case "referenceDiagnostics":
9885
case "parseDiagnostics":
9986
case "grammarDiagnostics":
100-
o[propertyName] = convertDiagnostics((<any>n)[propertyName]);
87+
o[propertyName] = Utils.convertDiagnostics((<any>n)[propertyName]);
10188
break;
10289

10390
case "nextContainer":

0 commit comments

Comments
 (0)