Skip to content

Commit

Permalink
Merge pull request #397 from usethesource/feature/rename-refactoring/…
Browse files Browse the repository at this point in the history
…cross-module

Cross-module renaming
  • Loading branch information
DavyLandman authored Sep 5, 2024
2 parents 82e04f6 + 3050e2b commit d8aae33
Show file tree
Hide file tree
Showing 22 changed files with 2,924 additions and 793 deletions.
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>
<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

0 comments on commit d8aae33

Please sign in to comment.