Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,13 @@ private CompletableFuture<ISourceLocation> computeRenameRange(final ILanguageCon
@Override
public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {
logger.trace("rename for: {}, new name: {}", params.getTextDocument().getUri(), params.getNewName());
ISourceLocation loc = Locations.toLoc(params.getTextDocument());
ISourceLocation loc = Locations.setPosition(Locations.toLoc(params.getTextDocument()), params.getPosition(), columns);
ILanguageContributions contribs = contributions(loc);
Position rascalPos = Locations.toRascalPosition(loc, params.getPosition(), columns);
return getFile(loc)
.getCurrentTreeAsync(true)
.thenApply(Versioned::get)
.thenCompose(tree -> computeRename(contribs,
rascalPos.getLine(), rascalPos.getCharacter(), params.getNewName(), tree));
loc.getBeginLine(), loc.getBeginColumn(), params.getNewName(), tree));
}

private CompletableFuture<WorkspaceEdit> computeRename(final ILanguageContributions contribs, final int startLine,
Expand Down Expand Up @@ -691,6 +690,7 @@ private TextDocumentState open(TextDocumentItem doc, long timestamp) {
}

private TextDocumentState getFile(ISourceLocation loc) {
loc = loc.top();
TextDocumentState file = files.get(loc);
if (file == null) {
throw new ResponseErrorException(unknownFileError(loc, loc));
Expand Down Expand Up @@ -752,7 +752,7 @@ public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> docume
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
logger.debug("codeAction: {}", params);

var location = Locations.toLoc(params.getTextDocument());
var location = Locations.setPosition(Locations.toLoc(params.getTextDocument()), params.getRange().getStart(), columns);
final ILanguageContributions contribs = contributions(location);

// first we make a future stream for filtering out the "fixes" that were optionally sent along with earlier diagnostics
Expand All @@ -766,10 +766,7 @@ public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActio
getFile(location)
.getCurrentTreeAsync(true)
.thenApply(Versioned::get)
.thenCompose(tree -> {
var range = Locations.toRascalRange(location, params.getRange(), columns);
return computeCodeActions(contribs, range.getStart().getLine(), range.getStart().getCharacter(), tree);
})
.thenCompose(tree -> computeCodeActions(contribs, location.getBeginLine(), location.getBeginColumn(), tree))
.thenApply(IList::stream)
, Stream::empty)
;
Expand Down Expand Up @@ -866,34 +863,32 @@ public CompletableFuture<List<SelectionRange>> selectionRange(SelectionRangePara
return recoverExceptions(file.getCurrentTreeAsync(true)
.thenApply(Versioned::get)
.thenCompose(t -> CompletableFutureUtils.reduce(params.getPositions().stream()
.map(p -> Locations.toRascalPosition(loc, p, columns))
.map(p -> Locations.setPosition(loc, p, columns))
.map(p -> computeSelection
.thenCompose(compute -> compute.apply(TreeSearch.computeFocusList(t, p.getLine(), p.getCharacter())))
.thenCompose(compute -> compute.apply(TreeSearch.computeFocusList(t, p.getBeginLine(), p.getBeginColumn())))
.thenApply(selection -> SelectionRanges.toSelectionRange(p, selection, columns)))
.collect(Collectors.toUnmodifiableList()), exec)),
Collections::emptyList);
}

@Override
public CompletableFuture<List<CallHierarchyItem>> prepareCallHierarchy(CallHierarchyPrepareParams params) {
final var loc = Locations.toLoc(params.getTextDocument());
final var loc = Locations.setPosition(Locations.toLoc(params.getTextDocument()), params.getPosition(), columns);
final var contrib = contributions(loc);
final var file = getFile(loc);

return recoverExceptions(file.getCurrentTreeAsync(true)
.thenApply(Versioned::get)
.thenCompose(t -> {
final var pos = Locations.toRascalPosition(loc, params.getPosition(), columns);
return contrib.prepareCallHierarchy(TreeSearch.computeFocusList(t, pos.getLine(), pos.getCharacter()))
.thenCompose(t ->
contrib.prepareCallHierarchy(TreeSearch.computeFocusList(t, loc.getBeginLine(), loc.getBeginColumn()))
.get()
.thenApply(items -> {
var ch = new CallHierarchy(exec);
return items.stream()
.map(IConstructor.class::cast)
.map(ci -> ch.toLSP(ci, columns))
.collect(Collectors.toList());
});
}), Collections::emptyList);
})), Collections::emptyList);
}

