Skip to content

Commit edad317

Browse files
committed
Fourslash server tests
1 parent 018026a commit edad317

File tree

7 files changed

+24
-17
lines changed

7 files changed

+24
-17
lines changed

src/harness/client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,12 @@ namespace ts.server {
395395
const locations: RenameLocation[] = [];
396396
for (const entry of body.locs) {
397397
const fileName = entry.file;
398-
for (const { start, end, ...prefixSuffixText } of entry.locs) {
399-
locations.push({ textSpan: this.decodeSpan({ start, end }, fileName), fileName, ...prefixSuffixText });
398+
for (const { start, end, declarationStart, declarationEnd, ...prefixSuffixText } of entry.locs) {
399+
const renameLocation: RenameLocation = { textSpan: this.decodeSpan({ start, end }, fileName), fileName, ...prefixSuffixText };
400+
if (declarationStart !== undefined) {
401+
renameLocation.declarationSpan = this.decodeSpan({ start: declarationStart, end: declarationEnd! }, fileName);
402+
}
403+
locations.push(renameLocation);
400404
}
401405
}
402406

tests/cases/fourslash/server/jsdocCallbackTagRename01.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// @Filename: jsDocCallback.js
55
////
66
//// /**
7-
//// * @callback [|FooCallback|]
7+
//// * [|@callback [|{| "declarationRangeIndex": 0 |}FooCallback|]
88
//// * @param {string} eventName - Rename should work
9-
//// */
9+
//// |]*/
1010
////
1111
//// /** @type {/*1*/[|FooCallback|]} */
1212
//// var t;
1313

14-
const ranges = test.ranges();
14+
const [rDef, ...ranges] = test.ranges();
1515
verify.renameLocations(ranges[0], { findInStrings: false, findInComments: true, ranges });

tests/cases/fourslash/server/jsdocTypedefTagRename01.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
// @Filename: jsDocTypedef_form1.js
55
////
66
//// /** @typedef {(string | number)} */
7-
//// var [|NumberLike|];
7+
//// [|var [|{| "declarationRangeIndex": 0 |}NumberLike|];|]
88
////
99
//// [|NumberLike|] = 10;
1010
////
1111
//// /** @type {[|NumberLike|]} */
1212
//// var numberLike;
1313

14-
verify.rangesAreRenameLocations({ findInComments: true });
14+
const [rDef, ...ranges] = test.ranges();
15+
verify.rangesAreRenameLocations({ findInComments: true, ranges });

tests/cases/fourslash/server/jsdocTypedefTagRename02.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
// @allowNonTsExtensions: true
44
// @Filename: jsDocTypedef_form2.js
55
////
6-
//// /** @typedef {(string | number)} [|NumberLike|] */
6+
//// /** [|@typedef {(string | number)} [|{| "declarationRangeIndex": 0 |}NumberLike|]|] */
77
////
88
//// /** @type {[|NumberLike|]} */
99
//// var numberLike;
1010

11-
verify.rangesAreRenameLocations({ findInComments: true });
11+
const [rDef, ...ranges] = test.ranges();
12+
verify.rangesAreRenameLocations({ findInComments: true, ranges });

tests/cases/fourslash/server/jsdocTypedefTagRename03.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
// @Filename: jsDocTypedef_form3.js
55
////
66
//// /**
7-
//// * @typedef /*1*/[|Person|]
7+
//// * [|@typedef /*1*/[|{| "declarationRangeIndex": 0 |}Person|]
88
//// * @type {Object}
99
//// * @property {number} age
1010
//// * @property {string} name
11-
//// */
11+
//// |]*/
1212
////
1313
//// /** @type {/*2*/[|Person|]} */
1414
//// var person;
1515

1616
goTo.file('jsDocTypedef_form3.js')
17-
verify.rangesAreRenameLocations({ findInComments: true });
17+
verify.rangesAreRenameLocations({ findInComments: true, ranges: test.rangesByText().get("Person") });

tests/cases/fourslash/server/rename01.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
///////<reference path="./Bar.ts" />
44

5-
////function [|Bar|]() {
5+
////[|function [|{| "declarationRangeIndex": 0 |}Bar|]() {
66
//// // This is a reference to [|Bar|] in a comment.
77
//// "this is a reference to [|Bar|] in a string"
8-
////}
8+
////}|]
99

10-
const ranges = test.ranges();
10+
const [rDef, ...ranges] = test.ranges();
1111
verify.renameLocations(ranges[0], { findInStrings: true, findInComments: true, ranges });
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/// <reference path="../fourslash.ts"/>
22

33
// @Filename: referencesForGlobals_1.ts
4-
////var [|globalName|] = 0;
4+
////[|var [|{| "declarationRangeIndex": 0 |}globalName|] = 0;|]
55

66
// @Filename: referencesForGlobals_2.ts
77
////var y = [|globalName|];
88

99
// @Filename: tsconfig.json
1010
////{ "files": ["referencesForGlobals_1.ts", "referencesForGlobals_2.ts"] }
1111

12-
verify.rangesAreRenameLocations({ findInStrings: true, findInComments: true });
12+
const [rDef, ...ranges] = test.ranges();
13+
verify.rangesAreRenameLocations({ findInStrings: true, findInComments: true, ranges });

0 commit comments

Comments
 (0)