@@ -13,6 +13,8 @@ import { RunOnceScheduler } from 'vs/base/common/async';
13
13
import { Range } from 'vs/editor/common/core/range' ;
14
14
import { Emitter } from 'vs/base/common/event' ;
15
15
import { binarySearch } from 'vs/base/common/arrays' ;
16
+ import { FoldingController } from 'vs/editor/contrib/folding/browser/folding' ;
17
+ import { FoldingModel } from 'vs/editor/contrib/folding/browser/foldingModel' ;
16
18
17
19
export class StickyRange {
18
20
constructor (
@@ -88,11 +90,29 @@ export class StickyLineCandidateProvider extends Disposable {
88
90
if ( this . _editor . hasModel ( ) ) {
89
91
const model = this . _editor . getModel ( ) ;
90
92
const modelVersionId = model . getVersionId ( ) ;
93
+ console . log ( 'this._languageFeaturesService.documentSymbolProvider : ' , this . _languageFeaturesService . documentSymbolProvider ) ;
94
+ // TODO: Actually I should probably check what method to choose in the constructor
91
95
const outlineModel = await OutlineModel . create ( this . _languageFeaturesService . documentSymbolProvider , model , token ) as OutlineModel ;
92
96
if ( token . isCancellationRequested ) {
93
97
return ;
94
98
}
95
- this . _outlineModel = StickyOutlineElement . fromOutlineModel ( outlineModel ) ;
99
+ console . log ( 'outline model : ' , outlineModel ) ;
100
+ if ( outlineModel . children . size !== 0 ) {
101
+ this . _outlineModel = StickyOutlineElement . fromOutlineModel ( outlineModel ) ;
102
+ } else {
103
+ const foldingController = FoldingController . get ( this . _editor ) ;
104
+ const foldingModel = await foldingController ?. getFoldingModel ( ) ;
105
+ if ( foldingModel ) {
106
+ this . _outlineModel = StickyOutlineElement . fromFoldingModel ( foldingModel ) ;
107
+ } else {
108
+ this . _outlineModel = new StickyOutlineElement (
109
+ new StickyRange ( - 1 , - 1 ) ,
110
+ [ ] ,
111
+ undefined
112
+ ) ;
113
+ }
114
+ }
115
+ console . log ( 'this._outlineModel : ' , this . _outlineModel ) ;
96
116
this . _modelVersionId = modelVersionId ;
97
117
}
98
118
}
@@ -183,9 +203,32 @@ class StickyOutlineElement {
183
203
}
184
204
return new StickyOutlineElement (
185
205
range ,
186
- children
206
+ children ,
207
+ undefined
208
+ ) ;
209
+ }
210
+
211
+ public static fromFoldingModel ( foldingModel : FoldingModel ) : StickyOutlineElement {
212
+ const regions = foldingModel . getRegions ( ) ;
213
+ const startIndexes = regions . getStartIndexes ( ) ;
214
+ const endIndexes = regions . getEndIndexes ( ) ;
215
+ console . log ( 'startIndexes : ' , startIndexes ) ;
216
+ console . log ( 'endIndexes : ' , endIndexes ) ;
217
+ let range = undefined ;
218
+ const children = [ ] ;
219
+ const stack = [ ] ;
220
+ for ( let i = 1 ; i < startIndexes . length ; i ++ ) {
221
+ range = new StickyRange ( startIndexes [ i ] , endIndexes [ i ] ) ;
222
+ }
223
+
224
+ //
225
+ return new StickyOutlineElement (
226
+ new StickyRange ( - 1 , - 1 ) ,
227
+ [ ] ,
228
+ undefined
187
229
) ;
188
230
}
231
+
189
232
constructor (
190
233
/**
191
234
* Range of line numbers spanned by the current scope
@@ -195,6 +238,10 @@ class StickyOutlineElement {
195
238
* Must be sorted by start line number
196
239
*/
197
240
public readonly children : readonly StickyOutlineElement [ ] ,
241
+ /**
242
+ * Parent sticky outline element
243
+ */
244
+ public readonly parent : StickyOutlineElement | undefined
198
245
) {
199
246
}
200
247
}
0 commit comments