Skip to content

Commit

Permalink
Escape qualified names, unescape file names.
Browse files Browse the repository at this point in the history
  • Loading branch information
toinehartman committed Dec 4, 2024
1 parent d5ea288 commit 2eb84b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ private set[IllegalRenameReason] rascalCollectIllegalRenames(WorkspaceInfo ws, r
}
@memo{maximumSize(1000), expireAfter(minutes=5)}
private str rascalEscapeName(str name) = name in getRascalReservedIdentifiers() ? "\\<name>" : name;
private str rascalEscapeName(str name) = intercalate("::", [n in getRascalReservedIdentifiers() ? "\\<n>" : n | n <- split("::", name)]);
private str rascalUnescapeName(str name) = replaceAll(name, "\\", "");
// Find the smallest trees of defined non-terminal type with a source location in `useDefs`
private rel[loc name, loc useDef] rascalFindNamesInUseDefs(start[Module] m, set[loc] useDefs, CursorKind cursorKind) {
Expand Down Expand Up @@ -650,7 +652,7 @@ Edits rascalRenameSymbol(Tree cursorT, set[loc] workspaceFolders, str newName, P
(file: edits | file <- \files, edits := computeTextEdits(ws, file, defsPerFile[file], usesPerFile[file], cur, newName, registerChangeAnnotation));
list[DocumentEdit] changes = [changed(file, moduleResults[file]) | file <- moduleResults];
list[DocumentEdit] renames = [renamed(from, to) | <from, to> <- getRenames(newName)];
list[DocumentEdit] renames = [renamed(from, to) | <from, to> <- getRenames(rascalUnescapeName(newName))];
return <changes + renames, changeAnnotations>;
}, totalWork = 7);
Expand Down
22 changes: 22 additions & 0 deletions rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ValidNames.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ test bool renameToReservedName() {
return newNames == {"\\int"};
}

test bool renameToUnescapedQualifiedName() = testRenameOccurrences({
byText("FooSyntax", "syntax S = \"s\";", {0}, newName = "syntax::Foo"),
byText("Main", "
'import FooSyntax;
'import ParseTree;
'void main() {
' s = parse(#FooSyntax::S, \"s\");
'}
", {0, 1}, skipCursors = {1})
}, oldName = "FooSyntax", newName = "syntax::Foo");

test bool renameToEscapedQualifiedName() = testRenameOccurrences({
byText("FooSyntax", "syntax S = \"s\";", {0}, newName = "syntax::Foo"),
byText("Main", "
'import FooSyntax;
'import ParseTree;
'void main() {
' s = parse(#FooSyntax::S, \"s\");
'}
", {0, 1}, skipCursors = {1})
}, oldName = "FooSyntax", newName = "\\syntax::Foo");

@expected{illegalRename}
test bool renameToUsedReservedName() = testRename("
'int \\int = 0;
Expand Down

0 comments on commit 2eb84b2

Please sign in to comment.