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

Cross-module renaming #397

Merged
merged 117 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
6039db7
Refactor to workspace-wide renaming.
toinehartman Jun 21, 2024
2706efb
Support global functions.
toinehartman Jun 21, 2024
d22b3f3
Do not pass module tree to renaming.
toinehartman Jun 21, 2024
5d8f1db
Multi-module test setup.
toinehartman Jun 27, 2024
401ccfc
Add large, repetitive test.
toinehartman Jul 2, 2024
d64376c
Extract test occurrences faster.
toinehartman Jul 2, 2024
3df2d12
Support aliases, data types.
toinehartman Jul 2, 2024
6955390
Support multi-module tests from disk as well.
toinehartman Jul 2, 2024
6f67fce
Test qualified names in multi-module tests.
toinehartman Jul 3, 2024
fe43110
Split tests over multiple files.
toinehartman Jul 3, 2024
098b303
Simplify workspace info collection.
toinehartman Jul 3, 2024
58c81e9
Always use fresh environment for compiler/typechecker.
toinehartman Jul 3, 2024
e740621
Use JUnit 4 only.
toinehartman Jul 3, 2024
ef290e1
Implement function overload renaming.
toinehartman Jul 4, 2024
46454f3
Fix type errors.
toinehartman Jul 5, 2024
abd5a65
Fix test path config.
toinehartman Jul 5, 2024
713d807
Adapt to new typechecker version.
toinehartman Jul 8, 2024
4aa54fb
Align single/multi module tests, simplify, remove duplicate type check.
toinehartman Jul 8, 2024
6b1b44e
Distinguish role of id at cursor.
toinehartman Jul 8, 2024
3c28e25
Use generic locations instead of defines to prepare for fact-based lo…
toinehartman Jul 9, 2024
0706072
Ignore new source and test locations.
toinehartman Jul 11, 2024
d02f5ca
Verify type-correctness before attempting rename.
toinehartman Jul 11, 2024
9bd0a44
Implement fact-based support for type parameters.
toinehartman Jul 11, 2024
be8ebde
Merge remote-tracking branch 'origin/main' into feature/rename-refact…
toinehartman Jul 16, 2024
b52d2f9
Add missing test cases for already implemented rename functionality.
toinehartman Jul 16, 2024
3781964
Add license headers to new files.
toinehartman Jul 16, 2024
c480de3
Use field assigment instead of interpolation.
toinehartman Jul 16, 2024
7b472a2
Fix module location in evaluator.
toinehartman Jul 16, 2024
07c5d52
Include renames in test expectations.
toinehartman Jul 16, 2024
3cf28af
Per-project path config, lazily loaded.
toinehartman Jul 17, 2024
abd16b9
Pass message in unsupported rename exception.
toinehartman Jul 18, 2024
3efcaf9
Implement some field renames; don't support others for now.
toinehartman Jul 18, 2024
e2a6335
Small fixes to trim util.
toinehartman Jul 18, 2024
5b69783
Fix type errors.
toinehartman Jul 18, 2024
a61d558
Add tests for annotations (already implemented).
toinehartman Jul 18, 2024
912c24b
Only ignore specific files for compilation.
toinehartman Jul 18, 2024
9d70671
Report progress and errors to the user.
toinehartman Jul 19, 2024
5d9aa69
Test data field rename across extends.
toinehartman Jul 19, 2024
f02bd51
Merge remote-tracking branch 'origin/main' into feature/rename-refact…
toinehartman Jul 19, 2024
a99cc19
Crawl modules in source folders only.
toinehartman Jul 22, 2024
331d2b4
Load TPLs for selected modules only.
toinehartman Jul 24, 2024
229d7a6
Rename evaluator.
toinehartman Jul 24, 2024
2c26259
Implement all field types.
toinehartman Jul 25, 2024
26ce478
Implement module renaming.
toinehartman Jul 26, 2024
4bdeb78
Fix warnings.
toinehartman Jul 26, 2024
dd1dcee
Don't load new parser for tests.
toinehartman Jul 26, 2024
3999de8
Verify type-correctness of renaming in tests.
toinehartman Jul 30, 2024
ef1d7d2
Fix duplicate field declarations.
toinehartman Jul 30, 2024
ee30bdd
Implement check for duplicate field names.
toinehartman Jul 30, 2024
cbb7229
Fix isPrefixOf when trailing slash is missing.
toinehartman Jul 30, 2024
a3363fd
Use alias instead of complex tuple.
toinehartman Jul 30, 2024
90ca2f4
Do not load workspace for local renaming.
toinehartman Jul 30, 2024
6d1bd05
Add benchmarking code.
toinehartman Jul 30, 2024
6131d01
Merge remote-tracking branch 'origin/main' into feature/rename-refact…
toinehartman Jul 31, 2024
3084b83
Improve illegal rename error with message.
toinehartman Jul 31, 2024
a96b007
Document dependency override in POM.
toinehartman Jul 31, 2024
1afa2fe
Improve performance of comprehensions and reductions.
toinehartman Jul 31, 2024
6d4a1ac
Clean up and document cursor determination.
toinehartman Jul 31, 2024
7759823
Improve testing with actual workspaces.
toinehartman Jul 31, 2024
9ecc1a6
Small stylistic fixes from review (@DavyLandman)
toinehartman Aug 1, 2024
995a651
Document WorkspaceInfo.
toinehartman Aug 1, 2024
d30a717
Fixed comments from review by @rodinaarssen.
toinehartman Aug 5, 2024
051f4c7
Fix type error.
toinehartman Aug 5, 2024
cfccd8e
Fix `resolveLocations`
toinehartman Aug 5, 2024
bb69e93
Implement type param double declaration detection.
toinehartman Aug 5, 2024
3b04ea4
Support renaming of keyword parameters.
toinehartman Aug 6, 2024
d8ecd2b
Remove unused imports.
toinehartman Aug 7, 2024
65d91e7
Improve finding names in definitions.
toinehartman Aug 2, 2024
a87f100
Improve user-facing errors.
toinehartman Aug 7, 2024
e6849ae
Separate Rasal-specific from generic by name.
toinehartman Aug 7, 2024
f9ec5e6
Cache inverted WorkspaceInfo fields.
toinehartman Aug 8, 2024
864e98f
Resolve definitions properly.
toinehartman Aug 13, 2024
b22fe33
Improve/refactor collection field renaming.
toinehartman Aug 16, 2024
680f863
Temporarily remove some tests until ADTs have been implemented fully.
toinehartman Aug 19, 2024
7fe3192
Rename Rascal speicifc functions.
toinehartman Aug 19, 2024
9caab33
Fix memoization retention policies.
toinehartman Aug 19, 2024
3a3ecb8
Document renaming and utility functions.
toinehartman Aug 19, 2024
566a922
Rename test comparison helper.
toinehartman Aug 19, 2024
0f7c5f0
Merge remote-tracking branch 'origin/main' into feature/rename-refact…
toinehartman Aug 20, 2024
2e46c7e
Remove now-unused file.
toinehartman Aug 20, 2024
7c03ee2
Small fixes from review.
toinehartman Aug 20, 2024
3046dd5
Run single-module tests with all expected occurrences as cursor.
toinehartman Aug 19, 2024
c900648
Support type parameter in nested function as cursor.
toinehartman Aug 19, 2024
d2e6287
Run multi-module tests with all expected occurrences as cursor.
toinehartman Aug 20, 2024
83e3b7b
Mark cursor as module name less aggressively.
toinehartman Aug 20, 2024
19ec113
Merge branch 'main' into feature/rename-refactoring/cross-module
toinehartman Aug 20, 2024
db9f7dc
Merge branch 'feature/rename-refactoring/cross-module' into feature/r…
toinehartman Aug 20, 2024
07ec5ab
Merge pull request #426 from usethesource/feature/rename-refactoring/…
toinehartman Aug 20, 2024
ed62e20
Extend/improve data type tests.
toinehartman Aug 16, 2024
f852237
Basic implementation of constructor field renaming.
toinehartman Aug 19, 2024
2fc4ec7
Implement basic constructor keyword fields.
toinehartman Aug 21, 2024
62836bc
Merge branch 'main' into feature/rename-refactoring/cross-module
toinehartman Aug 26, 2024
9ffbaff
Implement common keyword fields.
toinehartman Aug 22, 2024
fa965c1
Find nested (field) definitions as well.
toinehartman Aug 26, 2024
d2d8a7a
Fix cursor at ADT field def.
toinehartman Aug 26, 2024
98809e5
Simplify cursor calculation/preloading.
toinehartman Aug 26, 2024
f709bf0
Resolve reachable definitions in two directions.
toinehartman Aug 26, 2024
949c609
Re-use more generic field machinery.
toinehartman Aug 27, 2024
df99b82
Only rename definitions with the same role.
toinehartman Aug 28, 2024
5be976b
Fix iteration in presence of multiple definitions.
toinehartman Aug 29, 2024
0f28d3f
Support skipping cursors in multi-module tests.
toinehartman Aug 29, 2024
2a6108d
Resolve fields in data definitions.
toinehartman Aug 29, 2024
2d1bbf9
Fix existing field detection.
toinehartman Aug 29, 2024
18a18bf
Consider overloaded/reachable ADT defs only.
toinehartman Aug 30, 2024
216acc1
Find fields to rename in reachable scopes only.
toinehartman Aug 30, 2024
86a359a
Optimize repeated code and clean up.
toinehartman Aug 30, 2024
72a3202
Fix type errors.
toinehartman Sep 2, 2024
7dd59d0
Accept renaming from collection field projection.
toinehartman Sep 2, 2024
0a2ac13
Update documentation.
toinehartman Sep 2, 2024
d2ce994
Merge branch 'feature/rename-refactoring/cross-module' into feature/r…
toinehartman Sep 2, 2024
6b6c336
Clean up some more debugging artefacts.
toinehartman Sep 2, 2024
2eee868
Merge branch 'main' into feature/rename-refactoring/cross-module
toinehartman Sep 5, 2024
16d39b6
Merge branch 'feature/rename-refactoring/cross-module' into feature/r…
toinehartman Sep 5, 2024
fac01e3
Small fixes based on review by @PieterOlivier
toinehartman Sep 5, 2024
9c8c98f
Move path config function to workspace info field
toinehartman Sep 5, 2024
54d1a41
Split up logic to determine cursor kind.
toinehartman Sep 5, 2024
3050e2b
Merge pull request #444 from usethesource/feature/rename-refactoring/…
toinehartman Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions rascal-lsp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<version>2.21.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.3</junit.version>
<junit.version>4.13.1</junit.version>
<maven-surefire-plugin.version>3.3.0</maven-surefire-plugin.version>
<log4j2.version>2.23.1</log4j2.version>
<lsp4j.version>0.23.1</lsp4j.version>
Expand Down Expand Up @@ -68,36 +68,17 @@
<dependency>
<groupId>org.rascalmpl</groupId>
<artifactId>rascal-core</artifactId>
<version>0.12.3</version>
<version>0.12.4</version>
</dependency>
<dependency>
<groupId>org.rascalmpl</groupId>
<artifactId>typepal</artifactId>
<version>0.13.4</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
<version>0.14.0</version>
</dependency>
<!-- Rascal tests require JUnit 4 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<!-- Required to run JUnit 4 and 5 tests in the same test run -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -169,6 +150,14 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<dependencies>
<!-- Make sure to use the JUnit 4 test runner -->
<dependency>
toinehartman marked this conversation as resolved.
Show resolved Hide resolved
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.rascalmpl</groupId>
Expand All @@ -181,8 +170,9 @@
<src>${project.basedir}/src/main/rascal</src>
</srcs>
<srcIgnores>
<ignore>${project.basedir}/src/main/rascal/lang/rascal/lsp/Rename.rsc</ignore>
<ignore>${project.basedir}/src/main/rascal/lang/rascal/tests/Rename.rsc</ignore>
<ignore>${project.basedir}/src/main/rascal/lang/rascal/lsp/refactor/Rename.rsc</ignore>
<ignore>${project.basedir}/src/main/rascal/lang/rascal/lsp/refactor/WorkspaceInfo.rsc</ignore>
<ignore>${project.basedir}/src/main/rascal/lang/rascal/tests/rename</ignore>
</srcIgnores>
<sourceLookup>|lib://rascal-lsp|</sourceLookup>
<enableStandardLibrary>false</enableStandardLibrary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -50,6 +51,7 @@
import org.rascalmpl.interpreter.Evaluator;
import org.rascalmpl.library.util.PathConfig;
import org.rascalmpl.values.IRascalValueFactory;
import org.rascalmpl.values.functions.IFunction;
import org.rascalmpl.values.parsetrees.ITree;
import org.rascalmpl.values.parsetrees.TreeAdapter;
import org.rascalmpl.vscode.lsp.BaseWorkspaceService;
Expand All @@ -65,6 +67,9 @@
import io.usethesource.vallang.IString;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.type.Type;
import io.usethesource.vallang.type.TypeFactory;
import io.usethesource.vallang.type.TypeStore;

