From 63dba6b0b9dff3463473cdfa45eb8aa494996254 Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Wed, 6 Nov 2024 15:20:58 +0100 Subject: [PATCH] Improved descriptions in refactor preview. --- .../rascal/lang/rascal/lsp/refactor/Rename.rsc | 16 ++++++++++++++-- .../lang/rascal/lsp/refactor/WorkspaceInfo.rsc | 8 ++++++-- 2 files changed, 20 insertions(+), 4 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 8a5054fab..3f7aa03a7 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 = "Please do not reject these edits. This could change the behaviour of the program.", 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..1a3d98e03 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 ", "Cannot automatically confirm these edits. Please check if they are correct and confirm manually.", true))) | loc l <- rascalReachableModules(ws, defs) , start[Module] m := parseModuleWithSpacesCached(l) - , /(Expression) ` has ` := m + , /(Expression) ` has ` := m , "" == cursorName }; }