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:
2026-09-22 08:45:31 +01:00
parent 3320f222bb
commit ce2e3e4cd3
21 changed files with 854 additions and 0 deletions
@@ -0,0 +1,14 @@
package p.studio.lsp.messages;
public record BaselineFoldingRange(
int startLine,
int startCharacter,
int endLine,
int endCharacter) {
public BaselineFoldingRange {
if (startLine < 0 || startCharacter < 0 || endLine < 0 || endCharacter < 0) {
throw new IllegalArgumentException("folding range coordinates must not be negative");
}
}
}
@@ -0,0 +1,13 @@
package p.studio.lsp.messages;
import java.util.List;
public record BaselineFoldingRanges(List<BaselineFoldingRange> ranges) {
public BaselineFoldingRanges {
ranges = ranges == null ? List.of() : List.copyOf(ranges);
}
public static BaselineFoldingRanges empty() {
return new BaselineFoldingRanges(List.of());
}
}
@@ -0,0 +1,15 @@
package p.studio.lsp.messages;
public record BaselineSelectionRange(
int startLine,
int startCharacter,
int endLine,
int endCharacter,
BaselineSelectionRange parent) {
public BaselineSelectionRange {
if (startLine < 0 || startCharacter < 0 || endLine < 0 || endCharacter < 0) {
throw new IllegalArgumentException("selection range coordinates must not be negative");
}
}
}
@@ -0,0 +1,13 @@
package p.studio.lsp.messages;
import java.util.List;
public record BaselineSelectionRanges(List<BaselineSelectionRange> ranges) {
public BaselineSelectionRanges {
ranges = ranges == null ? List.of() : List.copyOf(ranges);
}
public static BaselineSelectionRanges empty() {
return new BaselineSelectionRanges(List.of());
}
}
@@ -17,6 +17,8 @@ public record BaselineServerDescription(
boolean renameSupported,
boolean codeActionsSupported,
boolean documentLinksSupported,
boolean foldingRangesSupported,
boolean selectionRangesSupported,
List<String> semanticTokenTypes,
List<BaselineSemanticHostProjection> semanticHostProjections,
List<BaselineVisualTheme> visualThemes,