public class RascalLanguageServices {
private static final IValueFactory VF = IRascalValueFactory.getInstance();
Expand All @@ -75,6 +80,10 @@ public class RascalLanguageServices {
private final CompletableFuture<Evaluator> semanticEvaluator;
private final CompletableFuture<Evaluator> compilerEvaluator;

private final TypeFactory tf = TypeFactory.getInstance();
private final TypeStore store = new TypeStore();
private final Type getPathConfigType = tf.functionType(tf.abstractDataType(store, "PathConfig"), tf.tupleType(tf.sourceLocationType()), tf.tupleEmpty());

private final ExecutorService exec;

private final IBaseLanguageClient client;
Expand All @@ -86,7 +95,7 @@ public RascalLanguageServices(RascalTextDocumentService docService, BaseWorkspac
var monitor = new RascalLSPMonitor(client, logger);

outlineEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal outline", monitor, null, false, "lang::rascal::lsp::Outline");
semanticEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal summary", monitor, null, true, "lang::rascalcore::check::Summary", "lang::rascal::lsp::Rename");
semanticEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal semantics", monitor, null, true, "lang::rascalcore::check::Summary", "lang::rascal::lsp::refactor::Rename");
compilerEvaluator = makeFutureEvaluator(exec, docService, workspaceService, client, "Rascal compiler", monitor, null, true, "lang::rascalcore::check::Checker");
}

Expand Down Expand Up @@ -181,15 +190,16 @@ public InterruptibleFuture<IList> getOutline(IConstructor module) {
}


public InterruptibleFuture<IList> getRename(ITree module, Position cursor, Set<ISourceLocation> workspaceFolders, PathConfig pcfg, String newName, ColumnMaps columns) {
public InterruptibleFuture<IList> getRename(ITree module, Position cursor, Set<ISourceLocation> workspaceFolders, Function<ISourceLocation, PathConfig> getPathConfig, String newName, ColumnMaps columns) {
var line = cursor.getLine() + 1;
var moduleLocation = TreeAdapter.getLocation(module);
var translatedOffset = columns.get(moduleLocation).translateInverseColumn(line, cursor.getCharacter(), false);
var cursorTree = TreeAdapter.locateLexical(module, line, translatedOffset);

return runEvaluator("Rascal rename", semanticEvaluator, eval -> {
try {
return (IList) eval.call("renameRascalSymbol", module, cursorTree, VF.set(workspaceFolders.toArray(ISourceLocation[]::new)), addResources(pcfg), VF.string(newName));
IFunction rascalGetPathConfig = eval.getFunctionValueFactory().function(getPathConfigType, (t, u) -> addResources(getPathConfig.apply((ISourceLocation) t[0])));
return (IList) eval.call("rascalRenameSymbol", cursorTree, VF.set(workspaceFolders.toArray(ISourceLocation[]::new)), VF.string(newName), rascalGetPathConfig);
} catch (Throw e) {
if (e.getException() instanceof IConstructor) {
var exception = (IConstructor)e.getException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {
return file.getCurrentTreeAsync()
.thenApply(Versioned::get)
.handle((t, r) -> (t == null ? (file.getMostRecentTree().get()) : t))
.thenCompose(tr -> rascalServices.getRename(tr, params.getPosition(), workspaceFolders, facts.getPathConfig(file.getLocation()), params.getNewName(), columns).get())
.thenCompose(tr -> rascalServices.getRename(tr, params.getPosition(), workspaceFolders, facts::getPathConfig, params.getNewName(), columns).get())
.thenApply(c -> new WorkspaceEdit(DocumentChanges.translateDocumentChanges(this, c)))
;
}
Expand Down
249 changes: 0 additions & 249 deletions rascal-lsp/src/main/rascal/lang/rascal/lsp/Rename.rsc

This file was deleted.

Loading
Loading