Skip to content

fix(language-server): rename response should use URI instead of fileName #1462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions integration/lsp/ivy_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {URI} from 'vscode-uri';
import {ProjectLanguageService, ProjectLanguageServiceParams, SuggestStrictMode, SuggestStrictModeParams} from '../../common/notifications';
import {NgccProgress, NgccProgressToken, NgccProgressType} from '../../common/progress';
import {GetComponentsWithTemplateFile, GetTcbRequest, IsInAngularProject} from '../../common/requests';
import {APP_COMPONENT, FOO_COMPONENT, FOO_TEMPLATE, PROJECT_PATH, TSCONFIG} from '../test_constants';
import {APP_COMPONENT, APP_COMPONENT_URI, FOO_COMPONENT_URI, FOO_TEMPLATE, FOO_TEMPLATE_URI, PROJECT_PATH, TSCONFIG} from '../test_constants';

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

Expand Down Expand Up @@ -66,7 +66,7 @@ describe('Angular Ivy language server', () => {
expect(languageServiceEnabled).toBeTrue();
const response = await client.sendRequest(lsp.HoverRequest.type, {
textDocument: {
uri: `file://${APP_COMPONENT}`,
uri: APP_COMPONENT_URI,
},
position: {line: 4, character: 25},
});
Expand All @@ -87,7 +87,7 @@ describe('Angular Ivy language server', () => {
it('should show diagnostics for external template on open', async () => {
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
languageId: 'html',
version: 1,
text: `{{ doesnotexist }}`,
Expand All @@ -108,7 +108,7 @@ describe('Angular Ivy language server', () => {
// Send a request and immediately cancel it
const promise = client.sendRequest(lsp.HoverRequest.type, {
textDocument: {
uri: `file://${APP_COMPONENT}`,
uri: FOO_COMPONENT_URI,
},
position: {line: 4, character: 25},
});
Expand All @@ -122,7 +122,7 @@ describe('Angular Ivy language server', () => {
it('does not break after opening `.d.ts` file from external template', async () => {
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
languageId: 'html',
version: 1,
text: `<div *ngIf="false"></div>`,
Expand All @@ -132,7 +132,7 @@ describe('Angular Ivy language server', () => {
expect(languageServiceEnabled).toBeTrue();
const response = await client.sendRequest(lsp.DefinitionRequest.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
},
position: {line: 0, character: 7},
}) as lsp.LocationLink[];
Expand All @@ -145,7 +145,7 @@ describe('Angular Ivy language server', () => {
// try a hover operation again on *ngIf
const hoverResponse = await client.sendRequest(lsp.HoverRequest.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
},
position: {line: 0, character: 7},
});
Expand All @@ -159,7 +159,7 @@ describe('Angular Ivy language server', () => {
it('should show signature help for an empty call', async () => {
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
languageId: 'html',
version: 1,
text: `{{ title.toString() }}`,
Expand All @@ -169,7 +169,7 @@ describe('Angular Ivy language server', () => {
expect(languageServiceEnabled).toBeTrue();
const response = (await client.sendRequest(lsp.SignatureHelpRequest.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
},
position: {line: 0, character: 18},
}))!;
Expand All @@ -181,7 +181,7 @@ describe('Angular Ivy language server', () => {
it('should show signature help with multiple arguments', async () => {
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
languageId: 'html',
version: 1,
text: `{{ title.substr(0, ) }}`,
Expand All @@ -191,7 +191,7 @@ describe('Angular Ivy language server', () => {
expect(languageServiceEnabled).toBeTrue();
const response = (await client.sendRequest(lsp.SignatureHelpRequest.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
},
position: {line: 0, character: 19},
}))!;
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('Angular Ivy language server', () => {
expect(languageServiceEnabled).toBeTrue();
const response = await client.sendRequest(lsp.CompletionRequest.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
},
position: {line: 0, character: 9},
}) as lsp.CompletionItem[];
Expand All @@ -264,7 +264,7 @@ describe('Angular Ivy language server', () => {
it('should handle prepare rename request for property read', async () => {
const response = await client.sendRequest(lsp.PrepareRenameRequest.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
},
position: {line: 0, character: 3},
}) as {range: lsp.Range, placeholder: string};
Expand Down Expand Up @@ -293,16 +293,16 @@ describe('Angular Ivy language server', () => {
it('should handle rename request for property read', async () => {
const response = await client.sendRequest(lsp.RenameRequest.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
},
position: {line: 0, character: 3},
newName: 'subtitle'
});
expect(response).not.toBeNull();
expect(response?.changes?.[FOO_TEMPLATE].length).toBe(1);
expect(response?.changes?.[FOO_TEMPLATE]).toContain(expectedRenameInTemplate);
expect(response?.changes?.[FOO_COMPONENT].length).toBe(1);
expect(response?.changes?.[FOO_COMPONENT]).toContain(expectedRenameInComponent);
expect(response?.changes?.[FOO_TEMPLATE_URI].length).toBe(1);
expect(response?.changes?.[FOO_TEMPLATE_URI]).toContain(expectedRenameInTemplate);
expect(response?.changes?.[FOO_COMPONENT_URI].length).toBe(1);
expect(response?.changes?.[FOO_COMPONENT_URI]).toContain(expectedRenameInComponent);
});
});

Expand All @@ -316,7 +316,7 @@ describe('Angular Ivy language server', () => {
it('should handle prepare rename request for inline template property read', async () => {
const response = await client.sendRequest(lsp.PrepareRenameRequest.type, {
textDocument: {
uri: `file://${APP_COMPONENT}`,
uri: APP_COMPONENT_URI,
},
position: {line: 4, character: 25},
}) as {range: lsp.Range, placeholder: string};
Expand Down Expand Up @@ -346,29 +346,29 @@ describe('Angular Ivy language server', () => {
it('should handle rename request for property read in a template', async () => {
const response = await client.sendRequest(lsp.RenameRequest.type, {
textDocument: {
uri: `file://${APP_COMPONENT}`,
uri: APP_COMPONENT_URI,
},
position: {line: 4, character: 25},
newName: 'surname'
});
expect(response).not.toBeNull();
expect(response?.changes?.[APP_COMPONENT].length).toBe(2);
expect(response?.changes?.[APP_COMPONENT]).toContain(expectedRenameInComponent);
expect(response?.changes?.[APP_COMPONENT]).toContain(expectedRenameInTemplate);
expect(response?.changes?.[APP_COMPONENT_URI].length).toBe(2);
expect(response?.changes?.[APP_COMPONENT_URI]).toContain(expectedRenameInComponent);
expect(response?.changes?.[APP_COMPONENT_URI]).toContain(expectedRenameInTemplate);
});

it('should handle rename request for property in the component', async () => {
const response = await client.sendRequest(lsp.RenameRequest.type, {
textDocument: {
uri: `file://${APP_COMPONENT}`,
uri: APP_COMPONENT_URI,
},
position: {line: 7, character: 4},
newName: 'surname'
});
expect(response).not.toBeNull();
expect(response?.changes?.[APP_COMPONENT].length).toBe(2);
expect(response?.changes?.[APP_COMPONENT]).toContain(expectedRenameInComponent);
expect(response?.changes?.[APP_COMPONENT]).toContain(expectedRenameInTemplate);
expect(response?.changes?.[APP_COMPONENT_URI].length).toBe(2);
expect(response?.changes?.[APP_COMPONENT_URI]).toContain(expectedRenameInComponent);
expect(response?.changes?.[APP_COMPONENT_URI]).toContain(expectedRenameInTemplate);
});
});
});
Expand Down Expand Up @@ -403,15 +403,15 @@ describe('Angular Ivy language server', () => {

const prepareRenameResponse = await client.sendRequest(lsp.PrepareRenameRequest.type, {
textDocument: {
uri: `file://${APP_COMPONENT}`,
uri: FOO_COMPONENT_URI,
},
position: {line: 4, character: 25},
}) as {range: lsp.Range, placeholder: string};
expect(prepareRenameResponse).toBeNull();

const renameResponse = await client.sendRequest(lsp.RenameRequest.type, {
textDocument: {
uri: `file://${APP_COMPONENT}`,
uri: FOO_COMPONENT_URI,
},
position: {line: 4, character: 25},
newName: 'surname'
Expand All @@ -426,7 +426,7 @@ describe('Angular Ivy language server', () => {
await waitForNgcc(client);
const response = await client.sendRequest(GetTcbRequest, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
},
position: {line: 0, character: 3},
});
Expand All @@ -438,7 +438,7 @@ describe('Angular Ivy language server', () => {
await waitForNgcc(client);
const response = await client.sendRequest(GetComponentsWithTemplateFile, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
}
});
expect(response).toBeDefined();
Expand All @@ -449,12 +449,12 @@ describe('Angular Ivy language server', () => {
await waitForNgcc(client);
const codeLensResponse = await client.sendRequest(lsp.CodeLensRequest.type, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
}
});
expect(codeLensResponse).toBeDefined();
const [codeLens] = codeLensResponse!;
expect(codeLens.data.uri).toEqual(`file://${FOO_TEMPLATE}`);
expect(codeLens.data.uri).toEqual(FOO_TEMPLATE_URI);

const codeLensResolveResponse =
await client.sendRequest(lsp.CodeLensResolveRequest.type, codeLensResponse![0]);
Expand All @@ -467,13 +467,13 @@ describe('Angular Ivy language server', () => {
await waitForNgcc(client);
const templateResponse = await client.sendRequest(IsInAngularProject, {
textDocument: {
uri: `file://${FOO_TEMPLATE}`,
uri: FOO_TEMPLATE_URI,
}
});
expect(templateResponse).toBe(true);
const componentResponse = await client.sendRequest(IsInAngularProject, {
textDocument: {
uri: `file://${FOO_COMPONENT}`,
uri: FOO_COMPONENT_URI,
}
});
expect(componentResponse).toBe(true);
Expand Down
3 changes: 3 additions & 0 deletions integration/test_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export const PACKAGE_ROOT = resolve(__dirname, '../..');
export const SERVER_PATH = join(PACKAGE_ROOT, 'dist', 'npm', 'server', 'index.js');
export const PROJECT_PATH = join(PACKAGE_ROOT, 'integration', 'project');
export const APP_COMPONENT = join(PROJECT_PATH, 'app', 'app.component.ts');
export const APP_COMPONENT_URI = `file://${APP_COMPONENT}`;
export const FOO_TEMPLATE = join(PROJECT_PATH, 'app', 'foo.component.html');
export const FOO_TEMPLATE_URI = `file://${FOO_TEMPLATE}`;
export const FOO_COMPONENT = join(PROJECT_PATH, 'app', 'foo.component.ts');
export const FOO_COMPONENT_URI = `file://${FOO_COMPONENT}`;
export const TSCONFIG = join(PROJECT_PATH, 'tsconfig.json');
7 changes: 4 additions & 3 deletions server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,11 @@ export class Session {
}

const changes = renameLocations.reduce((changes, location) => {
if (changes[location.fileName] === undefined) {
changes[location.fileName] = [];
let uri: lsp.URI = filePathToUri(location.fileName);
if (changes[uri] === undefined) {
changes[uri] = [];
}
const fileEdits = changes[location.fileName];
const fileEdits = changes[uri];

const lsInfo = this.getLSAndScriptInfo(location.fileName);
if (lsInfo === null) {
Expand Down