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 8a5054fab..dae831c9c 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 @@ -595,10 +595,22 @@ Edits rascalRenameSymbol(Tree cursorT, set[loc] workspaceFolders, str newName, P return id; }; + set[RenameLocation] registerChangeAnnotations(set[RenameLocation] locs, str label, str description = "These changes are required for a correct renaming. They can be previewed here, but it is not advised to disable them.", bool needsConfirmation = false) { + set[RenameLocation] modifiedLocs = {}; + for (rl <- locs) { + if (nothing() := rl.annotation) { + modifiedLocs += rl[annotation = just(registerChangeAnnotation(label, description, needsConfirmation))]; + } else { + modifiedLocs += rl; + } + } + return modifiedLocs; + } + = rascalGetDefsUses(ws, cur, rascalMayOverloadSameName, registerChangeAnnotation); - rel[loc file, RenameLocation defines] defsPerFile = { | d <- defs}; - rel[loc file, RenameLocation uses] usesPerFile = { | u <- uses}; + rel[loc file, RenameLocation defines] defsPerFile = { | d <- registerChangeAnnotations(defs, "Definitions")}; + rel[loc file, RenameLocation uses] usesPerFile = { | u <- registerChangeAnnotations(uses, "References")}; set[loc] \files = defsPerFile.file + usesPerFile.file; diff --git a/rascal-lsp/src/main/rascal/lang/rascal/lsp/refactor/WorkspaceInfo.rsc b/rascal-lsp/src/main/rascal/lang/rascal/lsp/refactor/WorkspaceInfo.rsc index 28c09fbbf..4ee511b10 100644 --- a/rascal-lsp/src/main/rascal/lang/rascal/lsp/refactor/WorkspaceInfo.rsc +++ b/rascal-lsp/src/main/rascal/lang/rascal/lsp/refactor/WorkspaceInfo.rsc @@ -31,6 +31,7 @@ import Relation; import analysis::typepal::TModel; +import lang::rascalcore::check::ATypeUtils; import lang::rascalcore::check::Checker; import lang::rascal::\syntax::Rascal; @@ -541,12 +542,15 @@ DefsUsesRenames rascalGetDefsUses(WorkspaceInfo ws, cursor(typeParam(), cursorLo return ; } +private str describeFact(just(AType tp)) = "type \'\'"; +private str describeFact(nothing()) = "unknown type"; + set[RenameLocation] rascalGetHasUses(WorkspaceInfo ws, set[loc] defs, str cursorName, ChangeAnnotationRegister registerChangeAnnotation) { return { - rl(name.src, annotation = just(registerChangeAnnotation("dynamic field name", "", true))) + rl(name.src, annotation = just(registerChangeAnnotation("Use of `has ` on value of ", "Due to the dynamic nature of these names, it cannot be ensured that they need to be renamed. Please review these suggested changes.", true))) | loc l <- rascalReachableModules(ws, defs) , start[Module] m := parseModuleWithSpacesCached(l) - , /(Expression) ` has ` := m + , /(Expression) ` has ` := m , "" == cursorName }; } diff --git a/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/TestUtils.rsc b/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/TestUtils.rsc index 7baf7ebe6..910a95d69 100644 --- a/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/TestUtils.rsc +++ b/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/TestUtils.rsc @@ -64,8 +64,11 @@ private DocumentEdit sortChanges(changed(loc l, list[TextEdit] edits)) = changed })); private default DocumentEdit sortChanges(DocumentEdit e) = e; +private list[DocumentEdit] stripAnnotations(list[DocumentEdit] edits) = + visit (edits) { case replace(range, replacement, _) => replace(range, replacement) }; + private void verifyTypeCorrectRenaming(loc root, Edits edits, PathConfig pcfg) { - executeDocumentEdits(sortEdits(edits<0>)); + executeDocumentEdits(sortEdits(stripAnnotations(edits<0>))); remove(pcfg.resources); RascalCompilerConfig ccfg = rascalCompilerConfig(pcfg)[forceCompilationTopModule = true][verbose = false][logPathConfig = false]; throwAnyErrors(checkAll(root, ccfg)); diff --git a/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ValidNames.rsc b/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ValidNames.rsc index a5ef93ca1..76ab56160 100644 --- a/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ValidNames.rsc +++ b/rascal-lsp/src/main/rascal/lang/rascal/tests/rename/ValidNames.rsc @@ -33,8 +33,9 @@ import analysis::diff::edits::TextEdits; test bool renameToReservedName() { edits = getEdits("int foo = 8;", 0, "foo", "int", "", ""); - newNames = {name | e <- edits<0>, changed(_, replaces) := e - , r <- replaces, replace(_, name) := r}; + newNames = {name | e <- edits<0> + , r <- e.edits + , name := r.replacement}; return newNames == {"\\int"}; }