Skip to content

Commit

Permalink
Workaround for extra ts folding range
Browse files Browse the repository at this point in the history
Fixes #49904
  • Loading branch information
mjbvz committed May 22, 2018
1 parent ab6290f commit 86adb52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"request": "attach",
"name": "Attach to Extension Host",
"protocol": "inspector",
"port": 5870,
"port": 5871,
// "restart": true,
"outFiles": [
"${workspaceFolder}/out/**/*.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,26 @@ export default class TypeScriptFoldingProvider implements vscode.FoldingRangePro
return;
}

return response.body.map(span => this.convertOutliningSpan(span, document));
return response.body
.map(span => this.convertOutliningSpan(span, document))
.filter(foldingRange => !!foldingRange) as vscode.FoldingRange[];
}

private convertOutliningSpan(span: Proto.OutliningSpan, document: vscode.TextDocument): vscode.FoldingRange {
private convertOutliningSpan(
span: Proto.OutliningSpan,
document: vscode.TextDocument
): vscode.FoldingRange | undefined {
const range = typeConverters.Range.fromTextSpan(span.textSpan);
const kind = TypeScriptFoldingProvider.getFoldingRangeKind(span);

// Workaround for #49904
if (span.kind === 'comment') {
const line = document.lineAt(range.start.line).text;
if (line.match(/\/\/\s*#endregion/gi)) {
return undefined;
}
}

const start = range.start.line;
// workaround for #47240
const end = (range.end.character > 0 && document.getText(new vscode.Range(range.end.translate(0, -1), range.end)) === '}')
Expand Down

0 comments on commit 86adb52

Please sign in to comment.