Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code folding with nested ifs. #7793

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Extension/src/LanguageServer/Providers/foldingRangeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ export class FoldingRangeProvider implements vscode.FoldingRangeProvider {
}
const result: vscode.FoldingRange[] = [];
ranges.ranges.forEach((r: CppFoldingRange, index: number, array: CppFoldingRange[]) => {
let nextNonNestedIndex: number = index + 1; // Skip over nested if's.
for (; nextNonNestedIndex < array.length; ++nextNonNestedIndex) {
if (array[nextNonNestedIndex].range.start.line >= r.range.end.line) {
break;
}
}
const foldingRange: vscode.FoldingRange = {
start: r.range.start.line,
// Move the end range up one if it overlaps with the next start range, because
// VS Code doesn't support column-based folding: https://github.com/microsoft/vscode/issues/50840
end: r.range.end.line - (index + 1 >= array.length ? 0 :
(array[index + 1].range.start.line !== r.range.end.line ? 0 : 1))
end: r.range.end.line - (nextNonNestedIndex >= array.length ? 0 :
(array[nextNonNestedIndex].range.start.line !== r.range.end.line ? 0 : 1))
};
switch (r.kind) {
case FoldingRangeKind.Comment:
Expand Down