diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_folding.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_folding.dart index 94e4b761de6..65f254c4da3 100644 --- a/pkg/analysis_server/lib/src/lsp/handlers/handler_folding.dart +++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_folding.dart @@ -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; diff --git a/pkg/analysis_server/test/lsp/folding_test.dart b/pkg/analysis_server/test/lsp/folding_test.dart index a2442e5dae0..bd6cf18895b 100644 --- a/pkg/analysis_server/test/lsp/folding_test.dart +++ b/pkg/analysis_server/test/lsp/folding_test.dart @@ -482,6 +482,30 @@ void f(int a) { }, requireAll: false); } + /// https://github.com/Dart-Code/Dart-Code/issues/5750 + Future test_switchStatement_nested_sameEndLine_lineFoldingOnly() async { + lineFoldingOnly = true; + + var content = ''' +Future 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.