@@ -12,11 +12,13 @@ import { LanguageFeaturesService } from 'vs/editor/common/services/languageFeatu
12
12
import { DocumentSymbol , SymbolKind } from 'vs/editor/common/languages' ;
13
13
import { StickyLineCandidate , StickyLineCandidateProvider } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollProvider' ;
14
14
import { EditorOption } from 'vs/editor/common/config/editorOptions' ;
15
+ import { ILogService , NullLogService } from 'vs/platform/log/common/log' ;
15
16
16
17
suite ( 'Sticky Scroll Tests' , ( ) => {
17
18
18
19
const serviceCollection = new ServiceCollection (
19
- [ ILanguageFeaturesService , new LanguageFeaturesService ( ) ]
20
+ [ ILanguageFeaturesService , new LanguageFeaturesService ( ) ] ,
21
+ [ ILogService , new NullLogService ( ) ]
20
22
) ;
21
23
22
24
const text = [
@@ -121,10 +123,10 @@ suite('Sticky Scroll Tests', () => {
121
123
await withAsyncTestCodeEditor ( model , { serviceCollection } , async ( editor , _viewModel , instantiationService ) => {
122
124
123
125
const stickyScrollController : StickyScrollController = editor . registerAndInstantiateContribution ( StickyScrollController . ID , StickyScrollController ) ;
124
- await stickyScrollController . stickyScrollCandidateProvider . update ( ) ;
125
126
const lineHeight : number = editor . getOption ( EditorOption . lineHeight ) ;
126
127
const languageService : ILanguageFeaturesService = instantiationService . get ( ILanguageFeaturesService ) ;
127
128
languageService . documentSymbolProvider . register ( '*' , documentSymbolProviderForTestModel ( ) ) ;
129
+ await stickyScrollController . stickyScrollCandidateProvider . update ( ) ;
128
130
let state ;
129
131
130
132
editor . setScrollTop ( 1 ) ;
@@ -163,12 +165,11 @@ suite('Sticky Scroll Tests', () => {
163
165
await withAsyncTestCodeEditor ( model , { serviceCollection } , async ( editor , viewModel , instantiationService ) => {
164
166
165
167
const stickyScrollController : StickyScrollController = editor . registerAndInstantiateContribution ( StickyScrollController . ID , StickyScrollController ) ;
166
- await stickyScrollController . stickyScrollCandidateProvider . update ( ) ;
167
168
const lineHeight = editor . getOption ( EditorOption . lineHeight ) ;
168
169
169
170
const languageService = instantiationService . get ( ILanguageFeaturesService ) ;
170
171
languageService . documentSymbolProvider . register ( '*' , documentSymbolProviderForTestModel ( ) ) ;
171
-
172
+ await stickyScrollController . stickyScrollCandidateProvider . update ( ) ;
172
173
editor . setHiddenAreas ( [ { startLineNumber : 2 , endLineNumber : 2 , startColumn : 1 , endColumn : 1 } , { startLineNumber : 10 , endLineNumber : 11 , startColumn : 1 , endColumn : 1 } ] ) ;
173
174
let state ;
174
175
@@ -197,4 +198,90 @@ suite('Sticky Scroll Tests', () => {
197
198
model . dispose ( ) ;
198
199
} ) ;
199
200
} ) ;
201
+
202
+ const textWithScopesWithSameStartingLines = [
203
+ 'class TestClass { foo() {' ,
204
+ 'function bar(){' ,
205
+ '' ,
206
+ '}}' ,
207
+ '}' ,
208
+ ''
209
+ ] . join ( '\n' ) ;
210
+
211
+ function documentSymbolProviderForSecondTestModel ( ) {
212
+ return {
213
+ provideDocumentSymbols ( ) {
214
+ return [
215
+ {
216
+ name : 'TestClass' ,
217
+ detail : 'TestClass' ,
218
+ kind : SymbolKind . Class ,
219
+ tags : [ ] ,
220
+ range : { startLineNumber : 1 , endLineNumber : 5 , startColumn : 1 , endColumn : 1 } ,
221
+ selectionRange : { startLineNumber : 1 , endLineNumber : 1 , startColumn : 1 , endColumn : 1 } ,
222
+ children : [
223
+ {
224
+ name : 'foo' ,
225
+ detail : 'foo' ,
226
+ kind : SymbolKind . Function ,
227
+ tags : [ ] ,
228
+ range : { startLineNumber : 1 , endLineNumber : 4 , startColumn : 1 , endColumn : 1 } ,
229
+ selectionRange : { startLineNumber : 1 , endLineNumber : 1 , startColumn : 1 , endColumn : 1 } ,
230
+ children : [
231
+ {
232
+ name : 'bar' ,
233
+ detail : 'bar' ,
234
+ kind : SymbolKind . Function ,
235
+ tags : [ ] ,
236
+ range : { startLineNumber : 2 , endLineNumber : 4 , startColumn : 1 , endColumn : 1 } ,
237
+ selectionRange : { startLineNumber : 2 , endLineNumber : 2 , startColumn : 1 , endColumn : 1 } ,
238
+ children : [ ]
239
+ } as DocumentSymbol
240
+ ]
241
+ } as DocumentSymbol ,
242
+ ]
243
+ } as DocumentSymbol
244
+ ] ;
245
+ }
246
+ } ;
247
+ }
248
+
249
+ test ( 'issue #159271 : render the correct widget state when the child scope starts on the same line as the parent scope' , async ( ) => {
250
+
251
+ const model = createTextModel ( textWithScopesWithSameStartingLines ) ;
252
+ await withAsyncTestCodeEditor ( model , { serviceCollection } , async ( editor , _viewModel , instantiationService ) => {
253
+
254
+ const stickyScrollController : StickyScrollController = editor . registerAndInstantiateContribution ( StickyScrollController . ID , StickyScrollController ) ;
255
+ const lineHeight = editor . getOption ( EditorOption . lineHeight ) ;
256
+
257
+ const languageService = instantiationService . get ( ILanguageFeaturesService ) ;
258
+ languageService . documentSymbolProvider . register ( '*' , documentSymbolProviderForSecondTestModel ( ) ) ;
259
+ await stickyScrollController . stickyScrollCandidateProvider . update ( ) ;
260
+ let state ;
261
+
262
+ editor . setScrollTop ( 1 ) ;
263
+ state = stickyScrollController . getScrollWidgetState ( ) ;
264
+ assert . deepStrictEqual ( state . lineNumbers , [ 1 , 2 ] ) ;
265
+
266
+ editor . setScrollTop ( lineHeight + 1 ) ;
267
+ state = stickyScrollController . getScrollWidgetState ( ) ;
268
+ assert . deepStrictEqual ( state . lineNumbers , [ 1 , 2 ] ) ;
269
+
270
+ editor . setScrollTop ( 2 * lineHeight + 1 ) ;
271
+ state = stickyScrollController . getScrollWidgetState ( ) ;
272
+ assert . deepStrictEqual ( state . lineNumbers , [ 1 ] ) ;
273
+
274
+ editor . setScrollTop ( 3 * lineHeight + 1 ) ;
275
+ state = stickyScrollController . getScrollWidgetState ( ) ;
276
+ assert . deepStrictEqual ( state . lineNumbers , [ 1 ] ) ;
277
+
278
+ editor . setScrollTop ( 4 * lineHeight + 1 ) ;
279
+ state = stickyScrollController . getScrollWidgetState ( ) ;
280
+ assert . deepStrictEqual ( state . lineNumbers , [ ] ) ;
281
+
282
+ stickyScrollController . dispose ( ) ;
283
+ stickyScrollController . stickyScrollCandidateProvider . dispose ( ) ;
284
+ model . dispose ( ) ;
285
+ } ) ;
286
+ } ) ;
200
287
} ) ;
0 commit comments