Skip to content

Commit 07b318d

Browse files
committed
Re-use path config getter.
1 parent 34681f0 commit 07b318d

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalLanguageServices.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.util.concurrent.ExecutionException;
4242
import java.util.concurrent.Executor;
4343
import java.util.concurrent.ExecutorService;
44-
import java.util.function.Function;
4544
import java.util.stream.Collectors;
4645

4746
import org.apache.logging.log4j.LogManager;
@@ -231,11 +230,10 @@ public InterruptibleFuture<IList> getDocumentSymbols(IConstructor module) {
231230
}
232231

233232

234-
public InterruptibleFuture<ITuple> getRename(ISourceLocation cursorLoc, IList focus, Set<ISourceLocation> workspaceFolders, Function<ISourceLocation, PathConfig> getPathConfig, String newName) {
233+
public InterruptibleFuture<ITuple> getRename(ISourceLocation cursorLoc, IList focus, Set<ISourceLocation> workspaceFolders, String newName) {
235234
return runEvaluator("Rascal rename", semanticEvaluator, eval -> {
236235
try {
237-
IFunction rascalGetPathConfig = eval.getFunctionValueFactory().function(getPathConfigType, (t, u) -> getPathConfig.apply((ISourceLocation) t[0]).asConstructor());
238-
return (ITuple) eval.call("rascalRenameSymbol", cursorLoc, focus, VF.string(newName), workspaceFolders.stream().collect(VF.setWriter()), rascalGetPathConfig);
236+
return (ITuple) eval.call("rascalRenameSymbol", cursorLoc, focus, VF.string(newName), workspaceFolders.stream().collect(VF.setWriter()), makePathConfigGetter(eval));
239237
} catch (Throw e) {
240238
if (e.getException() instanceof IConstructor) {
241239
var exception = (IConstructor)e.getException();
@@ -265,7 +263,7 @@ private ISourceLocation sourceLocationFromUri(String uri) {
265263
}
266264
}
267265

268-
public CompletableFuture<ITuple> getModuleRenames(List<FileRename> fileRenames, Set<ISourceLocation> workspaceFolders, Function<ISourceLocation, PathConfig> getPathConfig) {
266+
public CompletableFuture<ITuple> getModuleRenames(List<FileRename> fileRenames, Set<ISourceLocation> workspaceFolders) {
269267
var emptyResult = VF.tuple(VF.list(), VF.map());
270268
if (fileRenames.isEmpty()) {
271269
return CompletableFuture.completedFuture(emptyResult);
@@ -277,9 +275,8 @@ public CompletableFuture<ITuple> getModuleRenames(List<FileRename> fileRenames,
277275
, exec)
278276
.thenCompose(renames ->
279277
runEvaluator("Rascal module rename", semanticEvaluator, eval -> {
280-
IFunction rascalGetPathConfig = eval.getFunctionValueFactory().function(getPathConfigType, (t, u) -> getPathConfig.apply((ISourceLocation) t[0]).asConstructor());
281278
try {
282-
return (ITuple) eval.call("rascalRenameModule", renames, workspaceFolders.stream().collect(VF.setWriter()), rascalGetPathConfig);
279+
return (ITuple) eval.call("rascalRenameModule", renames, workspaceFolders.stream().collect(VF.setWriter()), makePathConfigGetter(eval));
283280
} catch (Throw e) {
284281
throw new RuntimeException(e.getMessage());
285282
}

rascal-lsp/src/main/java/org/rascalmpl/vscode/lsp/rascal/RascalTextDocumentService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {
419419
Position rascalCursorPos = Locations.toRascalPosition(file.getLocation(), params.getPosition(), columns);
420420
var focus = TreeSearch.computeFocusList(tr, rascalCursorPos.getLine(), rascalCursorPos.getCharacter());
421421
var cursorTree = findQualifiedNameUnderCursor(focus);
422-
return availableRascalServices().getRename(TreeAdapter.getLocation(cursorTree), focus, workspaceFolders, availableFacts()::getPathConfig, params.getNewName()).get();
422+
return availableRascalServices().getRename(TreeAdapter.getLocation(cursorTree), focus, workspaceFolders, params.getNewName()).get();
423423
})
424424
.thenApply(t -> {
425425
showMessages((ISet) t.get(1));
@@ -495,7 +495,7 @@ public void didRenameFiles(RenameFilesParams params, List<WorkspaceFolder> works
495495
.map(f -> Locations.toLoc(f.getUri()))
496496
.collect(Collectors.toSet());
497497

498-
availableRascalServices().getModuleRenames(params.getFiles(), folders, availableFacts()::getPathConfig)
498+
availableRascalServices().getModuleRenames(params.getFiles(), folders)
499499
.thenAccept(res -> {
500500
var edits = (IList) res.get(0);
501501
var messages = (ISet) res.get(1);

0 commit comments

Comments
 (0)