Skip to content

Commit

Permalink
Escape qualified names.
Browse files Browse the repository at this point in the history
  • Loading branch information
toinehartman committed Dec 4, 2024
1 parent d5ea288 commit ab74b9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ 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)]);
// 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
11 changes: 11 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,17 @@ test bool renameToReservedName() {
return newNames == {"\\int"};
}

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", escapedNewName = true);

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

0 comments on commit ab74b9e

Please sign in to comment.