diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index b4fba9a4501..5b46ec32a1c 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -279,7 +279,7 @@ module FourSlash { // Create a new Services Adaptor this.cancellationToken = new TestCancellationToken(); var compilationOptions = convertGlobalOptionsToCompilerOptions(this.testData.globalOptions); - var languageServiceAdaptor = new Harness.LanguageService.ShimLanugageServiceAdaptor(this.cancellationToken, compilationOptions); + var languageServiceAdaptor = new Harness.LanguageService.NativeLanugageServiceAdaptor(this.cancellationToken, compilationOptions); this.languageServiceAdaptorHost = languageServiceAdaptor.getHost(); this.languageService = languageServiceAdaptor.getLanguageService(); @@ -1787,67 +1787,6 @@ module FourSlash { } } - public verifyTypesAgainstFullCheckAtPositions(positions: number[]) { - this.taoInvalidReason = 'verifyTypesAgainstFullCheckAtPositions impossible'; - - // Create a from-scratch LS to check against - var referenceLanguageServiceShimHost = new Harness.LanguageService.TypeScriptLS(); - var referenceLanguageServiceShim = referenceLanguageServiceShimHost.getLanguageService(); - var referenceLanguageService = referenceLanguageServiceShim.languageService; - - // Add lib.d.ts to the reference language service - referenceLanguageServiceShimHost.addDefaultLibrary(); - - for (var i = 0; i < this.testData.files.length; i++) { - var file = this.testData.files[i]; - - var content = this.getFileContent(file.fileName); - referenceLanguageServiceShimHost.addScript(this.testData.files[i].fileName, content); - } - - for (i = 0; i < positions.length; i++) { - var nameOf = (type: ts.QuickInfo) => type ? ts.displayPartsToString(type.displayParts) : '(none)'; - - var pullName: string, refName: string; - var anyFailed = false; - - var errMsg = ''; - - try { - var pullType = this.languageService.getQuickInfoAtPosition(this.activeFile.fileName, positions[i]); - pullName = nameOf(pullType); - } catch (err1) { - errMsg = 'Failed to get pull type check. Exception: ' + err1 + '\r\n'; - if (err1.stack) errMsg = errMsg + err1.stack; - pullName = '(failed)'; - anyFailed = true; - } - - try { - var referenceType = referenceLanguageService.getQuickInfoAtPosition(this.activeFile.fileName, positions[i]); - refName = nameOf(referenceType); - } catch (err2) { - errMsg = 'Failed to get full type check. Exception: ' + err2 + '\r\n'; - if (err2.stack) errMsg = errMsg + err2.stack; - refName = '(failed)'; - anyFailed = true; - } - - var failure = anyFailed || (refName !== pullName); - if (failure) { - content = this.getFileContent(this.activeFile.fileName); - var textAtPosition = content.substr(positions[i], 10); - var positionDescription = 'Position ' + positions[i] + ' ("' + textAtPosition + '"...)'; - - if (anyFailed) { - throw new Error('Exception thrown in language service for ' + positionDescription + '\r\n' + errMsg); - } else if (refName !== pullName) { - throw new Error('Pull/Full disagreement failed at ' + positionDescription + ' - expected full typecheck type "' + refName + '" to equal pull type "' + pullName + '".'); - } - } - } - } - /* Check number of navigationItems which match both searchValue and matchKind. Report an error if expected value and actual value do not match. diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 9316ef813c6..dcf211d3306 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -436,283 +436,5 @@ module Harness.LanguageService { return convertResult; } } - - export class TypeScriptLS implements ts.LanguageServiceShimHost { - private ls: ts.LanguageServiceShim = null; - - private fileNameToScript: ts.Map = {}; - private settings: ts.CompilerOptions = {}; - - constructor(private cancellationToken: ts.CancellationToken = CancellationToken.None) { - } - - public trace(s: string) { - } - - public addDefaultLibrary() { - this.addScript(Harness.Compiler.defaultLibFileName, Harness.Compiler.defaultLibSourceFile.text); - } - - public getHostIdentifier(): string { - return "TypeScriptLS"; - } - - private getScriptInfo(fileName: string): ScriptInfo { - return ts.lookUp(this.fileNameToScript, fileName); - } - - public addScript(fileName: string, content: string) { - this.fileNameToScript[fileName] = new ScriptInfo(fileName, content); - } - - private contains(fileName: string): boolean { - return ts.hasProperty(this.fileNameToScript, fileName); - } - - public updateScript(fileName: string, content: string) { - var script = this.getScriptInfo(fileName); - if (script !== null) { - script.updateContent(content); - return; - } - - this.addScript(fileName, content); - } - - public editScript(fileName: string, minChar: number, limChar: number, newText: string) { - var script = this.getScriptInfo(fileName); - if (script !== null) { - script.editContent(minChar, limChar, newText); - return; - } - - throw new Error("No script with name '" + fileName + "'"); - } - - ////////////////////////////////////////////////////////////////////// - // ILogger implementation - // - public information(): boolean { return false; } - public debug(): boolean { return true; } - public warning(): boolean { return true; } - public error(): boolean { return true; } - public fatal(): boolean { return true; } - - public log(s: string): void { - // For debugging... - //TypeScript.Environment.standardOut.WriteLine("TypeScriptLS:" + s); - } - - ////////////////////////////////////////////////////////////////////// - // LanguageServiceShimHost implementation - // - - /// Returns json for Tools.CompilationSettings - public getCompilationSettings(): string { - return JSON.stringify(this.settings); - } - - public getCancellationToken(): ts.CancellationToken { - return this.cancellationToken; - } - - public getCurrentDirectory(): string { - return ""; - } - - public getDefaultLibFilename(): string { - return ""; - } - - public getScriptFileNames(): string { - var fileNames: string[] = []; - ts.forEachKey(this.fileNameToScript,(fileName) => { fileNames.push(fileName); }); - return JSON.stringify(fileNames); - } - - public getScriptSnapshot(fileName: string): ts.ScriptSnapshotShim { - if (this.contains(fileName)) { - return new ScriptSnapshotShim(new ScriptSnapshot(this.getScriptInfo(fileName))); - } - return undefined; - } - - public getScriptVersion(fileName: string): string { - if (this.contains(fileName)) { - return this.getScriptInfo(fileName).version.toString(); - } - return undefined; - } - - public getLocalizedDiagnosticMessages(): string { - return JSON.stringify({}); - } - - /** Return a new instance of the language service shim, up-to-date wrt to typecheck. - * To access the non-shim (i.e. actual) language service, use the "ls.languageService" property. - */ - public getLanguageService(): ts.LanguageServiceShim { - this.ls = new TypeScript.Services.TypeScriptServicesFactory().createLanguageServiceShim(this); - return this.ls; - } - - public setCompilationSettings(settings: ts.CompilerOptions) { - for (var key in settings) { - if (settings.hasOwnProperty(key)) { - this.settings[key] = settings[key]; - } - } - } - - /** Return a new instance of the classifier service shim */ - public getClassifier(): ts.ClassifierShim { - return new TypeScript.Services.TypeScriptServicesFactory().createClassifierShim(this); - } - - public getCoreService(): ts.CoreServicesShim { - return new TypeScript.Services.TypeScriptServicesFactory().createCoreServicesShim(this); - } - - /** Parse file given its source text */ - public parseSourceText(fileName: string, sourceText: ts.IScriptSnapshot): ts.SourceFile { - var result = ts.createSourceFile(fileName, sourceText.getText(0, sourceText.getLength()), ts.ScriptTarget.Latest); - result.version = "1"; - return result; - } - - /** Parse a file on disk given its fileName */ - public parseFile(fileName: string) { - var sourceText = ts.ScriptSnapshot.fromString(Harness.IO.readFile(fileName)); - return this.parseSourceText(fileName, sourceText); - } - - /** - * @param line 1 based index - * @param col 1 based index - */ - public lineColToPosition(fileName: string, line: number, col: number): number { - var script: ScriptInfo = this.fileNameToScript[fileName]; - assert.isNotNull(script); - assert.isTrue(line >= 1); - assert.isTrue(col >= 1); - - return ts.getPositionFromLineAndCharacter(script.lineMap, line, col); - } - - /** - * @param line 0 based index - * @param col 0 based index - */ - public positionToZeroBasedLineCol(fileName: string, position: number): ts.LineAndCharacter { - var script: ScriptInfo = this.fileNameToScript[fileName]; - assert.isNotNull(script); - - var result = ts.getLineAndCharacterOfPosition(script.lineMap, position); - - assert.isTrue(result.line >= 1); - assert.isTrue(result.character >= 1); - return { line: result.line - 1, character: result.character - 1 }; - } - - /** Verify that applying edits to sourceFileName result in the content of the file baselineFileName */ - public checkEdits(sourceFileName: string, baselineFileName: string, edits: ts.TextChange[]) { - var script = Harness.IO.readFile(sourceFileName); - var formattedScript = this.applyEdits(script, edits); - var baseline = Harness.IO.readFile(baselineFileName); - - function noDiff(text1: string, text2: string) { - text1 = text1.replace(/^\s+|\s+$/g, "").replace(/\r\n?/g, "\n"); - text2 = text2.replace(/^\s+|\s+$/g, "").replace(/\r\n?/g, "\n"); - - if (text1 !== text2) { - var errorString = ""; - var text1Lines = text1.split(/\n/); - var text2Lines = text2.split(/\n/); - for (var i = 0; i < text1Lines.length; i++) { - if (text1Lines[i] !== text2Lines[i]) { - errorString += "Difference at line " + (i + 1) + ":\n"; - errorString += " Left File: " + text1Lines[i] + "\n"; - errorString += " Right File: " + text2Lines[i] + "\n\n"; - } - } - throw (new Error(errorString)); - } - } - assert.isTrue(noDiff(formattedScript, baseline)); - assert.equal(formattedScript, baseline); - } - - - /** Apply an array of text edits to a string, and return the resulting string. */ - public applyEdits(content: string, edits: ts.TextChange[]): string { - var result = content; - edits = this.normalizeEdits(edits); - - for (var i = edits.length - 1; i >= 0; i--) { - var edit = edits[i]; - var prefix = result.substring(0, edit.span.start); - var middle = edit.newText; - var suffix = result.substring(ts.textSpanEnd(edit.span)); - result = prefix + middle + suffix; - } - return result; - } - - /** Normalize an array of edits by removing overlapping entries and sorting entries on the minChar position. */ - private normalizeEdits(edits: ts.TextChange[]): ts.TextChange[] { - var result: ts.TextChange[] = []; - - function mapEdits(edits: ts.TextChange[]): { edit: ts.TextChange; index: number; }[] { - var result: { edit: ts.TextChange; index: number; }[] = []; - for (var i = 0; i < edits.length; i++) { - result.push({ edit: edits[i], index: i }); - } - return result; - } - - var temp = mapEdits(edits).sort(function (a, b) { - var result = a.edit.span.start - b.edit.span.start; - if (result === 0) - result = a.index - b.index; - return result; - }); - - var current = 0; - var next = 1; - while (current < temp.length) { - var currentEdit = temp[current].edit; - - // Last edit - if (next >= temp.length) { - result.push(currentEdit); - current++; - continue; - } - var nextEdit = temp[next].edit; - - var gap = nextEdit.span.start - ts.textSpanEnd(currentEdit.span); - - // non-overlapping edits - if (gap >= 0) { - result.push(currentEdit); - current = next; - next++; - continue; - } - - // overlapping edits: for now, we only support ignoring an next edit - // entirely contained in the current edit. - if (ts.textSpanEnd(currentEdit.span) >= ts.textSpanEnd(nextEdit.span)) { - next++; - continue; - } - else { - throw new Error("Trying to apply overlapping edits"); - } - } - - return result; - } - } } \ No newline at end of file diff --git a/tests/cases/fourslash/addMethodToInterface1.ts b/tests/cases/fourslash/addMethodToInterface1.ts index 749f5601173..07cd4700583 100644 --- a/tests/cases/fourslash/addMethodToInterface1.ts +++ b/tests/cases/fourslash/addMethodToInterface1.ts @@ -12,4 +12,3 @@ edit.disableFormatting(); goTo.marker('1'); edit.insert(" compareTo(): number;\n"); -diagnostics.validateTypesAtPositions(168,84,53,118,22); diff --git a/tests/cases/fourslash/arrayConcatTypeCheck0.ts b/tests/cases/fourslash/arrayConcatTypeCheck0.ts index ac5404266a6..9250eb5b6fd 100644 --- a/tests/cases/fourslash/arrayConcatTypeCheck0.ts +++ b/tests/cases/fourslash/arrayConcatTypeCheck0.ts @@ -14,4 +14,3 @@ edit.disableFormatting(); goTo.marker('1'); edit.insert(", 'world'"); -diagnostics.validateTypesAtPositions(78); diff --git a/tests/cases/fourslash/arrayConcatTypeCheck1.ts b/tests/cases/fourslash/arrayConcatTypeCheck1.ts index 42d9cdb8a1c..c62bd5b7f14 100644 --- a/tests/cases/fourslash/arrayConcatTypeCheck1.ts +++ b/tests/cases/fourslash/arrayConcatTypeCheck1.ts @@ -23,5 +23,4 @@ goTo.marker('2'); edit.deleteAtCaret(7); goTo.marker('4'); -diagnostics.validateTypesAtPositions(43); diff --git a/tests/cases/fourslash/arrayTypeMismatchIncrementalTypeCheck.ts b/tests/cases/fourslash/arrayTypeMismatchIncrementalTypeCheck.ts deleted file mode 100644 index 778f20db219..00000000000 --- a/tests/cases/fourslash/arrayTypeMismatchIncrementalTypeCheck.ts +++ /dev/null @@ -1,31 +0,0 @@ -/// - -//// interface Iterator { -//// (value: T, index: any): U; -//// } -//// -//// interface WrappedArray { -//// map(iterator: Iterator): U[]; -//// } -//// -//// interface Underscore { -//// (list: T[]): WrappedArray; -//// map(list: T[], iterator: Iterator, context?: any): U[]; -//// } -//// -//// declare var _: Underscore; -//// -//// var a: string[]; -//// var b = _.map(a, x => x.length); // Type any[], should be number[] -//// var c = _(a).map(); -//// var d = a.map(x => x.length); -//// var bb = _.map(aa, x => x.length); -//// var cc = _(aa).map(x => x.length); // Error, could not select overload -//// var dd = aa.map(x => x.length); // Error, could not select overload -//// -//// -//// -//// - -edit.disableFormatting(); -diagnostics.validateTypesAtPositions(364); diff --git a/tests/cases/fourslash/emptyTypeArgumentList.ts b/tests/cases/fourslash/emptyTypeArgumentList.ts deleted file mode 100644 index d8f7947559b..00000000000 --- a/tests/cases/fourslash/emptyTypeArgumentList.ts +++ /dev/null @@ -1,7 +0,0 @@ -/// - -//// function foo2(test); -//// function foo2() { } -//// /**/foo2<>(""); -goTo.marker(); -diagnostics.validateTypeAtCurrentPosition(); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 77b5add7a11..717962fd39f 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -80,16 +80,6 @@ module FourSlashInterface { } } - export class diagnostics { - public validateTypeAtCurrentPosition() { - return this.validateTypesAtPositions(FourSlash.currentTestState.currentCaretPosition); - } - - public validateTypesAtPositions(...positions: number[]) { - return FourSlash.currentTestState.verifyTypesAgainstFullCheckAtPositions(positions); - } - } - export class goTo { // Moves the caret to the specified marker, // or the anonymous marker ('/**/') if no name @@ -647,7 +637,6 @@ module fs { export var edit = new FourSlashInterface.edit(); export var debug = new FourSlashInterface.debug(); export var format = new FourSlashInterface.format(); - export var diagnostics = new FourSlashInterface.diagnostics(); export var cancellation = new FourSlashInterface.cancellation(); } module ts { @@ -666,6 +655,5 @@ var verify = new FourSlashInterface.verify(); var edit = new FourSlashInterface.edit(); var debug = new FourSlashInterface.debug(); var format = new FourSlashInterface.format(); -var diagnostics = new FourSlashInterface.diagnostics(); var cancellation = new FourSlashInterface.cancellation(); var classification = FourSlashInterface.classification; diff --git a/tests/cases/fourslash/getTypeAtModuleExtends.ts b/tests/cases/fourslash/getTypeAtModuleExtends.ts deleted file mode 100644 index 8114ee94c1b..00000000000 --- a/tests/cases/fourslash/getTypeAtModuleExtends.ts +++ /dev/null @@ -1,12 +0,0 @@ -/// - -////declare module A.B { -//// export class C { } -////} -//// -////import ab = A.B; -//// -////class D extends ab.C/**/{ } - -goTo.marker(); -diagnostics.validateTypesAtPositions(FourSlash.currentTestState.currentCaretPosition); diff --git a/tests/cases/fourslash/numberAssignement0.ts b/tests/cases/fourslash/numberAssignement0.ts deleted file mode 100644 index 540a8d91f3d..00000000000 --- a/tests/cases/fourslash/numberAssignement0.ts +++ /dev/null @@ -1,8 +0,0 @@ -/// - -//// var x: Number; -//// var y: Number; -//// var z = x ; - -edit.disableFormatting(); -diagnostics.validateTypesAtPositions(28); diff --git a/tests/cases/fourslash/pullFullDiffTypeParameterExtends0.ts b/tests/cases/fourslash/pullFullDiffTypeParameterExtends0.ts deleted file mode 100644 index 990d65404d3..00000000000 --- a/tests/cases/fourslash/pullFullDiffTypeParameterExtends0.ts +++ /dev/null @@ -1,29 +0,0 @@ -/// - -//// class A { } -//// class B { -//// data: A; -//// } -//// -//// // Below 2 should compile without error -//// var x: A< { }, { b: number }>; -//// var y: B< { a: string }, { }>; -//// -//// -//// // Below should be in error -//// var x1: A<{ a: string;}>; -//// var x2: A<{ a: number }>; -//// var x3: B<{ a: string;}, { b: string }>; -//// var x4: B<{ a: string;}>; -//// var x5: A<{ a: string; b: number }, { a: string }>; -//// var x6: B<>; -//// -//// interface I1 { -//// a: string; -//// } -//// var x8: B; -//// - -edit.disableFormatting(); -diagnostics.validateTypesAtPositions(34); - diff --git a/tests/cases/fourslash/restParametersTypeValidation1.ts b/tests/cases/fourslash/restParametersTypeValidation1.ts deleted file mode 100644 index b598ae7fc84..00000000000 --- a/tests/cases/fourslash/restParametersTypeValidation1.ts +++ /dev/null @@ -1,12 +0,0 @@ -/// - -//// function f18(a?:string, ...b){} -//// -//// function f19(a?:string, b?){} -//// -//// function f20(a:string, b?:string, ...c:number[]){} -//// -//// function f21(a:string, b?:string, ...d:number[]){} - -edit.disableFormatting(); -diagnostics.validateTypesAtPositions(133); diff --git a/tests/cases/fourslash/typeCheckAfterAddingGenericParameter.ts b/tests/cases/fourslash/typeCheckAfterAddingGenericParameter.ts index e2e978dd7ea..fa312f3c711 100644 --- a/tests/cases/fourslash/typeCheckAfterAddingGenericParameter.ts +++ b/tests/cases/fourslash/typeCheckAfterAddingGenericParameter.ts @@ -20,5 +20,3 @@ edit.insert(", X"); goTo.marker('addTypeParam'); edit.insert(", X"); - -diagnostics.validateTypesAtPositions(91, 163); diff --git a/tests/cases/fourslash/typeCheckExpression0.ts b/tests/cases/fourslash/typeCheckExpression0.ts deleted file mode 100644 index 51c6ae75655..00000000000 --- a/tests/cases/fourslash/typeCheckExpression0.ts +++ /dev/null @@ -1,27 +0,0 @@ -/// - -//// class Point { -//// -//// constructor(public x: number) { -//// -//// } -//// getDist() { -//// } -//// static origin = new Point(0); -//// } -//// -//// class Point3D { -//// -//// constructor(x: number, y: number, private z) { -//// super(x, y); -//// } -//// -//// getDist() { -//// return Math.sqrt(this.x*this.x + this.z*this.m); -//// } -//// } -//// -//// - -edit.disableFormatting(); -diagnostics.validateTypesAtPositions(258); diff --git a/tests/cases/fourslash/typeCheckGenericTypeLiteralArgument.ts b/tests/cases/fourslash/typeCheckGenericTypeLiteralArgument.ts deleted file mode 100644 index 107c7a3b525..00000000000 --- a/tests/cases/fourslash/typeCheckGenericTypeLiteralArgument.ts +++ /dev/null @@ -1,12 +0,0 @@ -/// - -//// interface Sequence { -//// each(iterator: (value: T) => void): void; -//// filter(): Sequence; -//// groupBy(keySelector: () => K): Sequence<{ items: T/**/[]; }>; -//// } - -goTo.file(0); - -// Marker in above file is placed at position 154 -diagnostics.validateTypesAtPositions(154); diff --git a/tests/cases/fourslash/typeCheckIndexSignature.ts b/tests/cases/fourslash/typeCheckIndexSignature.ts deleted file mode 100644 index a0c7d049b93..00000000000 --- a/tests/cases/fourslash/typeCheckIndexSignature.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// - -//// function method() { -//// var dictionary = <{ [index: string]: string; }>{}; -//// } -//// - -edit.disableFormatting(); // Disregard, just here to keep Fourslash happy - -diagnostics.validateTypesAtPositions(44); - diff --git a/tests/cases/fourslash/typeCheckIndexerAccess1.ts b/tests/cases/fourslash/typeCheckIndexerAccess1.ts deleted file mode 100644 index 384f6d003e2..00000000000 --- a/tests/cases/fourslash/typeCheckIndexerAccess1.ts +++ /dev/null @@ -1,40 +0,0 @@ -/// - -//// // @sourcemap: true -//// module Foo.Bar { -//// "use strict"; -//// -//// class Greeter { -//// constructor(public greeting: string) { -//// } -//// -//// greet() { -//// } -//// } -//// -//// -//// function foo(greeting: string): Foo.Bar.Greeter { -//// return new Greeter(greeting); -//// } -//// -//// var greeter = new Greeter("Hello, world!"); -//// var str = greeter.greet(); -//// -//// function foo2(greeting: string, ...restGreetings) { -//// var greeters: Greeter[] = []; -//// new Greeter(greeting); -//// for (var i = 0; restGreetings.length; i++) { -//// greeters.push(new Greeter(restGreetings[i])); -//// } -//// -//// return greeters; -//// } -//// -//// var b = foo2("Hello", "World"); -//// for (var j = 0; j < b.length; j++) { -//// b[j].greet(); -//// } -//// } - -edit.disableFormatting(); -diagnostics.validateTypesAtPositions(705); \ No newline at end of file