Skip to content

Commit 176475f

Browse files
atscottkirjs
authored andcommitted
fix(language-service): provide correct rename info for elements (#60088)
This commit ensures we do not block element rename if it is supported by other rename providers. fixes angular/vscode-ng-language-service#2077 PR Close #60088
1 parent 7d66360 commit 176475f

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎packages/language-service/src/references_and_rename_utils.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
TmplAstBoundEvent,
1717
TmplAstLetDeclaration,
1818
TmplAstNode,
19+
TmplAstElement,
1920
TmplAstReference,
2021
TmplAstTextAttribute,
2122
TmplAstVariable,
@@ -341,9 +342,7 @@ export function getRenameTextAndSpanAtPosition(
341342
} else if (node.valueSpan && isWithin(position, node.valueSpan)) {
342343
return {text: node.valueSpan.toString(), span: toTextSpan(node.valueSpan)};
343344
}
344-
}
345-
346-
if (
345+
} else if (
347346
node instanceof PropertyRead ||
348347
node instanceof PropertyWrite ||
349348
node instanceof SafePropertyRead ||
@@ -359,6 +358,8 @@ export function getRenameTextAndSpanAtPosition(
359358
span.length -= 2;
360359
}
361360
return {text, span};
361+
} else if (node instanceof TmplAstElement) {
362+
return {text: node.name, span: toTextSpan(node.startSourceSpan)};
362363
}
363364

364365
return null;

‎packages/language-service/test/references_and_rename_spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,14 @@ describe('find references and rename locations', () => {
18141814
});
18151815

18161816
it('finds rename locations', () => {
1817+
env.expectNoSourceDiagnostics();
1818+
const result = file.getRenameInfo() as ts.RenameInfoSuccess;
1819+
// Note that although we do not provide rename locations, we must _not_ respond with
1820+
// a result that indicates the item cannot be renamed when info is requested or we will prevent
1821+
// other rename providers from performing the rename.
1822+
expect(result.canRename).toBeTrue();
1823+
expect(result.displayName).toEqual('my-comp');
1824+
expect(result.kind).toEqual('component');
18171825
const renameLocations = getRenameLocationsAtPosition(file)!;
18181826
expect(renameLocations).toBeUndefined();
18191827
// TODO(atscott): We may consider supporting rename of component selector in the future

0 commit comments

Comments
 (0)