Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterize rename framework #547

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

toinehartman
Copy link
Contributor

@toinehartman toinehartman commented Dec 17, 2024

Paramterized rename framework + Rascal implementation.

This introduces a general framework for renaming refactorings. It rearranges existing code to separate generic renaming plumbing from Rascal-specific implementations, therefore increasing readability and increasing the amount of type-checkable (i.e. not dependent on rascal-core) code.

@toinehartman toinehartman self-assigned this Dec 17, 2024
@toinehartman toinehartman changed the title [WIP] Rename framework Parameterize rename framework Dec 19, 2024
@toinehartman toinehartman force-pushed the fix/rename-refactoring/maintainability branch from d56c958 to 580c61c Compare December 19, 2024 12:23

private tuple[set[IllegalRenameReason] reasons, list[TextEdit] edits] computeTextEdits(TModel ws, loc moduleLoc, set[RenameLocation] defs, set[RenameLocation] uses, str name, ChangeAnnotationRegister registerChangeAnnotation) =
computeTextEdits(ws, parseModuleWithSpacesCached(moduleLoc), defs, uses, name, registerChangeAnnotation);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to parametric util::refactor::Rename

}

set[TModel] tmodelsForProjectFiles(ProjectFiles projectFiles, set[TModel](set[loc], PathConfig) tmodelsForFiles, PathConfig(loc) getPathConfig) =
({} | it + tmodelsForFiles(projectFiles[pf, true], pcfg) | pf <- projectFiles.projectFolder, pcfg := getPathConfig(pf));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to parametric util::refactor::Rename

import lang::rascalcore::check::Checker;
import lang::rascalcore::check::ATypeBase;
import lang::rascalcore::check::BasicRascalConfig;
import lang::rascalcore::check::RascalConfig;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use some more specific imports here to speed up type-checking


set[loc] getDefs(TModel ws, loc use) = ws.useDef[use];

Maybe[AType] getFact(TModel ws, loc l) = l in ws.facts ? just(ws.facts[l]) : nothing();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to parametric util::refactor::WorkspaceInfo

@@ -168,9 +107,6 @@ set[loc] rascalReachableModules(TModel ws, set[loc] froms) {
return {s.top | s <- reachable.modScope};
}

@memo{maximumSize(1), expireAfter(minutes=5)}
rel[loc, Define] definitionsRel(TModel ws) = toRel(ws.definitions);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to parametric util::refactor::WorkspaceInfo

@@ -213,7 +213,7 @@ public InterruptibleFuture<ITuple> getRename(ITree module, Position cursor, Set<
return runEvaluator("Rascal rename", semanticEvaluator, eval -> {
try {
IFunction rascalGetPathConfig = eval.getFunctionValueFactory().function(getPathConfigType, (t, u) -> addResources(getPathConfig.apply((ISourceLocation) t[0])));
return (ITuple) eval.call("rascalRenameSymbol", cursorTree, VF.set(workspaceFolders.toArray(ISourceLocation[]::new)), VF.string(newName), rascalGetPathConfig);
return (ITuple) eval.call("rascalRenameSymbol", cursorTree, VF.string(newName), VF.set(workspaceFolders.toArray(ISourceLocation[]::new)), rascalGetPathConfig);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swap parameter order to make more sense

@@ -77,9 +73,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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed (like rascalCheckLegalNameByType below) to be able to pass as argument.

, CursorF getCursor
, DefsUsesF getDefsUses
, FindNamesF findNames
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more Rascal-y way would maybe be to define failing variants of these functions here, and extend them in the language specific module?

@synopsis{
A cached wrapper for the Rascal whole-module parse function.
}
start[Module] parseModuleWithSpacesCached(loc l) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to lang::rascal::lsp::refactor::WorkspaceInfo

return bool(&T t1, &T t2) {
return f(t2, t1);
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All unused -> removed.

@toinehartman toinehartman marked this pull request as ready for review December 20, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant