Skip to content

Commit

Permalink
Merge pull request #40546 from TharushiJay/fix-rename
Browse files Browse the repository at this point in the history
Fix issue in renaming symbols in groupby clause
  • Loading branch information
TharushiJay committed Jun 1, 2023
2 parents 66973cc + f166c9f commit 55cf7af
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,8 @@ public void visit(BLangGroupByClause groupByClause) {
Node groupingKey = keyNode.getGroupingKey();
if (groupingKey.getKind() == NodeKind.VARIABLE_DEF) {
find((BLangSimpleVariableDef) keyNode.getGroupingKey());
} else if (groupingKey.getKind() == NodeKind.VARIABLE) {
} else if (groupingKey.getKind() == NodeKind.VARIABLE
|| groupingKey.getKind() == NodeKind.SIMPLE_VARIABLE_REF) {
find((BLangSimpleVarRef) keyNode.getGroupingKey());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public Object[][] testDataProvider() {
{"rename_in_mapping_binding_pattern1.json", "name2"},
{"rename_in_mapping_binding_pattern2.json", "pName"},
{"rename_in_mapping_binding_pattern3.json", "pName"},
{"rename_in_groupby_clause.json", "newPrice"},

// Invalid rename positions tests
{"rename_on_keyword1.json", "fn"},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"source": {
"file": "rename_in_groupby_clause.bal"
},
"position": {
"line": 6,
"character": 18
},
"prepareRename": {
"valid": true
},
"result": {
"changes": {
"rename_in_groupby_clause.bal": [
{
"range": {
"start": {
"line": 4,
"character": 27
},
"end": {
"line": 4,
"character": 32
}
},
"newText": "price: newPrice"
},
{
"range": {
"start": {
"line": 5,
"character": 17
},
"end": {
"line": 5,
"character": 22
}
},
"newText": "newPrice"
},
{
"range": {
"start": {
"line": 6,
"character": 15
},
"end": {
"line": 6,
"character": 20
}
},
"newText": "newPrice"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public function main() {

var orders = [{buyer: "b1", price: 12}, {buyer: "b2", price: 13}, {buyer: "b3", price: 14}, {buyer: "b3", price: 15}];

var buyers = from var {price, buyer} in orders
group by price
select price;
}

0 comments on commit 55cf7af

Please sign in to comment.