Skip to content

Commit e0c9020

Browse files
authored
Fix overlapping folding ranges. (#7716)
1 parent e2d49e7 commit e0c9020

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Extension/src/LanguageServer/Providers/foldingRangeProvider.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* See 'LICENSE' in the project root for license information.
44
* ------------------------------------------------------------------------------------------ */
55
import * as vscode from 'vscode';
6-
import { DefaultClient, GetFoldingRangesParams, GetFoldingRangesRequest, FoldingRangeKind, GetFoldingRangesResult } from '../client';
6+
import { DefaultClient, GetFoldingRangesParams, GetFoldingRangesRequest, FoldingRangeKind, GetFoldingRangesResult, CppFoldingRange } from '../client';
77

88
export class FoldingRangeProvider implements vscode.FoldingRangeProvider {
99
private client: DefaultClient;
@@ -27,10 +27,13 @@ export class FoldingRangeProvider implements vscode.FoldingRangeProvider {
2727
return undefined;
2828
}
2929
const result: vscode.FoldingRange[] = [];
30-
ranges.ranges.forEach((r) => {
30+
ranges.ranges.forEach((r: CppFoldingRange, index: number, array: CppFoldingRange[]) => {
3131
const foldingRange: vscode.FoldingRange = {
3232
start: r.range.start.line,
33-
end: r.range.end.line
33+
// Move the end range up one if it overlaps with the next start range, because
34+
// VS Code doesn't support column-based folding: https://github.com/microsoft/vscode/issues/50840
35+
end: r.range.end.line - (index + 1 >= array.length ? 0 :
36+
(array[index + 1].range.start.line !== r.range.end.line ? 0 : 1))
3437
};
3538
switch (r.kind) {
3639
case FoldingRangeKind.Comment:

Extension/src/LanguageServer/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,14 @@ export enum FoldingRangeKind {
369369
Region = 3
370370
}
371371

372-
interface FoldingRange {
372+
export interface CppFoldingRange {
373373
kind: FoldingRangeKind;
374374
range: Range;
375375
}
376376

377377
export interface GetFoldingRangesResult {
378378
canceled: boolean;
379-
ranges: FoldingRange[];
379+
ranges: CppFoldingRange[];
380380
}
381381

382382
interface AbortRequestParams {

0 commit comments

Comments
 (0)