Skip to content

Commit 49d81aa

Browse files
committed
fix(language-server): rename response should use URI instead of file name (#1462)
fixes #1460 (cherry picked from commit 8112841)
1 parent 26f6fcf commit 49d81aa

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed

integration/lsp/ivy_spec.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {URI} from 'vscode-uri';
1515
import {ProjectLanguageService, ProjectLanguageServiceParams, SuggestStrictMode, SuggestStrictModeParams} from '../../common/notifications';
1616
import {NgccProgress, NgccProgressToken, NgccProgressType} from '../../common/progress';
1717
import {GetComponentsWithTemplateFile, GetTcbRequest, IsInAngularProject} from '../../common/requests';
18-
import {APP_COMPONENT, FOO_COMPONENT, FOO_TEMPLATE, PROJECT_PATH, TSCONFIG} from '../test_constants';
18+
import {APP_COMPONENT, APP_COMPONENT_URI, FOO_COMPONENT_URI, FOO_TEMPLATE, FOO_TEMPLATE_URI, PROJECT_PATH, TSCONFIG} from '../test_constants';
1919

2020
import {createConnection, createTracer, initializeServer, openTextDocument} from './test_utils';
2121

@@ -66,7 +66,7 @@ describe('Angular Ivy language server', () => {
6666
expect(languageServiceEnabled).toBeTrue();
6767
const response = await client.sendRequest(lsp.HoverRequest.type, {
6868
textDocument: {
69-
uri: `file://${APP_COMPONENT}`,
69+
uri: APP_COMPONENT_URI,
7070
},
7171
position: {line: 4, character: 25},
7272
});
@@ -87,7 +87,7 @@ describe('Angular Ivy language server', () => {
8787
it('should show diagnostics for external template on open', async () => {
8888
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
8989
textDocument: {
90-
uri: `file://${FOO_TEMPLATE}`,
90+
uri: FOO_TEMPLATE_URI,
9191
languageId: 'html',
9292
version: 1,
9393
text: `{{ doesnotexist }}`,
@@ -108,7 +108,7 @@ describe('Angular Ivy language server', () => {
108108
// Send a request and immediately cancel it
109109
const promise = client.sendRequest(lsp.HoverRequest.type, {
110110
textDocument: {
111-
uri: `file://${APP_COMPONENT}`,
111+
uri: FOO_COMPONENT_URI,
112112
},
113113
position: {line: 4, character: 25},
114114
});
@@ -122,7 +122,7 @@ describe('Angular Ivy language server', () => {
122122
it('does not break after opening `.d.ts` file from external template', async () => {
123123
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
124124
textDocument: {
125-
uri: `file://${FOO_TEMPLATE}`,
125+
uri: FOO_TEMPLATE_URI,
126126
languageId: 'html',
127127
version: 1,
128128
text: `<div *ngIf="false"></div>`,
@@ -132,7 +132,7 @@ describe('Angular Ivy language server', () => {
132132
expect(languageServiceEnabled).toBeTrue();
133133
const response = await client.sendRequest(lsp.DefinitionRequest.type, {
134134
textDocument: {
135-
uri: `file://${FOO_TEMPLATE}`,
135+
uri: FOO_TEMPLATE_URI,
136136
},
137137
position: {line: 0, character: 7},
138138
}) as lsp.LocationLink[];
@@ -145,7 +145,7 @@ describe('Angular Ivy language server', () => {
145145
// try a hover operation again on *ngIf
146146
const hoverResponse = await client.sendRequest(lsp.HoverRequest.type, {
147147
textDocument: {
148-
uri: `file://${FOO_TEMPLATE}`,
148+
uri: FOO_TEMPLATE_URI,
149149
},
150150
position: {line: 0, character: 7},
151151
});
@@ -159,7 +159,7 @@ describe('Angular Ivy language server', () => {
159159
it('should show signature help for an empty call', async () => {
160160
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
161161
textDocument: {
162-
uri: `file://${FOO_TEMPLATE}`,
162+
uri: FOO_TEMPLATE_URI,
163163
languageId: 'html',
164164
version: 1,
165165
text: `{{ title.toString() }}`,
@@ -169,7 +169,7 @@ describe('Angular Ivy language server', () => {
169169
expect(languageServiceEnabled).toBeTrue();
170170
const response = (await client.sendRequest(lsp.SignatureHelpRequest.type, {
171171
textDocument: {
172-
uri: `file://${FOO_TEMPLATE}`,
172+
uri: FOO_TEMPLATE_URI,
173173
},
174174
position: {line: 0, character: 18},
175175
}))!;
@@ -181,7 +181,7 @@ describe('Angular Ivy language server', () => {
181181
it('should show signature help with multiple arguments', async () => {
182182
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
183183
textDocument: {
184-
uri: `file://${FOO_TEMPLATE}`,
184+
uri: FOO_TEMPLATE_URI,
185185
languageId: 'html',
186186
version: 1,
187187
text: `{{ title.substr(0, ) }}`,
@@ -191,7 +191,7 @@ describe('Angular Ivy language server', () => {
191191
expect(languageServiceEnabled).toBeTrue();
192192
const response = (await client.sendRequest(lsp.SignatureHelpRequest.type, {
193193
textDocument: {
194-
uri: `file://${FOO_TEMPLATE}`,
194+
uri: FOO_TEMPLATE_URI,
195195
},
196196
position: {line: 0, character: 19},
197197
}))!;
@@ -241,7 +241,7 @@ describe('Angular Ivy language server', () => {
241241
expect(languageServiceEnabled).toBeTrue();
242242
const response = await client.sendRequest(lsp.CompletionRequest.type, {
243243
textDocument: {
244-
uri: `file://${FOO_TEMPLATE}`,
244+
uri: FOO_TEMPLATE_URI,
245245
},
246246
position: {line: 0, character: 9},
247247
}) as lsp.CompletionItem[];
@@ -264,7 +264,7 @@ describe('Angular Ivy language server', () => {
264264
it('should handle prepare rename request for property read', async () => {
265265
const response = await client.sendRequest(lsp.PrepareRenameRequest.type, {
266266
textDocument: {
267-
uri: `file://${FOO_TEMPLATE}`,
267+
uri: FOO_TEMPLATE_URI,
268268
},
269269
position: {line: 0, character: 3},
270270
}) as {range: lsp.Range, placeholder: string};
@@ -293,16 +293,16 @@ describe('Angular Ivy language server', () => {
293293
it('should handle rename request for property read', async () => {
294294
const response = await client.sendRequest(lsp.RenameRequest.type, {
295295
textDocument: {
296-
uri: `file://${FOO_TEMPLATE}`,
296+
uri: FOO_TEMPLATE_URI,
297297
},
298298
position: {line: 0, character: 3},
299299
newName: 'subtitle'
300300
});
301301
expect(response).not.toBeNull();
302-
expect(response?.changes?.[FOO_TEMPLATE].length).toBe(1);
303-
expect(response?.changes?.[FOO_TEMPLATE]).toContain(expectedRenameInTemplate);
304-
expect(response?.changes?.[FOO_COMPONENT].length).toBe(1);
305-
expect(response?.changes?.[FOO_COMPONENT]).toContain(expectedRenameInComponent);
302+
expect(response?.changes?.[FOO_TEMPLATE_URI].length).toBe(1);
303+
expect(response?.changes?.[FOO_TEMPLATE_URI]).toContain(expectedRenameInTemplate);
304+
expect(response?.changes?.[FOO_COMPONENT_URI].length).toBe(1);
305+
expect(response?.changes?.[FOO_COMPONENT_URI]).toContain(expectedRenameInComponent);
306306
});
307307
});
308308

@@ -316,7 +316,7 @@ describe('Angular Ivy language server', () => {
316316
it('should handle prepare rename request for inline template property read', async () => {
317317
const response = await client.sendRequest(lsp.PrepareRenameRequest.type, {
318318
textDocument: {
319-
uri: `file://${APP_COMPONENT}`,
319+
uri: APP_COMPONENT_URI,
320320
},
321321
position: {line: 4, character: 25},
322322
}) as {range: lsp.Range, placeholder: string};
@@ -346,29 +346,29 @@ describe('Angular Ivy language server', () => {
346346
it('should handle rename request for property read in a template', async () => {
347347
const response = await client.sendRequest(lsp.RenameRequest.type, {
348348
textDocument: {
349-
uri: `file://${APP_COMPONENT}`,
349+
uri: APP_COMPONENT_URI,
350350
},
351351
position: {line: 4, character: 25},
352352
newName: 'surname'
353353
});
354354
expect(response).not.toBeNull();
355-
expect(response?.changes?.[APP_COMPONENT].length).toBe(2);
356-
expect(response?.changes?.[APP_COMPONENT]).toContain(expectedRenameInComponent);
357-
expect(response?.changes?.[APP_COMPONENT]).toContain(expectedRenameInTemplate);
355+
expect(response?.changes?.[APP_COMPONENT_URI].length).toBe(2);
356+
expect(response?.changes?.[APP_COMPONENT_URI]).toContain(expectedRenameInComponent);
357+
expect(response?.changes?.[APP_COMPONENT_URI]).toContain(expectedRenameInTemplate);
358358
});
359359

360360
it('should handle rename request for property in the component', async () => {
361361
const response = await client.sendRequest(lsp.RenameRequest.type, {
362362
textDocument: {
363-
uri: `file://${APP_COMPONENT}`,
363+
uri: APP_COMPONENT_URI,
364364
},
365365
position: {line: 7, character: 4},
366366
newName: 'surname'
367367
});
368368
expect(response).not.toBeNull();
369-
expect(response?.changes?.[APP_COMPONENT].length).toBe(2);
370-
expect(response?.changes?.[APP_COMPONENT]).toContain(expectedRenameInComponent);
371-
expect(response?.changes?.[APP_COMPONENT]).toContain(expectedRenameInTemplate);
369+
expect(response?.changes?.[APP_COMPONENT_URI].length).toBe(2);
370+
expect(response?.changes?.[APP_COMPONENT_URI]).toContain(expectedRenameInComponent);
371+
expect(response?.changes?.[APP_COMPONENT_URI]).toContain(expectedRenameInTemplate);
372372
});
373373
});
374374
});
@@ -403,15 +403,15 @@ describe('Angular Ivy language server', () => {
403403

404404
const prepareRenameResponse = await client.sendRequest(lsp.PrepareRenameRequest.type, {
405405
textDocument: {
406-
uri: `file://${APP_COMPONENT}`,
406+
uri: FOO_COMPONENT_URI,
407407
},
408408
position: {line: 4, character: 25},
409409
}) as {range: lsp.Range, placeholder: string};
410410
expect(prepareRenameResponse).toBeNull();
411411

412412
const renameResponse = await client.sendRequest(lsp.RenameRequest.type, {
413413
textDocument: {
414-
uri: `file://${APP_COMPONENT}`,
414+
uri: FOO_COMPONENT_URI,
415415
},
416416
position: {line: 4, character: 25},
417417
newName: 'surname'
@@ -426,7 +426,7 @@ describe('Angular Ivy language server', () => {
426426
await waitForNgcc(client);
427427
const response = await client.sendRequest(GetTcbRequest, {
428428
textDocument: {
429-
uri: `file://${FOO_TEMPLATE}`,
429+
uri: FOO_TEMPLATE_URI,
430430
},
431431
position: {line: 0, character: 3},
432432
});
@@ -438,7 +438,7 @@ describe('Angular Ivy language server', () => {
438438
await waitForNgcc(client);
439439
const response = await client.sendRequest(GetComponentsWithTemplateFile, {
440440
textDocument: {
441-
uri: `file://${FOO_TEMPLATE}`,
441+
uri: FOO_TEMPLATE_URI,
442442
}
443443
});
444444
expect(response).toBeDefined();
@@ -449,12 +449,12 @@ describe('Angular Ivy language server', () => {
449449
await waitForNgcc(client);
450450
const codeLensResponse = await client.sendRequest(lsp.CodeLensRequest.type, {
451451
textDocument: {
452-
uri: `file://${FOO_TEMPLATE}`,
452+
uri: FOO_TEMPLATE_URI,
453453
}
454454
});
455455
expect(codeLensResponse).toBeDefined();
456456
const [codeLens] = codeLensResponse!;
457-
expect(codeLens.data.uri).toEqual(`file://${FOO_TEMPLATE}`);
457+
expect(codeLens.data.uri).toEqual(FOO_TEMPLATE_URI);
458458

459459
const codeLensResolveResponse =
460460
await client.sendRequest(lsp.CodeLensResolveRequest.type, codeLensResponse![0]);
@@ -467,13 +467,13 @@ describe('Angular Ivy language server', () => {
467467
await waitForNgcc(client);
468468
const templateResponse = await client.sendRequest(IsInAngularProject, {
469469
textDocument: {
470-
uri: `file://${FOO_TEMPLATE}`,
470+
uri: FOO_TEMPLATE_URI,
471471
}
472472
});
473473
expect(templateResponse).toBe(true);
474474
const componentResponse = await client.sendRequest(IsInAngularProject, {
475475
textDocument: {
476-
uri: `file://${FOO_COMPONENT}`,
476+
uri: FOO_COMPONENT_URI,
477477
}
478478
});
479479
expect(componentResponse).toBe(true);

integration/test_constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export const PACKAGE_ROOT = resolve(__dirname, '../..');
44
export const SERVER_PATH = join(PACKAGE_ROOT, 'dist', 'npm', 'server', 'index.js');
55
export const PROJECT_PATH = join(PACKAGE_ROOT, 'integration', 'project');
66
export const APP_COMPONENT = join(PROJECT_PATH, 'app', 'app.component.ts');
7+
export const APP_COMPONENT_URI = `file://${APP_COMPONENT}`;
78
export const FOO_TEMPLATE = join(PROJECT_PATH, 'app', 'foo.component.html');
9+
export const FOO_TEMPLATE_URI = `file://${FOO_TEMPLATE}`;
810
export const FOO_COMPONENT = join(PROJECT_PATH, 'app', 'foo.component.ts');
11+
export const FOO_COMPONENT_URI = `file://${FOO_COMPONENT}`;
912
export const TSCONFIG = join(PROJECT_PATH, 'tsconfig.json');

server/src/session.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,10 +817,11 @@ export class Session {
817817
}
818818

819819
const changes = renameLocations.reduce((changes, location) => {
820-
if (changes[location.fileName] === undefined) {
821-
changes[location.fileName] = [];
820+
let uri: lsp.URI = filePathToUri(location.fileName);
821+
if (changes[uri] === undefined) {
822+
changes[uri] = [];
822823
}
823-
const fileEdits = changes[location.fileName];
824+
const fileEdits = changes[uri];
824825

825826
const lsInfo = this.getLSAndScriptInfo(location.fileName);
826827
if (lsInfo === null) {

0 commit comments

Comments
 (0)