Skip to content

Commit

Permalink
Improved descriptions in refactor preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
toinehartman committed Nov 6, 2024
1 parent 68df61c commit 63dba6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 14 additions & 2 deletions rascal-lsp/src/main/rascal/lang/rascal/lsp/refactor/Rename.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
<defs, uses, getRenames> = rascalGetDefsUses(ws, cur, rascalMayOverloadSameName, registerChangeAnnotation);
rel[loc file, RenameLocation defines] defsPerFile = {<d.l.top, d> | d <- defs};
rel[loc file, RenameLocation uses] usesPerFile = {<u.l.top, u> | u <- uses};
rel[loc file, RenameLocation defines] defsPerFile = {<d.l.top, d> | d <- registerChangeAnnotations(defs, "Definitions")};
rel[loc file, RenameLocation uses] usesPerFile = {<u.l.top, u> | u <- registerChangeAnnotations(uses, "References")};
set[loc] \files = defsPerFile.file + usesPerFile.file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -541,12 +542,15 @@ DefsUsesRenames rascalGetDefsUses(WorkspaceInfo ws, cursor(typeParam(), cursorLo
return <fromLocs(defs), fromLocs(useDefs - defs), NO_RENAMES>;
}
private str describeFact(just(AType tp)) = "type \'<prettyAType(tp)>\'";
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 <cursorName>` on value of <describeFact(getFact(ws, e.src))>", "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) `<Expression _> has <Name name>` := m
, /(Expression) `<Expression e> has <Name name>` := m
, "<name>" == cursorName
};
}
Expand Down

0 comments on commit 63dba6b

Please sign in to comment.