[analysis_server] Fix folding ranges when nested ranges end on the same line
When the client only supports folding by-line (VS Code), we truncate ranges that intersect but allow nested ranges as long as they don't. This code was performing truncation if the outer range ended on the same line as the inner range, but this is perfectly fine and didn't need to truncate. Fixes https://github.com/Dart-Code/Dart-Code/issues/5750 Change-Id: I05e2307574481a7a53ee01ef76bd8a26bfde09c0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454920 Commit-Queue: Keerti Parthasarathy <keertip@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Keerti Parthasarathy <keertip@google.com>
This commit is contained in:
committed by
Commit Queue
parent
9cce31c2bb
commit
ceb6b5f797
@@ -106,8 +106,8 @@ class FoldingHandler
|
||||
for (var i = 0; i < foldingRanges.length - 1; i++) {
|
||||
var range = foldingRanges[i];
|
||||
var next = foldingRanges[i + 1];
|
||||
// If this item runs into the next but does not completely enclose it...
|
||||
if (range.endLine >= next.startLine && range.endLine <= next.endLine) {
|
||||
// If this item runs into the next but does not enclose it...
|
||||
if (range.endLine >= next.startLine && range.endLine < next.endLine) {
|
||||
// Truncate it to end on the line before.
|
||||
var newEndLine = next.startLine - 1;
|
||||
|
||||
|
||||
@@ -482,6 +482,30 @@ void f(int a) {
|
||||
}, requireAll: false);
|
||||
}
|
||||
|
||||
/// https://github.com/Dart-Code/Dart-Code/issues/5750
|
||||
Future<void> test_switchStatement_nested_sameEndLine_lineFoldingOnly() async {
|
||||
lineFoldingOnly = true;
|
||||
|
||||
var content = '''
|
||||
Future<void> f(int i) async {
|
||||
switch (i) {/*[0*/
|
||||
case 1:/*[1*/
|
||||
print('something');
|
||||
f(/*[2*/
|
||||
1,
|
||||
);/*2]*//*1]*/
|
||||
}/*0]*/
|
||||
}
|
||||
''';
|
||||
|
||||
await computeRanges(content);
|
||||
expectRanges({
|
||||
0: noFoldingKind,
|
||||
1: noFoldingKind,
|
||||
2: noFoldingKind,
|
||||
}, requireAll: false);
|
||||
}
|
||||
|
||||
/// Even without lineFolding, try/catch/finally folding regions end
|
||||
/// on the last statement of each block (matching if/else) to avoid long
|
||||
/// lines when folded.
|
||||
|
||||
Reference in New Issue
Block a user