Skip to content

Commit 8f3d2d9

Browse files
committed
Goto defintion will not go to source if map is present
1 parent 34a1283 commit 8f3d2d9

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10718,7 +10718,9 @@ fn5();
1071810718
path: `${projectLocation}/random/tsconfig.json`,
1071910719
content: "{}"
1072010720
};
10721-
const dtsMapLocation = `${dependecyLocation}/FnS.d.ts.map`;
10721+
const dtsLocation = `${dependecyLocation}/FnS.d.ts`;
10722+
const dtsPath = dtsLocation.toLowerCase() as Path;
10723+
const dtsMapLocation = `${dtsLocation}.map`;
1072210724
const dtsMapPath = dtsMapLocation.toLowerCase() as Path;
1072310725

1072410726
const files = [dependencyTs, dependencyConfig, mainTs, mainConfig, libFile, randomFile, randomConfig];
@@ -10736,18 +10738,25 @@ fn5();
1073610738
verifyScriptInfos(session, host, [randomFile.path], [libFile.path], [randomConfig.path]);
1073710739
}
1073810740

10739-
// Returns request and expected Response
10740-
type SessionAction<Req = protocol.Request, Response = {}> = [Partial<Req>, Response];
10741+
// Returns request and expected Response, expected response when no map file
10742+
type SessionAction<Req = protocol.Request, Response = {}> = [Partial<Req>, Response, Response?];
1074110743
function gotoDefintinionFromMainTs(fn: number): SessionAction<protocol.DefinitionAndBoundSpanRequest, protocol.DefinitionInfoAndBoundSpan> {
1074210744
const startSpan = { line: fn + 4, offset: 1 };
10745+
const textSpan: protocol.TextSpan = { start: startSpan, end: { line: startSpan.line, offset: startSpan.offset + 3 } };
10746+
const definitionSpan: protocol.FileSpan = { file: dependencyTs.path, start: { line: fn, offset: 17 }, end: { line: fn, offset: 20 } };
10747+
const declareSpaceLength = "declare ".length;
1074310748
return [
1074410749
{
1074510750
command: protocol.CommandTypes.DefinitionAndBoundSpan,
1074610751
arguments: { file: mainTs.path, ...startSpan }
1074710752
},
1074810753
{
10749-
definitions: [{ file: dependencyTs.path, start: { line: fn, offset: 17 }, end: { line: fn, offset: 20 } }],
10750-
textSpan: { start: startSpan, end: { line: startSpan.line, offset: startSpan.offset + 3 } }
10754+
definitions: [definitionSpan],
10755+
textSpan
10756+
},
10757+
{
10758+
definitions: [{ file: dtsPath, start: { line: fn, offset: definitionSpan.start.offset + declareSpaceLength }, end: { line: fn, offset: definitionSpan.end.offset + declareSpaceLength } }],
10759+
textSpan
1075110760
}
1075210761
];
1075310762
}
@@ -10812,8 +10821,8 @@ fn5();
1081210821
});
1081310822
}
1081410823

