@@ -42,6 +42,7 @@ export class StickyLineCandidateProvider extends Disposable {
42
42
private _outlineModel : StickyOutlineElement | undefined ;
43
43
private readonly _sessionStore : DisposableStore = new DisposableStore ( ) ;
44
44
private _modelVersionId : number = 0 ;
45
+ private _providerString : string = '' ;
45
46
46
47
constructor (
47
48
editor : ICodeEditor ,
@@ -65,10 +66,16 @@ export class StickyLineCandidateProvider extends Disposable {
65
66
this . _sessionStore . clear ( ) ;
66
67
return ;
67
68
} else {
68
- this . _sessionStore . add ( this . _editor . onDidChangeModel ( ( ) => this . update ( ) ) ) ;
69
+ this . _sessionStore . add ( this . _editor . onDidChangeModel ( ( ) => {
70
+ this . _providerString = '' ;
71
+ this . update ( ) ;
72
+ } ) ) ;
69
73
this . _sessionStore . add ( this . _editor . onDidChangeHiddenAreas ( ( ) => this . update ( ) ) ) ;
70
74
this . _sessionStore . add ( this . _editor . onDidChangeModelContent ( ( ) => this . _updateSoon . schedule ( ) ) ) ;
71
- this . _sessionStore . add ( this . _languageFeaturesService . documentSymbolProvider . onDidChange ( ( ) => this . update ( ) ) ) ;
75
+ this . _sessionStore . add ( this . _languageFeaturesService . documentSymbolProvider . onDidChange ( ( ) => {
76
+ this . _providerString = '' ;
77
+ this . update ( ) ;
78
+ } ) ) ;
72
79
this . update ( ) ;
73
80
}
74
81
}
@@ -81,16 +88,45 @@ export class StickyLineCandidateProvider extends Disposable {
81
88
this . _cts ?. dispose ( true ) ;
82
89
this . _cts = new CancellationTokenSource ( ) ;
83
90
await this . updateOutlineModel ( this . _cts . token ) ;
84
- console . log ( 'this._outlineModel : ' , this . _outlineModel ) ;
85
91
this . onStickyScrollChangeEmitter . fire ( ) ;
86
92
}
87
93
94
+ private findSumOfRangesOfGroup ( outline : OutlineGroup | OutlineElement ) : number {
95
+ let res = 0 ;
96
+ if ( outline . children . size !== 0 ) {
97
+ for ( const child of outline . children . values ( ) ) {
98
+ res += this . findSumOfRangesOfGroup ( child ) ;
99
+ }
100
+ }
101
+ if ( outline instanceof OutlineElement ) {
102
+ return res + outline . symbol . range . endLineNumber - outline . symbol . selectionRange . startLineNumber ;
103
+ } else {
104
+ return res ;
105
+ }
106
+ }
107
+
88
108
private async updateOutlineModel ( token : CancellationToken ) {
89
109
if ( this . _editor . hasModel ( ) ) {
90
110
const model = this . _editor . getModel ( ) ;
91
111
const modelVersionId = model . getVersionId ( ) ;
92
- console . log ( 'this._languageFeaturesService.documentSymbolProvider : ' , this . _languageFeaturesService . documentSymbolProvider ) ;
93
- const outlineModel = await OutlineModel . create ( this . _languageFeaturesService . documentSymbolProvider , model , token ) as OutlineModel ;
112
+ let outlineModel = await OutlineModel . create ( this . _languageFeaturesService . documentSymbolProvider , model , token ) as OutlineModel ;
113
+ if ( outlineModel . children . size !== 0 && outlineModel . children . values ( ) . next ( ) . value instanceof OutlineGroup ) {
114
+ if ( outlineModel . children . has ( this . _providerString ) ) {
115
+ outlineModel = outlineModel . children . get ( this . _providerString ) as unknown as OutlineModel ;
116
+ } else {
117
+ let providerString = '' ;
118
+ let maxTotalSumRanges = 0 ;
119
+ for ( const [ key , outlineGroup ] of outlineModel . children . entries ( ) ) {
120
+ const totalSumRanges = this . findSumOfRangesOfGroup ( outlineGroup ) ;
121
+ if ( totalSumRanges > maxTotalSumRanges ) {
122
+ maxTotalSumRanges = totalSumRanges ;
123
+ providerString = key ;
124
+ }
125
+ }
126
+ this . _providerString = providerString ;
127
+ outlineModel = outlineModel . children . get ( this . _providerString ) as unknown as OutlineModel ;
128
+ }
129
+ }
94
130
if ( token . isCancellationRequested ) {
95
131
return ;
96
132
}
0 commit comments