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 22480e77..0110b6e1 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,7 @@ public InterruptibleFuture getRename(ITree cursorTree, Set; + 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) { @@ -495,7 +496,7 @@ private set[TModel] rascalTModels(set[loc] fs, PathConfig pcfg) { set[TModel] tmodels = {}; for (str modName <- ms.moduleLocs) { = 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; @@ -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); 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 ead40355..ee846f06 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 9db612cf..6676e23f 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,8 +27,10 @@ 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; Edits testProjectOnDisk(loc projectDir, str file, str oldName, int occurrence = 0, str newName = "_new") { PathConfig pcfg;