10815-
function verifyInfos(session: TestSession, host: TestServerHost, minusDtsMap?: true) {
10816-
verifyInfosWithRandom(session, host, openInfos, minusDtsMap ? closedInfos.filter(f => f.toLowerCase() !== dtsMapPath) : closedInfos, otherWatchedFiles);
10824+
function verifyInfos(session: TestSession, host: TestServerHost, minusDtsMapAndSource?: true) {
10825+
verifyInfosWithRandom(session, host, openInfos, minusDtsMapAndSource ? closedInfos.filter(f => f !== dependencyTs.path && f.toLowerCase() !== dtsMapPath) : closedInfos, otherWatchedFiles);
1081710826
}
1081810827

1081910828
function verifyDocumentPositionMapper(session: TestSession, dependencyMap: server.ScriptInfo, documentPositionMapper: server.ScriptInfo["documentPositionMapper"], notEqual?: true) {
@@ -10827,17 +10836,17 @@ fn5();
1082710836
}
1082810837

1082910838
function action(actionGetter: SessionActionGetter, fn: number, session: TestSession) {
10830-
const [req, expectedResponse] = actionGetter(fn);
10839+
const [req, expectedResponse, expectedNoMapResponse] = actionGetter(fn);
1083110840
const { response } = session.executeCommandSeq(req);
10832-
return { response, expectedResponse };
10841+
return { response, expectedResponse, expectedNoMapResponse };
1083310842
}
1083410843

1083510844
function verifyAllFnActionWorker(session: TestSession, verifyAction: (result: ReturnType<typeof action>, dtsInfo: server.ScriptInfo) => void) {
1083610845
// action
1083710846
for (const actionGetter of actionGetters) {
1083810847
for (let fn = 1; fn <= 5; fn++) {
1083910848
const result = action(actionGetter, fn, session);
10840-
const dtsInfo = session.getProjectService().filenameToScriptInfo.get(`${dependecyLocation}/fns.d.ts`);
10849+
const dtsInfo = session.getProjectService().filenameToScriptInfo.get(dtsPath);
1084110850
assert.isDefined(dtsInfo);
1084210851
verifyAction(result, dtsInfo!);
1084310852
}
@@ -10880,9 +10889,9 @@ fn5();
1088010889
host: TestServerHost
1088110890
) {
1088210891
// action
10883-
verifyAllFnActionWorker(session, ({ response, expectedResponse }, dtsInfo) => {
10884-
assert.deepEqual(response, expectedResponse);
10885-
verifyInfos(session, host);
10892+
verifyAllFnActionWorker(session, ({ response, expectedResponse, expectedNoMapResponse }, dtsInfo) => {
10893+
assert.deepEqual(response, expectedNoMapResponse && verifier.length ? expectedNoMapResponse : expectedResponse);
10894+
verifyInfos(session, host, /*minusDtsMapAndSource*/ true);
1088610895
assert.isFalse(dtsInfo.sourceMapFilePath);
1088710896
assert.isUndefined(session.getProjectService().filenameToScriptInfo.get(dtsMapPath));
1088810897
});
@@ -10957,8 +10966,8 @@ fn5();
1095710966
describe("when dependency file changes, document position mapper doesnt change", () => {
1095810967
// Edit dts to add new fn
1095910968
verifyScenarioWithChanges(host => host.writeFile(
10960-
`${dependecyLocation}/fns.d.ts`,
10961-
host.readFile(`${dependecyLocation}/fns.d.ts`)!.replace(
10969+
dtsLocation,
10970+
host.readFile(dtsLocation)!.replace(
1096210971
"//# sourceMappingURL=FnS.d.ts.map",
1096310972
`export declare function fn6(): void;
1096410973
//# sourceMappingURL=FnS.d.ts.map`
@@ -10988,12 +10997,12 @@ fn5();
1098810997

1098910998
const usageVerifier: DocumentPositionMapperVerifier = [
1099010999
/*openFile*/ mainTs,
10991-
/*expectedProjectActualFiles*/[mainTs.path, libFile.path, mainConfig.path, `${dependecyLocation}/fns.d.ts`],
11000+
/*expectedProjectActualFiles*/[mainTs.path, libFile.path, mainConfig.path, dtsPath],
1099211001
/*actionGetter*/ gotoDefintinionFromMainTs,
1099311002
/*openFileLastLine*/ 10
1099411003
];
1099511004
describe("from project that uses dependency", () => {
10996-
const closedInfos = [dependencyTs.path, dependencyConfig.path, libFile.path, `${dependecyLocation}/fns.d.ts`, dtsMapLocation];
11005+
const closedInfos = [dependencyTs.path, dependencyConfig.path, libFile.path, dtsPath, dtsMapLocation];
1099711006
verifyDocumentPositionMapperUpdates(
1099811007
"can go to definition correctly",
1099911008
[usageVerifier],
@@ -11008,7 +11017,7 @@ fn5();
1100811017
/*openFileLastLine*/ 6
1100911018
];
1101011019
describe("from defining project", () => {
11011-
const closedInfos = [libFile.path, `${dependecyLocation}/FnS.d.ts`, dtsMapLocation];
11020+
const closedInfos = [libFile.path, dtsLocation, dtsMapLocation];
1101211021
verifyDocumentPositionMapperUpdates(
1101311022
"rename locations from dependency",
1101411023
[definingVerifier],
@@ -11017,7 +11026,7 @@ fn5();
1101711026
});
1101811027

1101911028
describe("when opening depedency and usage project", () => {
11020-
const closedInfos = [libFile.path, `${dependecyLocation}/FnS.d.ts`, dtsMapLocation];
11029+
const closedInfos = [libFile.path, dtsLocation, dtsMapLocation];
1102111030
verifyDocumentPositionMapperUpdates(
1102211031
"goto Definition in usage and rename locations from defining project",
1102311032
[definingVerifier],

0 commit comments

Comments
 (0)