fix(language-service): Correct rename info for pipe name expressions (#41974)
Prior to this PR, attempting to get rename info for pipe name expressions would defer to the typescript language service, which would return no rename info. This was not caught because the test was written incorrectly. This PR corrects the test behavior and adjusts the logic in getting rename info to account for indirect renames (like pipe names). PR Close #41974
This commit is contained in:
parent
f8814d3558
commit
fe22c2b0b6
|
@ -154,7 +154,29 @@ export class RenameBuilder {
|
|||
// We could not get a template at position so we assume the request came from outside the
|
||||
// template.
|
||||
if (templateInfo === undefined) {
|
||||
return this.tsLS.getRenameInfo(filePath, position);
|
||||
const renameRequest = this.buildRenameRequestAtTypescriptPosition(filePath, position);
|
||||
if (renameRequest === null) {
|
||||
return {
|
||||
canRename: false,
|
||||
localizedErrorMessage: 'Could not determine rename info at typescript position.',
|
||||
};
|
||||
}
|
||||
if (renameRequest.type === RequestKind.PipeName) {
|
||||
const pipeName = renameRequest.pipeNameExpr.text;
|
||||
return {
|
||||
canRename: true,
|
||||
displayName: pipeName,
|
||||
fullDisplayName: pipeName,
|
||||
triggerSpan: {
|
||||
length: pipeName.length,
|
||||
// Offset the pipe name by 1 to account for start of string '/`/"
|
||||
start: renameRequest.pipeNameExpr.getStart() + 1,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
// TODO(atscott): Add support for other special indirect renames from typescript files.
|
||||
return this.tsLS.getRenameInfo(filePath, position);
|
||||
}
|
||||
}
|
||||
|
||||
const allTargetDetails = getTargetDetailsAtTemplatePosition(templateInfo, position, this.ttc);
|
||||
|
|
|
@ -809,20 +809,23 @@ describe('find references and rename locations', () => {
|
|||
birthday = '';
|
||||
}
|
||||
`,
|
||||
'prefix-pipe.ts': prefixPipe
|
||||
'prefix_pipe.ts': prefixPipe
|
||||
};
|
||||
env = LanguageServiceTestEnv.setup();
|
||||
const project = createModuleAndProjectWithDeclarations(env, 'test', files);
|
||||
const file = project.openFile('app.ts');
|
||||
file.moveCursorToText('prefi¦xPipe:');
|
||||
const file = project.openFile('prefix_pipe.ts');
|
||||
file.moveCursorToText(`'prefi¦xPipe'`);
|
||||
const renameLocations = getRenameLocationsAtPosition(file)!;
|
||||
expect(renameLocations.length).toBe(2);
|
||||
assertFileNames(renameLocations, ['prefix-pipe.ts', 'app.ts']);
|
||||
assertFileNames(renameLocations, ['prefix_pipe.ts', 'app.ts']);
|
||||
assertTextSpans(renameLocations, ['prefixPipe']);
|
||||
|
||||
const result = file.getRenameInfo() as ts.RenameInfoSuccess;
|
||||
expect(result.canRename).toEqual(true);
|
||||
expect(result.displayName).toEqual('prefixPipe');
|
||||
expect(file.contents.substring(
|
||||
result.triggerSpan.start, result.triggerSpan.start + result.triggerSpan.length))
|
||||
.toBe('prefixPipe');
|
||||
});
|
||||
|
||||
it('finds rename locations in base class', () => {
|
||||
|
|
Loading…
Reference in New Issue