implements PLN-0137 (3/7) folding-and-selection-ranges
Advertise folding and selection only when the frontend supports them. Folding uses recovered spans for the listed declarations, their bodies, parameter lists, and Doc text blocks. A brace, parenthesis, or text block the tree does not cover still folds, including an unmatched opener through the end of the text. Selection grows outward from the identifier to the argument or parameter list, the block, and the declaration.
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
package p.studio.compiler.services;
|
||||
|
||||
public record FrontendFoldingRange(
|
||||
int startOffset,
|
||||
int endOffset) {
|
||||
|
||||
public FrontendFoldingRange {
|
||||
if (startOffset < 0) {
|
||||
throw new IllegalArgumentException("startOffset must not be negative");
|
||||
}
|
||||
if (endOffset < startOffset) {
|
||||
throw new IllegalArgumentException("endOffset must not be before startOffset");
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -153,6 +153,37 @@ public interface FrontendLanguageService {
|
||||
return documentLinks(request);
|
||||
}
|
||||
|
||||
default boolean foldingRangesSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default List<FrontendFoldingRange> foldingRanges(final FrontendDocumentRequest request) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
default List<FrontendFoldingRange> foldingRanges(
|
||||
final FrontendDocumentRequest request,
|
||||
final FrontendEditorialContext editorialContext) {
|
||||
return foldingRanges(request);
|
||||
}
|
||||
|
||||
default boolean selectionRangesSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default List<FrontendSelectionRange> selectionRanges(
|
||||
final FrontendDocumentRequest request,
|
||||
final List<Integer> offsets) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
default List<FrontendSelectionRange> selectionRanges(
|
||||
final FrontendDocumentRequest request,
|
||||
final FrontendEditorialContext editorialContext,
|
||||
final List<Integer> offsets) {
|
||||
return selectionRanges(request, offsets);
|
||||
}
|
||||
|
||||
default boolean codeActionsSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package p.studio.compiler.services;
|
||||
|
||||
public record FrontendSelectionRange(
|
||||
int startOffset,
|
||||
int endOffset,
|
||||
FrontendSelectionRange parent) {
|
||||
|
||||
public FrontendSelectionRange {
|
||||
if (startOffset < 0) {
|
||||
throw new IllegalArgumentException("startOffset must not be negative");
|
||||
}
|
||||
if (endOffset < startOffset) {
|
||||
throw new IllegalArgumentException("endOffset must not be before startOffset");
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -33,6 +33,12 @@ class FrontendLanguageServiceTest {
|
||||
assertFalse(service.documentLinksSupported());
|
||||
assertTrue(service.documentLinks(request).isEmpty());
|
||||
assertTrue(service.documentLinks(request, null).isEmpty());
|
||||
assertFalse(service.foldingRangesSupported());
|
||||
assertTrue(service.foldingRanges(request).isEmpty());
|
||||
assertTrue(service.foldingRanges(request, null).isEmpty());
|
||||
assertFalse(service.selectionRangesSupported());
|
||||
assertTrue(service.selectionRanges(request, List.of(0)).isEmpty());
|
||||
assertTrue(service.selectionRanges(request, null, List.of(0)).isEmpty());
|
||||
assertFalse(service.codeActionsSupported());
|
||||
assertTrue(service.codeActions(request).isEmpty());
|
||||
assertTrue(service.codeActions(request, null).isEmpty());
|
||||
|
||||
Reference in New Issue
Block a user