diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 51e6c2dbe29..5610eaf1510 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2709,8 +2709,8 @@ Actual: ${stringify(fullActual)}`); return this.languageService.getDocumentHighlights(this.activeFile.fileName, this.currentCaretPosition, filesToSearch); } - public verifyRangesAreOccurrences(isWriteAccess?: boolean) { - const ranges = this.getRanges(); + public verifyRangesAreOccurrences(isWriteAccess?: boolean, ranges?: Range[]) { + ranges = ranges || this.getRanges(); for (const r of ranges) { this.goToRangeStart(r); this.verifyOccurrencesAtPositionListCount(ranges.length); @@ -4084,8 +4084,8 @@ namespace FourSlashInterface { this.state.verifyOccurrencesAtPositionListCount(expectedCount); } - public rangesAreOccurrences(isWriteAccess?: boolean) { - this.state.verifyRangesAreOccurrences(isWriteAccess); + public rangesAreOccurrences(isWriteAccess?: boolean, ranges?: FourSlash.Range[]) { + this.state.verifyRangesAreOccurrences(isWriteAccess, ranges); } public rangesWithSameTextAreRenameLocations() { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index fa9cdd61c2f..b01f8842dee 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -228,7 +228,7 @@ declare namespace FourSlashInterface { */ referenceGroups(starts: ArrayOrSingle | ArrayOrSingle, parts: ReadonlyArray): void; singleReferenceGroup(definition: ReferencesDefinition, ranges?: Range[]): void; - rangesAreOccurrences(isWriteAccess?: boolean): void; + rangesAreOccurrences(isWriteAccess?: boolean, ranges?: Range[]): void; rangesWithSameTextAreRenameLocations(): void; rangesAreRenameLocations(options?: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges?: Range[] }); findReferencesDefinitionDisplayPartsAtCaretAre(expected: ts.SymbolDisplayPart[]): void; diff --git a/tests/cases/fourslash/javaScriptClass2.ts b/tests/cases/fourslash/javaScriptClass2.ts index dcdac24c7b8..130976dfe57 100644 --- a/tests/cases/fourslash/javaScriptClass2.ts +++ b/tests/cases/fourslash/javaScriptClass2.ts @@ -6,12 +6,12 @@ // @Filename: Foo.js //// class Foo { //// constructor() { -//// this.[|union|] = 'foo'; -//// this.[|union|] = 100; +//// [|this.[|{| "declarationRangeIndex": 0 |}union|] = 'foo';|] +//// [|this.[|{| "declarationRangeIndex": 2 |}union|] = 100;|] //// } //// method() { return this.[|union|]; } //// } //// var x = new Foo(); //// x.[|union|]; -verify.rangesAreRenameLocations(); +verify.rangesAreRenameLocations(test.rangesByText().get("union")); diff --git a/tests/cases/fourslash/jsDocServices.ts b/tests/cases/fourslash/jsDocServices.ts index df1e985f876..75c8957b5eb 100644 --- a/tests/cases/fourslash/jsDocServices.ts +++ b/tests/cases/fourslash/jsDocServices.ts @@ -7,11 +7,12 @@ /////** //// * @param /*use*/[|foo|] I pity the foo //// */ -////function f([|/*def*/{| "isWriteAccess": true, "isDefinition": true |}foo|]: I) { +////function f([|[|/*def*/{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 1 |}foo|]: I|]) { //// return [|foo|]; ////} -const ranges = test.ranges(); +const [r0, r1Def, r1, r2] = test.ranges(); +const ranges = [r0, r1, r2]; goTo.marker("use"); verify.goToDefinitionIs("def"); verify.goToType("use", "I"); @@ -19,6 +20,6 @@ verify.goToType("use", "I"); goTo.marker("use"); verify.quickInfoIs("(parameter) foo: I", "I pity the foo"); -verify.singleReferenceGroup("(parameter) foo: I"); -verify.rangesAreDocumentHighlights(); -verify.rangesAreRenameLocations(); +verify.singleReferenceGroup("(parameter) foo: I", ranges); +verify.rangesAreDocumentHighlights(ranges); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning0.ts b/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning0.ts index c45f4aadc80..5cde088e8b2 100644 --- a/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning0.ts +++ b/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning0.ts @@ -3,14 +3,14 @@ // @allowJs: true // @Filename: a.js -/////** @typedef {number} [|{| "isWriteAccess": true, "isDefinition": true |}T|] */ +/////** [|@typedef {number} [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|]|] */ -////const [|{| "isWriteAccess": true, "isDefinition": true |}T|] = 1; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}T|] = 1;|] /////** @type {[|T|]} */ ////const n = [|T|]; -const [t0, v0, t1, v1] = test.ranges(); +const [t0Def, t0, v0Def, v0, t1, v1] = test.ranges(); verify.singleReferenceGroup("type T = number", [t0, t1]); verify.singleReferenceGroup("const T: 1", [v0, v1]); diff --git a/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts b/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts index f052d4bd870..60bef778045 100644 --- a/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts +++ b/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts @@ -4,9 +4,9 @@ // @Filename: a.js /////** @typedef {number} */ -////const [|{| "isWriteAccess": true, "isDefinition": true |}T|] = 1; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|] = 1;|] /////** @type {[|T|]} */ ////const n = [|T|]; -verify.singleReferenceGroup("type T = number\nconst T: 1"); +verify.singleReferenceGroup("type T = number\nconst T: 1", test.rangesByText().get("T")); diff --git a/tests/cases/fourslash/jsdocTypedefTagServices.ts b/tests/cases/fourslash/jsdocTypedefTagServices.ts index e4b262c3ee4..282569dfb91 100644 --- a/tests/cases/fourslash/jsdocTypedefTagServices.ts +++ b/tests/cases/fourslash/jsdocTypedefTagServices.ts @@ -5,9 +5,9 @@ /////** //// * Doc comment -//// * @typedef /*def*/[|{| "isWriteAccess": true, "isDefinition": true |}Product|] +//// * [|@typedef /*def*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Product|] //// * @property {string} title -//// */ +//// |]*/ /////** //// * @type {[|/*use*/Product|]} @@ -18,11 +18,12 @@ const desc = `type Product = { title: string; }`; +const [r0Def, ...ranges] = test.ranges(); verify.quickInfoAt("use", desc, "Doc comment"); verify.goToDefinition("use", "def"); -verify.rangesAreOccurrences(); -verify.rangesAreDocumentHighlights(); -verify.singleReferenceGroup(desc); -verify.rangesAreRenameLocations(); +verify.rangesAreOccurrences(/*isWriteAccesss*/ undefined, ranges); +verify.rangesAreDocumentHighlights(ranges); +verify.singleReferenceGroup(desc, ranges); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/jsxSpreadReference.ts b/tests/cases/fourslash/jsxSpreadReference.ts index 915dbdcecdf..3b8b9e9425a 100644 --- a/tests/cases/fourslash/jsxSpreadReference.ts +++ b/tests/cases/fourslash/jsxSpreadReference.ts @@ -14,8 +14,9 @@ //// } //// } //// -//// var [|/*dst*/nn|]: {name?: string; size?: number}; +//// [|var [|/*dst*/{| "declarationRangeIndex": 0 |}nn|]: {name?: string; size?: number};|] //// var x = ; verify.goToDefinition("src", "dst"); -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts b/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts index 63494352ff4..c2c633926d5 100644 --- a/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts +++ b/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts @@ -2,9 +2,9 @@ // @Filename: file1.ts //// class Foo { -//// constructor(private [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}privateParam|]: number, -//// public [|{| "isWriteAccess": true, "isDefinition": true, "type": "string" |}publicParam|]: string, -//// protected [|{| "isWriteAccess": true, "isDefinition": true, "type": "boolean" |}protectedParam|]: boolean) { +//// constructor([|private [|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 0 |}privateParam|]: number|], +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "type": "string", "declarationRangeIndex": 2 |}publicParam|]: string|], +//// [|protected [|{| "isWriteAccess": true, "isDefinition": true, "type": "boolean", "declarationRangeIndex": 4 |}protectedParam|]: boolean|]) { //// //// let localPrivate = [|privateParam|]; //// this.[|{| "isWriteAccess": true |}privateParam|] += 10; @@ -18,6 +18,8 @@ //// } test.rangesByText().forEach((ranges, text) => { + if (text !== "privateParam" && text !== "publicParam" && text !== "protectedParam") return; + const [r0, r1, r2] = ranges; const type = r0.marker.data.type; verify.referenceGroups(ranges, [