diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index b244ac9d589..f5efa233a61 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1239,22 +1239,23 @@ Actual: ${stringify(fullActual)}`); return this.languageService.findReferences(this.activeFile.fileName, this.currentCaretPosition); } - public getSyntacticDiagnostics(expected: ReadonlyArray) { + public getSyntacticDiagnostics(expected: ReadonlyArray) { const diagnostics = this.languageService.getSyntacticDiagnostics(this.activeFile.fileName); - this.testDiagnostics(expected, diagnostics); + this.testDiagnostics(expected, diagnostics, "error"); } - public getSemanticDiagnostics(expected: ReadonlyArray) { + public getSemanticDiagnostics(expected: ReadonlyArray) { const diagnostics = this.languageService.getSemanticDiagnostics(this.activeFile.fileName); - this.testDiagnostics(expected, diagnostics); + this.testDiagnostics(expected, diagnostics, "error"); } - public getSuggestionDiagnostics(expected: ReadonlyArray): void { - this.testDiagnostics(expected, this.languageService.getSuggestionDiagnostics(this.activeFile.fileName)); + public getSuggestionDiagnostics(expected: ReadonlyArray): void { + this.testDiagnostics(expected, this.languageService.getSuggestionDiagnostics(this.activeFile.fileName), "suggestion"); } - private testDiagnostics(expected: ReadonlyArray, diagnostics: ReadonlyArray) { - assert.deepEqual(ts.realizeDiagnostics(diagnostics, ts.newLineCharacter), expected); + private testDiagnostics(expected: ReadonlyArray, diagnostics: ReadonlyArray, category: string) { + assert.deepEqual(ts.realizeDiagnostics(diagnostics, ts.newLineCharacter), expected.map(e => ( + { message: e.message, category, code: e.code, ...ts.createTextSpanFromRange(e.range || this.getRanges()[0]) }))); } public verifyQuickInfoAt(markerName: string, expectedText: string, expectedDocumentation?: string) { @@ -4676,4 +4677,10 @@ namespace FourSlashInterface { source?: string; description: string; } + + export interface Diagnostic { + message: string; + range?: FourSlash.Range; + code: number; + } } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 7561ca3793d..0bf9a6d3913 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -347,9 +347,9 @@ declare namespace FourSlashInterface { start: number; length: number; }, displayParts: ts.SymbolDisplayPart[], documentation: ts.SymbolDisplayPart[], tags: ts.JSDocTagInfo[]): void; - getSyntacticDiagnostics(expected: ReadonlyArray): void; - getSemanticDiagnostics(expected: ReadonlyArray): void; - getSuggestionDiagnostics(expected: ReadonlyArray): void; + getSyntacticDiagnostics(expected: ReadonlyArray): void; + getSemanticDiagnostics(expected: ReadonlyArray): void; + getSuggestionDiagnostics(expected: ReadonlyArray): void; ProjectInfo(expected: string[]): void; allRangesAppearInImplementationList(markerName: string): void; } @@ -521,11 +521,10 @@ declare namespace FourSlashInterface { text: string; range: Range; } - interface RealizedDiagnostic { + interface Diagnostic { message: string; - start: number; - length: number; - category: string; + /** @default `test.ranges()[0]` */ + range?: Range; code: number; } } diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts index 20ca5101ba8..46d9062c468 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// import a = b; +////[|import a = b;|] -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'import ... =' can only be used in a .ts file.", - start: 0, - length: 13, - category: "error", code: 8002 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics10.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics10.ts index fb9d68336e0..9f859c527d1 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics10.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics10.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// function F() { } +////function F<[|T|]>() { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'type parameter declarations' can only be used in a .ts file.", - start: 11, - length: 1, - category: "error", code: 8004 - } -]); +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics11.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics11.ts index 4a5dafd1042..f3928bf997d 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics11.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics11.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// function F(): number { } +////function F(): [|number|] { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'types' can only be used in a .ts file.", - start: 14, - length: 6, - category: "error", code: 8010 - } -]); +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics12.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics12.ts index fc7956d73c9..e9494017d5d 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics12.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics12.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// declare var v; +////[|declare|] var v; -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'declare' can only be used in a .ts file.", - start: 0, - length: 7, - category: "error", code: 8009 - } -]); +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics13.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics13.ts index 87cc7b37867..98b0471b256 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics13.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics13.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// var v: () => number; +////var v: [|() => number|]; -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'types' can only be used in a .ts file.", - start: 7, - length: 12, - category: "error", code: 8010 - } -]); \ No newline at end of file +}]); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics14.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics14.ts index 4659897559c..ed694fc4e5b 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics14.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics14.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// Foo(); +////Foo<[|number|]>(); -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'type arguments' can only be used in a .ts file.", - start: 4, - length: 6, - category: "error", code: 8011 - } -]); +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics15.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics15.ts index 31194e37fcb..5e3955a658b 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics15.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics15.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// function F(public p) { } +////function F([|public|] p) { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'parameter modifiers' can only be used in a .ts file.", - start: 11, - length: 6, - category: "error", code: 8012 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics16.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics16.ts index 4d4e3a56287..826c4157036 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics16.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics16.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// function F(p?) { } +////function F(p[|?|]) { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'?' can only be used in a .ts file.", - start: 12, - length: 1, - category: "error", code: 8009 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics17.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics17.ts index f6d4d65a83d..2bda62590d7 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics17.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics17.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// function F(a: number) { } +////function F(a: [|number|]) { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'types' can only be used in a .ts file.", - start: 14, - length: 6, - category: "error", code: 8010 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics18.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics18.ts index 71e098b0ee2..3344a630ca6 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics18.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics18.ts @@ -5,32 +5,23 @@ ////class C { //// x; // Regular property declaration allowed //// static y; // static allowed -//// public z; // public not allowed +//// [|public|] z; // public not allowed ////} goTo.file("a.js"); -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "\'public\' can only be used in a .ts file.", - start: 93, - length: 6, - category: "error", code: 8009 - } -]); +}]); // @Filename: b.js ////class C { -//// x: number; // Types not allowed +//// x: [|number|]; // Types not allowed ////} goTo.file("b.js"); -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'types' can only be used in a .ts file.", - start: 17, - length: 6, - category: "error", + range: test.ranges()[1], code: 8010 - } -]); +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics19.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics19.ts index fe602056dcb..3198615d8b4 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics19.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics19.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// enum E { } +////enum [|E|] { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'enum declarations' can only be used in a .ts file.", - start: 5, - length: 1, - category: "error", code: 8015 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics2.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics2.ts index 0a14c8b5ddf..1ad538071dd 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics2.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics2.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// export = b; +////[|export = b;|] -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'export=' can only be used in a .ts file.", - start: 0, - length: 11, - category: "error", code: 8003 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics3.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics3.ts index 47837864781..709e466bcf1 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics3.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics3.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// class C { } +////class C<[|T|]> { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'type parameter declarations' can only be used in a .ts file.", - start: 8, - length: 1, - category: "error", code: 8004 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics4.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics4.ts index efd8fe85964..936d6ede996 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics4.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics4.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// public class C { } +////[|public|] class C { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'public' can only be used in a .ts file.", - start: 0, - length: 6, - category: "error", code: 8009 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics5.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics5.ts index 0fcc7652101..f0b765e0ce9 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics5.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics5.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// class C implements D { } +////class C [|implements D|] { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'implements clauses' can only be used in a .ts file.", - start: 8, - length: 12, - category: "error", code: 8005 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics6.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics6.ts index 6d4c7e7dcca..565513d8c07 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics6.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics6.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// interface I { } +////interface [|I|] { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'interface declarations' can only be used in a .ts file.", - start: 10, - length: 1, - category: "error", code: 8006 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics7.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics7.ts index 32ebf6bde0d..66985164936 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics7.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics7.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// module M { } +////module [|M|] { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'module declarations' can only be used in a .ts file.", - start: 7, - length: 1, - category: "error", code: 8007 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics8.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics8.ts index 7ab0db792e8..6655f923022 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics8.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics8.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// type a = b; +////type [|a|] = b; -verify.getSyntacticDiagnostics([ - { - message: "'type aliases' can only be used in a .ts file.", - start: 5, - length: 1, - category: "error", - code: 8008 - } -]); \ No newline at end of file +verify.getSyntacticDiagnostics([{ + message: "'type aliases' can only be used in a .ts file.", + code: 8008 +}]); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics9.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics9.ts index c18f32e378e..fe83ad8488e 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics9.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics9.ts @@ -2,14 +2,9 @@ // @allowJs: true // @Filename: a.js -//// public function F() { } +////[|public|] function F() { } -verify.getSyntacticDiagnostics([ - { +verify.getSyntacticDiagnostics([{ message: "'public' can only be used in a .ts file.", - start: 0, - length: 6, - category: "error", code: 8009 - } -]); \ No newline at end of file +}]); diff --git a/tests/cases/fourslash/jsDocAugmentsAndExtends.ts b/tests/cases/fourslash/jsDocAugmentsAndExtends.ts index ca703f33025..c60475c072b 100644 --- a/tests/cases/fourslash/jsDocAugmentsAndExtends.ts +++ b/tests/cases/fourslash/jsDocAugmentsAndExtends.ts @@ -6,7 +6,7 @@ //// /** //// * @augments {Thing} -//// * @extends {Thing} +//// * [|@extends {Thing}|] //// */ //// class MyStringThing extends Thing { //// constructor() { @@ -27,8 +27,5 @@ goTo.marker(); verify.quickInfoIs("(local var) x: number"); verify.getSemanticDiagnostics([{ message: "Class declarations cannot have more than one \`@augments\` or \`@extends\` tag.", - start: 36, - length: 24, - category: "error", code: 8025 }]); diff --git a/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts b/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts index 115964b40f0..927d84ed8ba 100644 --- a/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts +++ b/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts @@ -9,16 +9,13 @@ // @Filename: a.ts // @emitThisFile: true -////function foo() { return 30; }/*2*/ +////function [|foo|]() { return 30; }/*2*/ goTo.marker("1"); verify.getSemanticDiagnostics([]); goTo.marker("2"); verify.getSemanticDiagnostics([{ message: "Duplicate function implementation.", - start: 9, - length: 3, - category: "error", code: 2393 }]); verify.verifyGetEmitOutputContentsForCurrentFile([ @@ -27,9 +24,6 @@ verify.verifyGetEmitOutputContentsForCurrentFile([ goTo.marker("2"); verify.getSemanticDiagnostics([{ message: "Duplicate function implementation.", - start: 9, - length: 3, - category: "error", code: 2393 }]); goTo.marker("1"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts index 03303b1e09e..fc910965aad 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts @@ -3,14 +3,12 @@ // @allowJs: true // @Filename: /a.js -////exports.f = function() {}/*diagEnd*/ -////exports.C = class {} +////[|exports.f = function() {}|]; +////exports.C = class {}; ////exports.x = 0; verify.getSuggestionDiagnostics([{ message: "File is a CommonJS module; it may be converted to an ES6 module.", - start: 0, - length: test.marker("diagEnd").position, category: "suggestion", code: 80001, }]); diff --git a/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics01.ts b/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics01.ts index d06395186e4..9b3153b13ac 100644 --- a/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics01.ts +++ b/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics01.ts @@ -2,21 +2,17 @@ // @allowJs: true // @Filename: a.js -//// var ===; +////var [|===|][|;|] verify.getSyntacticDiagnostics([ { message: "Variable declaration expected.", - start: 4, - length: 3, - category: "error", + range: test.ranges()[0], code: 1134 }, { message: "Expression expected.", - start: 7, - length: 1, - category: "error", + range: test.ranges()[1], code: 1109 }, ]); diff --git a/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts b/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts index ab12a5c146d..4d2b3d5d989 100644 --- a/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts +++ b/tests/cases/fourslash/server/getJavaScriptSyntacticDiagnostics02.ts @@ -2,45 +2,35 @@ // @allowJs: true // @Filename: b.js -//// var a = "a"; -//// var b: boolean = true; -//// function foo(): string { } -//// var var = "c"; +////var a = "a"; +////var b: [|boolean|] = true; +////function foo(): [|string|] { } +////var [|var|] [|=|] [|"c"|]; verify.getSyntacticDiagnostics([ { message: "'types' can only be used in a .ts file.", - start: 20, - length: 7, - category: "error", + range: test.ranges()[0], code: 8010 }, { message: "\'types\' can only be used in a .ts file.", - start: 52, - length: 6, - category: "error", + range: test.ranges()[1], code: 8010 }, { message: "Variable declaration expected.", - start: 67, - length: 3, - category: "error", + range: test.ranges()[2], code: 1134 }, { message: "Variable declaration expected.", - start: 71, - length: 1, - category: "error", + range: test.ranges()[3], code: 1134 }, { message: "Variable declaration expected.", - start: 73, - length: 3, - category: "error", + range: test.ranges()[4], code: 1134 }, ]);