Skip to content

Commit

Permalink
found another use for toRascalPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Oct 30, 2024
1 parent af3284d commit 8ffab57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
import org.rascalmpl.vscode.lsp.util.RascalServices;
import org.rascalmpl.vscode.lsp.util.concurrent.InterruptibleFuture;
import org.rascalmpl.vscode.lsp.util.locations.ColumnMaps;
import org.rascalmpl.vscode.lsp.util.locations.Locations;

import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IList;
import io.usethesource.vallang.ISet;
Expand Down Expand Up @@ -203,10 +205,9 @@ public InterruptibleFuture<IList> getDocumentSymbols(IConstructor module) {


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);
Position pos = Locations.toRascalPosition(moduleLocation, cursor, columns);
var cursorTree = TreeAdapter.locateLexical(module, pos.getLine(), pos.getCharacter());

return runEvaluator("Rascal rename", semanticEvaluator, eval -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,17 @@ public static Range toRascalRange(TextDocumentIdentifier doc, Range range, Colum
*/
public static Position toRascalPosition(TextDocumentIdentifier doc, Position pos, ColumnMaps columns) {
var uri = toLoc(doc.getUri());
return toRascalPosition(uri, pos, columns);
}

/**
* This fixes line offset off-by-one and column offsets character widths.
* Mapping them from the LSP standard to the Rascal standard.
*/
public static Position toRascalPosition(ISourceLocation doc, Position pos, ColumnMaps columns) {
return new Position(
pos.getLine() + 1,
columns.get(uri).translateInverseColumn(pos.getLine(), pos.getCharacter(), false)
columns.get(doc).translateInverseColumn(pos.getLine(), pos.getCharacter(), false)
);
}

Expand Down

0 comments on commit 8ffab57

Please sign in to comment.