private <T> CompletableFuture<List<T>> incomingOutgoingCalls(BiFunction<CallHierarchyItem, List<Range>, T> constructor, CallHierarchyItem source, CallHierarchy.Direction direction) {
Expand Down Expand Up @@ -976,6 +971,7 @@ public synchronized void registerLanguage(LanguageParameter lang) {
}

private void updateFileState(LanguageParameter lang, ISourceLocation f) {
f = f.top();
logger.trace("File of language {} - updating state: {}", lang.getName(), f);
// Since we cannot know what happened to this file before we were called, we need to be careful about races.
// It might have been closed in the meantime, so we compute the new value if the key still exists, based on the current value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.initialization.qual.UnderInitialization;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.eclipse.lsp4j.Diagnostic;
Expand All @@ -44,6 +44,7 @@
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.rascalmpl.util.locations.ColumnMaps;
import org.rascalmpl.values.IRascalValueFactory;
import org.rascalmpl.values.parsetrees.ITree;
import org.rascalmpl.vscode.lsp.parametric.ILanguageContributions;
Expand All @@ -56,7 +57,6 @@
import org.rascalmpl.vscode.lsp.util.Lazy;
import org.rascalmpl.vscode.lsp.util.Versioned;
import org.rascalmpl.vscode.lsp.util.concurrent.InterruptibleFuture;
import org.rascalmpl.util.locations.ColumnMaps;
import org.rascalmpl.vscode.lsp.util.locations.IRangeMap;
import org.rascalmpl.vscode.lsp.util.locations.Locations;
import org.rascalmpl.vscode.lsp.util.locations.impl.TreeMapLookup;
Expand Down Expand Up @@ -498,13 +498,13 @@ public void invalidate() {
return null;
}

var pos = Locations.toRascalPosition(file, cursor, columns);
var focus = TreeSearch.computeFocusList(tree.get(), pos.getLine(), pos.getCharacter());
var pos = Locations.setRange(file, new Range(cursor, cursor), columns);
var focus = TreeSearch.computeFocusList(tree.get(), pos.getBeginLine(), pos.getBeginColumn());

InterruptibleFuture<ISet> set = null;

if (focus.isEmpty()) {
logger.trace("{}: could not find substree at line {} and offset {}", logName, pos.getLine(), pos.getCharacter());
logger.trace("{}: could not find substree at line {} and offset {}", logName, pos.getBeginLine(), pos.getBeginColumn());
set = InterruptibleFuture.completedFuture(IRascalValueFactory.getInstance().set(), exec);
} else {
logger.trace("{}: looked up focus with length: {}, now calling dedicated function", logName, focus.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.MessageParams;
import org.eclipse.lsp4j.MessageType;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.PrepareRenameDefaultBehavior;
import org.eclipse.lsp4j.PrepareRenameParams;
import org.eclipse.lsp4j.PrepareRenameResult;
Expand Down Expand Up @@ -408,8 +407,8 @@ public CompletableFuture<Either3<Range, PrepareRenameResult, PrepareRenameDefaul
return recoverExceptions(file.getCurrentTreeAsync(false)
.thenApply(Versioned::get)
.thenApply(tr -> {
Position rascalCursorPos = Locations.toRascalPosition(file.getLocation(), params.getPosition(), columns);
IList focus = TreeSearch.computeFocusList(tr, rascalCursorPos.getLine(), rascalCursorPos.getCharacter());
ISourceLocation rascalCursorPos = Locations.setPosition(file.getLocation(), params.getPosition(), columns);
IList focus = TreeSearch.computeFocusList(tr, rascalCursorPos.getBeginLine(), rascalCursorPos.getBeginColumn());
return findQualifiedNameUnderCursor(focus);
})
.thenApply(cur -> Locations.toRange(TreeAdapter.getLocation(cur), columns))
Expand All @@ -430,8 +429,8 @@ public CompletableFuture<WorkspaceEdit> rename(RenameParams params) {
return t;
})
.thenCompose(tr -> {
Position rascalCursorPos = Locations.toRascalPosition(file.getLocation(), params.getPosition(), columns);
var focus = TreeSearch.computeFocusList(tr, rascalCursorPos.getLine(), rascalCursorPos.getCharacter());
ISourceLocation rascalCursorPos = Locations.setPosition(file.getLocation(), params.getPosition(), columns);
var focus = TreeSearch.computeFocusList(tr, rascalCursorPos.getBeginLine(), rascalCursorPos.getBeginColumn());
var cursorTree = findQualifiedNameUnderCursor(focus);
var workspaceFolders = availableWorkspaceServices().workspaceFolders()
.stream()
Expand Down Expand Up @@ -611,9 +610,9 @@ public CompletableFuture<List<SelectionRange>> selectionRange(SelectionRangePara
return recoverExceptions(file.getCurrentTreeAsync(true)
.thenApply(Versioned::get)
.thenApply(tr -> params.getPositions().stream()
.map(p -> Locations.toRascalPosition(file.getLocation(), p, columns))
.map(p -> Locations.setPosition(file.getLocation(), p, columns))
.map(p -> {
var focus = TreeSearch.computeFocusList(tr, p.getLine(), p.getCharacter());
var focus = TreeSearch.computeFocusList(tr, p.getBeginLine(), p.getBeginColumn());
var locs = SelectionRanges.uniqueTreeLocations(focus);
return SelectionRanges.toSelectionRange(p, locs, columns);
})
Expand Down Expand Up @@ -693,9 +692,8 @@ public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActio
.getCurrentTreeAsync(true)
.thenApply(Versioned::get)
.thenCompose((ITree tree) -> {
var doc = params.getTextDocument();
var range = Locations.toRascalRange(doc, params.getRange(), columns);
return computeCodeActions(range.getStart().getLine(), range.getStart().getCharacter(), tree, availableFacts().getPathConfig(Locations.toLoc(doc)));
var loc = Locations.setPosition(Locations.toLoc(params.getTextDocument()), params.getRange().getStart(), columns);
return computeCodeActions(loc.getBeginLine(), loc.getBeginColumn(), tree, availableFacts().getPathConfig(loc));
})
.thenApply(IList::stream)
, Stream::empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void expungePathConfig(ISourceLocation project) {
}

public PathConfig lookupConfig(ISourceLocation forFile) {
forFile = forFile.top();
ISourceLocation projectRoot = translatedRoots.get(forFile);
return currentPathConfigs.computeIfAbsent(projectRoot, this::buildPathConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.rascalmpl.util.locations.ColumnMaps;
import org.rascalmpl.values.IRascalValueFactory;
import org.rascalmpl.values.ValueFactoryFactory;
import org.rascalmpl.vscode.lsp.util.Lazy;
import org.rascalmpl.util.locations.ColumnMaps;
import org.rascalmpl.vscode.lsp.util.locations.IRangeMap;
import org.rascalmpl.vscode.lsp.util.locations.Locations;
import org.rascalmpl.vscode.lsp.util.locations.impl.TreeMapLookup;
Expand Down Expand Up @@ -80,7 +80,7 @@ public SummaryBridge() {

public SummaryBridge(ISourceLocation self, IConstructor summary, ColumnMaps cm) {
this.data = summary.asWithKeywordParameters();
definitions = Lazy.defer(() -> translateRelation(getKWFieldSet(data, "useDef"), self, v -> Locations.toLSPLocation((ISourceLocation)v, cm), cm));
definitions = Lazy.defer(() -> translateRelation(getKWFieldSet(data, "useDef"), self, v -> Locations.toLocation((ISourceLocation)v, cm), cm));
typeNames = Lazy.defer(() -> translateMap(getKWFieldMap(data, "locationTypes"), self, v -> ((IString)v).getValue(), cm));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
import org.rascalmpl.exceptions.RuntimeExceptionFactory;
import org.rascalmpl.exceptions.Throw;
import org.rascalmpl.parser.gtd.exception.ParseError;
import org.rascalmpl.util.locations.ColumnMaps;
import org.rascalmpl.values.ValueFactoryFactory;
import org.rascalmpl.values.parsetrees.ITree;
import org.rascalmpl.values.parsetrees.TreeAdapter;
import org.rascalmpl.util.locations.ColumnMaps;
import org.rascalmpl.vscode.lsp.util.locations.Locations;
import io.usethesource.vallang.ICollection;
import io.usethesource.vallang.IConstructor;
Expand Down Expand Up @@ -179,7 +179,7 @@ public static List<Template> generateParseErrorDiagnostics(ITree errorTree) {
}

private static DiagnosticRelatedInformation related(ColumnMaps cm, ISourceLocation loc, String message) {
return new DiagnosticRelatedInformation(Locations.toLSPLocation(loc, cm), message);
return new DiagnosticRelatedInformation(Locations.toLocation(loc, cm), message);
}

private static void storeFixCommands(IConstructor d, Diagnostic result) {
Expand Down Expand Up @@ -220,7 +220,7 @@ public static Diagnostic translateDiagnostic(IConstructor d, Range range, Column
((IList) dKW.getParameter("causes")).stream()
.map(IConstructor.class::cast)
.map(c -> new DiagnosticRelatedInformation(
Locations.toLSPLocation(getMessageLocation(c), otherFiles),
Locations.toLocation(getMessageLocation(c), otherFiles),
getMessageString(c)))
.collect(Collectors.toList())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.stream.Collectors;

import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.SelectionRange;
import org.rascalmpl.util.locations.ColumnMaps;
import org.rascalmpl.values.IRascalValueFactory;
import org.rascalmpl.values.parsetrees.ITree;
import org.rascalmpl.values.parsetrees.TreeAdapter;
import org.rascalmpl.util.locations.ColumnMaps;
import org.rascalmpl.vscode.lsp.util.locations.Locations;

import io.usethesource.vallang.IList;
Expand All @@ -55,17 +53,17 @@ private SelectionRanges() { /* hide implicit constructor */ }
* @return A range with optional parent ranges, or an empty range when {@link ranges} is empty.
* @throws IllegalArgumentException when the list of ranges contains anything else than source locations
*/
public static SelectionRange toSelectionRange(Position origin, IList ranges, ColumnMaps columns) {
public static SelectionRange toSelectionRange(ISourceLocation origin, IList ranges, ColumnMaps columns) {
if (ranges.isEmpty()) {
return empty(origin);
return empty(origin, columns);
}

try {
var lspRanges = ranges.stream()
.map(ISourceLocation.class::cast)
.map(l -> Locations.toRange(l, columns))
.collect(Collectors.toList());
return toSelectionRange(origin, lspRanges);
return toSelectionRange(origin, lspRanges, columns);
} catch (ClassCastException e) {
throw new IllegalArgumentException("List of selection ranges should only contain source locations", e);
}
Expand All @@ -76,9 +74,9 @@ public static SelectionRange toSelectionRange(Position origin, IList ranges, Col
* @param ranges The range hierarchy. Should be ordered child-before-parent, where any range is contained by the next.
* @return A range with optional parent ranges
*/
public static SelectionRange toSelectionRange(Position origin, List<Range> ranges) {
public static SelectionRange toSelectionRange(ISourceLocation origin, List<Range> ranges, ColumnMaps columns) {
if (ranges.isEmpty()) {
return empty(origin);
return empty(origin, columns);
}

// assumes child-before-parent ordering
Expand Down Expand Up @@ -126,7 +124,7 @@ public static IList uniqueTreeLocations(IList trees) {
.collect(IRascalValueFactory.getInstance().listWriter());
}

public static SelectionRange empty(Position p) {
return new SelectionRange(new Range(p, p), null);
public static SelectionRange empty(ISourceLocation loc, ColumnMaps columns) {
return new SelectionRange(Locations.toRange(loc, columns), null);
}
}
Loading
Loading