From aa0051c7666d04a98aaec55556e92e0898784d8c Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Fri, 10 Jan 2025 13:47:03 +0100 Subject: [PATCH 1/5] Change type of rename exceptions. --- .../rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java | 3 ++- .../src/main/rascal/lang/rascal/lsp/refactor/Exception.rsc | 4 ++-- .../src/main/rascal/lang/rascal/lsp/refactor/Rename.rsc | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java index 22480e770..c3b130352 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java @@ -215,7 +215,8 @@ public InterruptibleFuture getRename(ITree cursorTree, Set = getTModelForModule(modName, ms); - if (!found) throw unexpectedFailure("Cannot read TModel for module \'\'\n"); + if (!found) throw unexpectedRenameFailure("Cannot read TModel for module \'\'\n"); tmodels += convertTModel2PhysicalLocs(tm); } return tmodels; From 3475af12a76886ad67e3e5cce5290f2fbe3bdf70 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Fri, 10 Jan 2025 13:47:28 +0100 Subject: [PATCH 2/5] Fix `tryParseAs` types. --- .../main/rascal/lang/rascal/lsp/refactor/Rename.rsc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rascal-lsp/src/main/rascal/lang/rascal/lsp/refactor/Rename.rsc b/rascal-lsp/src/main/rascal/lang/rascal/lsp/refactor/Rename.rsc index 9948b7043..acc90c92d 100644 --- a/rascal-lsp/src/main/rascal/lang/rascal/lsp/refactor/Rename.rsc +++ b/rascal-lsp/src/main/rascal/lang/rascal/lsp/refactor/Rename.rsc @@ -78,9 +78,9 @@ void throwAnyErrors(program(_, msgs)) { throwAnyErrors(msgs); } -private set[IllegalRenameReason] rascalCheckLegalName(str name, set[IdRole] roles) { +private set[IllegalRenameReason] rascalCheckLegalNameByRoles(str name, set[IdRole] roles) { escName = rascalEscapeName(name); - tuple[type[&T <: Tree] as, str desc] asType = <#Name, "identifier">; + tuple[type[Tree] as, str desc] asType = <#Name, "identifier">; if ({moduleId(), *_} := roles) asType = <#QualifiedName, "module name">; if ({constructorId(), *_} := roles) asType = <#NonterminalLabel, "constructor name">; if ({fieldId(), *_} := roles) asType = <#NonterminalLabel, "constructor field name">; @@ -90,10 +90,11 @@ private set[IllegalRenameReason] rascalCheckLegalName(str name, set[IdRole] role return {}; } -private void rascalCheckLegalName(str name, Symbol sym) { +private void rascalCheckLegalNameByType(str name, Symbol sym) { escName = rascalEscapeName(name); g = grammar(#start[Module]); - if (tryParseAs(type(sym, g.rules), escName) is nothing) { + if (type[Tree] t := type(sym, g.rules) + , tryParseAs(t, escName) is nothing) { throw illegalRename("\'\' is not a valid name at this position", {invalidName(escName, "")}); } } @@ -177,7 +178,7 @@ private set[IllegalRenameReason] rascalCollectIllegalRenames(TModel ws, rel[loc set[loc] editFiles = defsPerFile.file + usesPerFile.file; set[IllegalRenameReason] reasons = {}; - reasons += rascalCheckLegalName(newName, definitionsRel(ws)[defsPerFile.rename.l].idRole); + reasons += rascalCheckLegalNameByRoles(newName, definitionsRel(ws)[defsPerFile.rename.l].idRole); reasons += rascalCheckDefinitionsOutsideWorkspace(ws, defsPerFile.rename.l); reasons += rascalCheckCausesDoubleDeclarations(ws, defsPerFile.rename.l, newNameDefs, newName); for (file <- editFiles) { @@ -599,7 +600,7 @@ Edits rascalRenameSymbol(Tree cursorT, set[loc] workspaceFolders, str newName, P loc cursorLoc = cursorT.src; str cursorName = ""; - rascalCheckLegalName(newName, typeOf(cursorT)); + rascalCheckLegalNameByType(newName, typeOf(cursorT)); step("preloading minimal workspace information", 1); set[TModel] localTmodelsForFiles(ProjectFiles projectFiles) = tmodelsForProjectFiles(projectFiles, rascalTModels, getPathConfig); From 57ad93e299a30b920a3bb490401687374329cf9d Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Fri, 10 Jan 2025 13:47:50 +0100 Subject: [PATCH 3/5] Add missing imports. --- rascal-lsp/src/main/rascal/lang/rascal/tests/rename/Grammars.rsc | 1 + .../src/main/rascal/lang/rascal/tests/rename/ProjectOnDisk.rsc | 1 + 2 files changed, 2 insertions(+) diff --git a/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/Grammars.rsc b/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/Grammars.rsc index ead403554..ee846f06c 100644 --- a/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/Grammars.rsc +++ b/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/Grammars.rsc @@ -27,6 +27,7 @@ POSSIBILITY OF SUCH DAMAGE. module lang::rascal::tests::rename::Grammars import lang::rascal::tests::rename::TestUtils; +import lang::rascal::lsp::refactor::Exception; test bool productionType() = testRenameOccurrences({0, 1, 2, 3}, " 'Foo func(Foo f) = f.child; diff --git a/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ProjectOnDisk.rsc b/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ProjectOnDisk.rsc index 9db612cf2..25b73247f 100644 --- a/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ProjectOnDisk.rsc +++ b/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ProjectOnDisk.rsc @@ -29,6 +29,7 @@ module lang::rascal::tests::rename::ProjectOnDisk import lang::rascal::lsp::refactor::Rename; import lang::rascal::tests::rename::TestUtils; import util::Reflective; +import lang::rascalcore::check::Checker; Edits testProjectOnDisk(loc projectDir, str file, str oldName, int occurrence = 0, str newName = "_new") { PathConfig pcfg; From 9c910504259539b989c4505d1ef83b813e769d97 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Fri, 10 Jan 2025 14:03:22 +0100 Subject: [PATCH 4/5] Simplify rename error check. --- .../rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java index c3b130352..0110b6e12 100644 --- a/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java +++ b/rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java @@ -215,8 +215,7 @@ public InterruptibleFuture getRename(ITree cursorTree, Set Date: Fri, 10 Jan 2025 14:59:17 +0100 Subject: [PATCH 5/5] Add another missing import. --- .../src/main/rascal/lang/rascal/tests/rename/ProjectOnDisk.rsc | 1 + 1 file changed, 1 insertion(+) diff --git a/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ProjectOnDisk.rsc b/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ProjectOnDisk.rsc index 25b73247f..6676e23fb 100644 --- a/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ProjectOnDisk.rsc +++ b/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ProjectOnDisk.rsc @@ -27,6 +27,7 @@ POSSIBILITY OF SUCH DAMAGE. module lang::rascal::tests::rename::ProjectOnDisk import lang::rascal::lsp::refactor::Rename; +import lang::rascal::lsp::refactor::Util; import lang::rascal::tests::rename::TestUtils; import util::Reflective; import lang::rascalcore::check::Checker;