Skip to content

Commit 60dc789

Browse files
committed
Attributes now supported when renaming
1 parent a2c4f56 commit 60dc789

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

server/src/capabilities/capabilities.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,10 +1008,16 @@ export class ScopeItemCapability {
10081008

10091009
private getItemsIdentifiedAtPosition(position: Position, results: ScopeItemCapability[] = [], searchItems: ScopeItemCapability[] = []): void {
10101010
while (searchItems.length > 0) {
1011+
// Get the next scope to search.
10111012
const scope = searchItems.pop();
1013+
if (scope === undefined) continue;
1014+
1015+
// Get the standard maps and add attributes to them if they exist.
1016+
const scopeMaps = scope.maps ?? [];
1017+
if (scope.attributes) scopeMaps.push(scope.attributes);
10121018

10131019
// Check all items for whether they have a name overlap or a scope overlap.
1014-
scope?.maps.forEach(map => map.forEach(items => items.forEach(item => {
1020+
scopeMaps.forEach(map => map.forEach(items => items.forEach(item => {
10151021
const elementRange = item.range;
10161022
const identifierRange = item.element?.identifierCapability?.range;
10171023
if (identifierRange && isPositionInsideRange(position, identifierRange)) {
@@ -1026,13 +1032,13 @@ export class ScopeItemCapability {
10261032
}
10271033

10281034
getRenameItems(uri: string, position: Position): ScopeItemCapability[] {
1029-
const module = this.findModuleByUri(uri);
1030-
if (!module) {
1035+
const moduleScope = this.findModuleByUri(uri);
1036+
if (!moduleScope) {
10311037
return [];
10321038
}
10331039

10341040
const itemsAtPosition: ScopeItemCapability[] = [];
1035-
this.getItemsIdentifiedAtPosition(position, itemsAtPosition, [module]);
1041+
this.getItemsIdentifiedAtPosition(position, itemsAtPosition, [moduleScope]);
10361042
if (itemsAtPosition.length === 0) {
10371043
Services.logger.warn(`Nothing to rename.`);
10381044
return [];
@@ -1051,14 +1057,15 @@ export class ScopeItemCapability {
10511057
item.parent.properties.letters?.get(item.identifier)
10521058
]
10531059
: item
1054-
).flat().flat().flat().filter(x => !!x);
1060+
).flat(2).filter(x => !!x);
10551061

1056-
// Add backlinks for each item.
1057-
const addedBacklinks = propertyIncludedItems.map(item =>
1058-
item.backlinks ? [item, ...item.backlinks] : item
1059-
).flat().flat();
1062+
// Add backlinks and attributes for each item.
1063+
const addedReferences = propertyIncludedItems.map(item => [
1064+
item.backlinks ? [item, ...item.backlinks] : item,
1065+
item.attributes?.get(item.name) ? [item, ...item.attributes.get(item.name)!] : item
1066+
]).flat(2);
10601067

1061-
const uniqueItemsAtPosition = this.removeDuplicatesByRange(addedBacklinks);
1068+
const uniqueItemsAtPosition = this.removeDuplicatesByRange(addedReferences);
10621069
return uniqueItemsAtPosition;
10631070
}
10641071

0 commit comments

Comments
 (0)