@@ -233,6 +233,8 @@ interface DecorationRangesPair {
233233 ranges : vscode . Range [ ] ;
234234}
235235
236+ type InactiveRegionFoldingOperation = 'fold' | 'unfold' ;
237+
236238interface InternalSourceFileConfiguration extends SourceFileConfiguration {
237239 compilerArgsLegacy ?: string [ ] ;
238240}
@@ -800,7 +802,8 @@ export interface Client {
800802 selectTranslationUnit ( uri : vscode . Uri , translationUnit : string ) : Promise < void > ;
801803 updateActiveDocumentTextOptions ( ) : void ;
802804 didChangeActiveEditor ( editor ?: vscode . TextEditor , selection ?: Range ) : Promise < void > ;
803- foldInactiveRegions ( ) : Promise < void > ;
805+ foldAllInactiveRegions ( ) : Promise < void > ;
806+ unfoldAllInactiveRegions ( ) : Promise < void > ;
804807 restartIntelliSenseForFile ( document : vscode . TextDocument ) : Promise < void > ;
805808 activate ( ) : void ;
806809 selectionChanged ( selection : Range ) : Promise < void > ;
@@ -882,7 +885,7 @@ export class DefaultClient implements Client {
882885 private trackedDocuments = new Map < string , vscode . TextDocument > ( ) ;
883886 private inactiveRegionsDecorations = new Map < string , DecorationRangesPair > ( ) ;
884887 private inactiveRegions = new InactiveRegionStore ( ) ;
885- private pendingInactiveRegionFolds = new Set < string > ( ) ;
888+ private pendingInactiveRegionFoldingOperations = new Map < string , InactiveRegionFoldingOperation > ( ) ;
886889 private autoFoldedEditors = new WeakSet < vscode . TextEditor > ( ) ;
887890 private settingsTracker : SettingsTracker ;
888891 private loggingLevel : number = 1 ;
@@ -1904,7 +1907,7 @@ export class DefaultClient implements Client {
19041907 }
19051908 if ( changedSettings . autoFoldInactiveRegions !== undefined && vscode . window . activeTextEditor
19061909 && clients . getClientFor ( vscode . window . activeTextEditor . document . uri ) === this ) {
1907- void this . tryFoldInactiveRegions ( vscode . window . activeTextEditor ) . catch ( logAndReturn . undefined ) ;
1910+ void this . tryApplyInactiveRegionFolding ( vscode . window . activeTextEditor ) . catch ( logAndReturn . undefined ) ;
19081911 }
19091912 if ( changedSettings . legacyCompilerArgsBehavior !== undefined ) {
19101913 this . configuration . handleConfigurationChange ( ) ;
@@ -2012,7 +2015,7 @@ export class DefaultClient implements Client {
20122015 const uri : string = document . uri . toString ( ) ;
20132016 openFileVersions . set ( uri , document . version ) ;
20142017 this . inactiveRegions . delete ( uri ) ;
2015- this . pendingInactiveRegionFolds . delete ( uri ) ;
2018+ this . pendingInactiveRegionFoldingOperations . delete ( uri ) ;
20162019 }
20172020 }
20182021
@@ -2025,7 +2028,7 @@ export class DefaultClient implements Client {
20252028 this . inlayHintsProvider . removeFile ( uri ) ;
20262029 }
20272030 this . inactiveRegions . delete ( uri ) ;
2028- this . pendingInactiveRegionFolds . delete ( uri ) ;
2031+ this . pendingInactiveRegionFoldingOperations . delete ( uri ) ;
20292032 this . inactiveRegionsDecorations . delete ( uri ) ;
20302033 if ( diagnosticsCollectionIntelliSense ) {
20312034 diagnosticsCollectionIntelliSense . delete ( document . uri ) ;
@@ -2981,21 +2984,29 @@ export class DefaultClient implements Client {
29812984
29822985 const activeEditor : vscode . TextEditor | undefined = vscode . window . activeTextEditor ;
29832986 if ( isCompletePass && activeEditor ?. document . uri . toString ( ) === uriString ) {
2984- void client . tryFoldInactiveRegions ( activeEditor ) . catch ( logAndReturn . undefined ) ;
2987+ void client . tryApplyInactiveRegionFolding ( activeEditor ) . catch ( logAndReturn . undefined ) ;
29852988 }
29862989 }
29872990
2988- public async foldInactiveRegions ( ) : Promise < void > {
2991+ public foldAllInactiveRegions ( ) : Promise < void > {
2992+ return this . applyInactiveRegionFolding ( 'fold' ) ;
2993+ }
2994+
2995+ public unfoldAllInactiveRegions ( ) : Promise < void > {
2996+ return this . applyInactiveRegionFolding ( 'unfold' ) ;
2997+ }
2998+
2999+ private async applyInactiveRegionFolding ( operation : InactiveRegionFoldingOperation ) : Promise < void > {
29893000 const editor : vscode . TextEditor | undefined = vscode . window . activeTextEditor ;
29903001 if ( ! editor || ! util . isCpp ( editor . document ) ) {
29913002 return ;
29923003 }
29933004
2994- this . pendingInactiveRegionFolds . add ( editor . document . uri . toString ( ) ) ;
2995- await this . tryFoldInactiveRegions ( editor ) ;
3005+ this . pendingInactiveRegionFoldingOperations . set ( editor . document . uri . toString ( ) , operation ) ;
3006+ await this . tryApplyInactiveRegionFolding ( editor ) ;
29963007 }
29973008
2998- private async tryFoldInactiveRegions ( editor : vscode . TextEditor ) : Promise < void > {
3009+ private async tryApplyInactiveRegionFolding ( editor : vscode . TextEditor ) : Promise < void > {
29993010 if ( vscode . window . activeTextEditor !== editor || ! util . isCpp ( editor . document ) ) {
30003011 return ;
30013012 }
@@ -3009,12 +3020,14 @@ export class DefaultClient implements Client {
30093020 const settings : CppSettings = new CppSettings ( editor . document . uri ) ;
30103021 const autoFold : boolean = settings . autoFoldInactiveRegions && settings . codeFolding
30113022 && ! this . autoFoldedEditors . has ( editor ) ;
3012- const manualFold : boolean = this . pendingInactiveRegionFolds . has ( uri ) ;
3013- if ( ! autoFold && ! manualFold ) {
3023+ const pendingOperation : InactiveRegionFoldingOperation | undefined =
3024+ this . pendingInactiveRegionFoldingOperations . get ( uri ) ;
3025+ const operation : InactiveRegionFoldingOperation | undefined = pendingOperation ?? ( autoFold ? 'fold' : undefined ) ;
3026+ if ( operation === undefined ) {
30143027 return ;
30153028 }
30163029
3017- this . pendingInactiveRegionFolds . delete ( uri ) ;
3030+ this . pendingInactiveRegionFoldingOperations . delete ( uri ) ;
30183031
30193032 const selectionLines : number [ ] = getInactiveRegionStartLines ( inactiveRegions ) ;
30203033 if ( selectionLines . length === 0 ) {
@@ -3025,16 +3038,16 @@ export class DefaultClient implements Client {
30253038 this . autoFoldedEditors . add ( editor ) ;
30263039 }
30273040 try {
3028- await vscode . commands . executeCommand ( ' editor.fold' , {
3041+ await vscode . commands . executeCommand ( ` editor.${ operation } ` , {
30293042 selectionLines,
30303043 direction : 'down'
30313044 } ) ;
30323045 } catch ( error ) {
30333046 if ( autoFold ) {
30343047 this . autoFoldedEditors . delete ( editor ) ;
30353048 }
3036- if ( manualFold ) {
3037- this . pendingInactiveRegionFolds . add ( uri ) ;
3049+ if ( pendingOperation ) {
3050+ this . pendingInactiveRegionFoldingOperations . set ( uri , pendingOperation ) ;
30383051 }
30393052 throw error ;
30403053 }
@@ -3207,7 +3220,7 @@ export class DefaultClient implements Client {
32073220 return ;
32083221 }
32093222
3210- void this . tryFoldInactiveRegions ( editor ) . catch ( logAndReturn . undefined ) ;
3223+ void this . tryApplyInactiveRegionFolding ( editor ) . catch ( logAndReturn . undefined ) ;
32113224 this . updateActiveDocumentTextOptions ( ) ;
32123225
32133226 const params : DidChangeActiveEditorParams = {
@@ -4519,7 +4532,8 @@ class NullClient implements Client {
45194532 selectTranslationUnit ( uri : vscode . Uri , translationUnit : string ) : Promise < void > { return Promise . resolve ( ) ; }
45204533 updateActiveDocumentTextOptions ( ) : void { }
45214534 didChangeActiveEditor ( editor ?: vscode . TextEditor ) : Promise < void > { return Promise . resolve ( ) ; }
4522- foldInactiveRegions ( ) : Promise < void > { return Promise . resolve ( ) ; }
4535+ foldAllInactiveRegions ( ) : Promise < void > { return Promise . resolve ( ) ; }
4536+ unfoldAllInactiveRegions ( ) : Promise < void > { return Promise . resolve ( ) ; }
45234537 restartIntelliSenseForFile ( document : vscode . TextDocument ) : Promise < void > { return Promise . resolve ( ) ; }
45244538 activate ( ) : void { }
45254539 selectionChanged ( selection : Range ) : Promise < void > { return Promise . resolve ( ) ; }
0 commit comments