fix(folding): don't join folding range (#380)

This commit is contained in:
kevinhwang91 2022-06-11 16:42:25 +08:00 committed by GitHub
parent 68e60a6924
commit ab3f48019d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)
}