From ab3f48019df63438ab9166a21962e27ae3f8e38c Mon Sep 17 00:00:00 2001 From: kevinhwang91 Date: Sat, 11 Jun 2022 16:42:25 +0800 Subject: [PATCH] fix(folding): don't join folding range (#380) --- src/server/features/folding.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/server/features/folding.ts b/src/server/features/folding.ts index 0917c41..1f257bf 100644 --- a/src/server/features/folding.ts +++ b/src/server/features/folding.ts @@ -45,16 +45,22 @@ export default class TypeScriptFoldingProvider implements FoldingRangeProvider { ): FoldingRange | undefined { const range = typeConverters.Range.fromTextSpan(span.textSpan) const kind = TypeScriptFoldingProvider.getFoldingRangeKind(span) + let { start, end } = range // Workaround for #49904 if (span.kind === 'comment') { let doc = workspace.getDocument(document.uri) - const line = doc.getline(range.start.line) + const line = doc.getline(start.line) if (line.match(/\/\/\s*#endregion/gi)) { return undefined } + } else if (span.kind === 'code') { + let doc = workspace.getDocument(document.uri) + if (end.line > start.line && /^\s*}/.test(doc.getline(end.line))) { + end.line -= 1 + end.character = doc.getline(end.line).length + } } - let { start, end } = range return FoldingRange.create(start.line, end.line, start.character, end.character, kind) }