import * as vscode from 'vscode' ; import { DefaultClient , GetFoldingRangesParams , GetFoldingRangesRequest , FoldingRangeKind , GetFoldingRangesResult , CppFoldingRange } from '../client' ; export class FoldingRangeProvider implements vscode . FoldingRangeProvider { private client : DefaultClient ; public onDidChangeFoldingRangesEvent = new vscode . EventEmitter < void > ( ) ; public onDidChangeFoldingRanges ? : vscode . Event < void > ; constructor ( client ) { this . client = client ; this . onDidChangeFoldingRanges = this . onDidChangeFoldingRangesEvent . event ; } async provideFoldingRanges ( document , context , token ) { const id = ++ DefaultClient . abortRequestId ; const params = { id : id , uri : document . uri . toString ( ) } ; await this . client . awaitUntilLanguageClientReady ( ) ; token . onCancellationRequested ( e => this . client . abortRequest ( id ) ) ; const ranges = await this . client . languageClient . sendRequest ( GetFoldingRangesRequest , params ) ; if ( ranges . canceled ) { return undefined ; } const result = [ ] ; ranges . ranges . forEach ( ( r ) => { const foldingRange = { start : r . range . startLine , end : r . range . endLine } ; switch ( r . kind ) { case FoldingRangeKind . Comment : foldingRange . kind = vscode . FoldingRangeKind . Comment ; break ; case FoldingRangeKind . Imports : foldingRange . kind = vscode . FoldingRangeKind . Imports ; break ; case FoldingRangeKind . Region : foldingRange . kind = vscode . FoldingRangeKind . Region ; break ; default : break ; } result . push ( foldingRange ) ; } ) ; return result ; } public refresh ( ) { this . onDidChangeFoldingRangesEvent . fire ( ) ; } }