|
98 | 98 | import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode;
|
99 | 99 | import org.eclipse.lsp4j.services.LanguageClient;
|
100 | 100 | import org.eclipse.lsp4j.services.LanguageClientAware;
|
101 |
| -import org.eclipse.lsp4j.util.Ranges; |
102 | 101 | import org.rascalmpl.library.Prelude;
|
103 |
| -import org.rascalmpl.uri.URIResolverRegistry; |
104 | 102 | import org.rascalmpl.library.util.PathConfig;
|
| 103 | +import org.rascalmpl.uri.URIResolverRegistry; |
105 | 104 | import org.rascalmpl.values.parsetrees.ITree;
|
106 | 105 | import org.rascalmpl.values.parsetrees.ProductionAdapter;
|
107 | 106 | import org.rascalmpl.values.parsetrees.TreeAdapter;
|
@@ -537,32 +536,22 @@ public CompletableFuture<List<SelectionRange>> selectionRange(SelectionRangePara
|
537 | 536 | private SelectionRange selectionRangeForPosition(ITree tr, Position pos) {
|
538 | 537 | // Compute focus list for cursor position
|
539 | 538 | var focus = TreeSearch.computeFocusList(tr, pos.getLine(), pos.getCharacter());
|
540 |
| - |
541 |
| - return focus |
542 |
| - // Iterate in reverse order, starting with the outermost tree |
| 539 | + var ranges = focus |
| 540 | + // Reverse, to prepare for folding later |
543 | 541 | .reverse()
|
544 | 542 | .stream()
|
545 | 543 | .map(ITree.class::cast)
|
546 | 544 | .map(TreeAdapter::getLocation)
|
547 |
| - // Map to distinct ranges |
548 | 545 | .map(l -> Locations.toRange(l, columns))
|
| 546 | + // Remove duplicate ranges |
549 | 547 | .distinct()
|
550 |
| - // Reduce to a single, nested SelectionRange |
551 |
| - .map(r -> new SelectionRange(r, null)) |
552 |
| - .reduce((t, u) -> { |
553 |
| - if (Ranges.containsRange(t.getRange(), u.getRange())) { |
554 |
| - // `t` contains `u` |
555 |
| - u.setParent(t); |
556 |
| - return u; |
557 |
| - } else if (Ranges.containsRange(u.getRange(), t.getRange())) { |
558 |
| - // `u` contains `t` |
559 |
| - t.setParent(u); |
560 |
| - return t; |
561 |
| - } else { |
562 |
| - throw new UnsupportedOperationException(String.format("Cannot combine two `SelectionRange`s, since they are not nested (%s and %s)", t, u)); |
563 |
| - } |
564 |
| - }) |
565 |
| - .orElse(new SelectionRange()); |
| 548 | + .collect(Collectors.toList()); |
| 549 | + |
| 550 | + SelectionRange selectionRange = null; |
| 551 | + for (var r : ranges) { |
| 552 | + selectionRange = new SelectionRange(r, selectionRange); |
| 553 | + } |
| 554 | + return selectionRange; |
566 | 555 | }
|
567 | 556 |
|
568 | 557 | @Override
|
|
0 commit comments