Skip to content

Commit

Permalink
Escape the new name iff it is a reserved keyword.
Browse files Browse the repository at this point in the history
  • Loading branch information
toinehartman committed Jun 11, 2024
1 parent 76e2c17 commit 843c60c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rascal-lsp/src/main/rascal/lang/rascal/lsp/Rename.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private set[loc] getDefinitions(TModel tm, loc use) {

bool isLegalName(str name) {
try {
parse(#Name, name);
parse(#Name, escapeName(name));
return true;
} catch ParseError: {
return false;
Expand Down Expand Up @@ -125,6 +125,8 @@ bool isLegalRename(TModel tm, start[Module] m, set[loc] defLocs, set[loc] useLoc
return true;
}
str escapeName(str name) = name in getRascalReservedIdentifiers() ? "\\<name>" : name;
list[DocumentEdit] renameRascalSymbol(start[Module] m, Tree cursor, set[loc] workspaceFolders, TModel tm, str newName) {
loc cursorLoc = cursor.src;
set[loc] defs = getDefinitions(tm, cursorLoc);
Expand Down Expand Up @@ -155,7 +157,7 @@ list[DocumentEdit] renameRascalSymbol(start[Module] m, Tree cursor, set[loc] wor
println("Use/Defs per file:");
iprintln(toMap(useDefsPerFile));
list[DocumentEdit] changes = [changed(file, [replace(findNameLocation(m, useDef), newName) | useDef <- useDefsPerFile[file]]) | loc file <- useDefsPerFile.file];;
list[DocumentEdit] changes = [changed(file, [replace(findNameLocation(m, useDef), escapeName(newName)) | useDef <- useDefsPerFile[file]]) | loc file <- useDefsPerFile.file];;
// TODO If the cursor was a module name, we need to rename files as well
list[DocumentEdit] renames = [];
Expand Down

0 comments on commit 843c60c

Please sign in to comment.