@@ -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 = [
@@ -197,4 +199,90 @@ suite('Sticky Scroll Tests', () => {
197
199
model . dispose ( ) ;
198
200
} ) ;
199
201
} ) ;
202
+
203
+ const textWithScopesWithSameStartingLines = [
204
+ 'class TestClass { foo() {' ,
205
+ 'function bar(){' ,
206
+ '' ,
207
+ '}}' ,
208
+ '}' ,
209
+ ''
210
+ ] . join ( '\n' ) ;
211
+
212
+ function documentSymbolProviderForSecondTestModel ( ) {
213
+ return {
214
+ provideDocumentSymbols ( ) {
215
+ return [
216
+ {
217
+ name : 'TestClass' ,
218
+ detail : 'TestClass' ,
219
+ kind : SymbolKind . Class ,
220
+ tags : [ ] ,
221
+ range : { startLineNumber : 1 , endLineNumber : 5 , startColumn : 1 , endColumn : 1 } ,
222
+ selectionRange : { startLineNumber : 1 , endLineNumber : 1 , startColumn : 1 , endColumn : 1 } ,
223
+ children : [
224
+ {
225
+ name : 'foo' ,
226
+ detail : 'foo' ,
227
+ kind : SymbolKind . Function ,
228
+ tags : [ ] ,
229
+ range : { startLineNumber : 1 , endLineNumber : 4 , startColumn : 1 , endColumn : 1 } ,
230
+ selectionRange : { startLineNumber : 1 , endLineNumber : 1 , startColumn : 1 , endColumn : 1 } ,
231
+ children : [
232
+ {
233
+ name : 'bar' ,
234
+ detail : 'bar' ,
235
+ kind : SymbolKind . Function ,
236
+ tags : [ ] ,
237
+ range : { startLineNumber : 2 , endLineNumber : 4 , startColumn : 1 , endColumn : 1 } ,
238
+ selectionRange : { startLineNumber : 2 , endLineNumber : 2 , startColumn : 1 , endColumn : 1 } ,
239
+ children : [ ]
240
+ } as DocumentSymbol
241
+ ]
242
+ } as DocumentSymbol ,
243
+ ]
244
+ } as DocumentSymbol
245
+ ] ;
246
+ }
247
+ } ;
248
+ }
249
+
250
+ test ( 'issue #159271 : render the correct widget state when the child scope starts on the same line as the parent scope' , async ( ) => {
251
+
252
+ const model = createTextModel ( textWithScopesWithSameStartingLines ) ;
253
+ await withAsyncTestCodeEditor ( model , { serviceCollection } , async ( editor , _viewModel , instantiationService ) => {
254
+
255
+ const stickyScrollController : StickyScrollController = editor . registerAndInstantiateContribution ( StickyScrollController . ID , StickyScrollController ) ;
256
+ const lineHeight = editor . getOption ( EditorOption . lineHeight ) ;
257
+
258
+ const languageService = instantiationService . get ( ILanguageFeaturesService ) ;
259
+ languageService . documentSymbolProvider . register ( '*' , documentSymbolProviderForSecondTestModel ( ) ) ;
260
+ await stickyScrollController . stickyScrollCandidateProvider . update ( ) ;
261
+ let state ;
262
+
263
+ editor . setScrollTop ( 1 ) ;
264
+ state = stickyScrollController . getScrollWidgetState ( ) ;
265
+ assert . deepStrictEqual ( state . lineNumbers , [ 1 , 2 ] ) ;
266
+
267
+ editor . setScrollTop ( lineHeight + 1 ) ;
268
+ state = stickyScrollController . getScrollWidgetState ( ) ;
269
+ assert . deepStrictEqual ( state . lineNumbers , [ 1 , 2 ] ) ;
270
+
271
+ editor . setScrollTop ( 2 * lineHeight + 1 ) ;
272
+ state = stickyScrollController . getScrollWidgetState ( ) ;
273
+ assert . deepStrictEqual ( state . lineNumbers , [ 1 ] ) ;
274
+
275
+ editor . setScrollTop ( 3 * lineHeight + 1 ) ;
276
+ state = stickyScrollController . getScrollWidgetState ( ) ;
277
+ assert . deepStrictEqual ( state . lineNumbers , [ 1 ] ) ;
278
+
279
+ editor . setScrollTop ( 4 * lineHeight + 1 ) ;
280
+ state = stickyScrollController . getScrollWidgetState ( ) ;
281
+ assert . deepStrictEqual ( state . lineNumbers , [ ] ) ;
282
+
283
+ stickyScrollController . dispose ( ) ;
284
+ stickyScrollController . stickyScrollCandidateProvider . dispose ( ) ;
285
+ model . dispose ( ) ;
286
+ } ) ;
287
+ } ) ;
200
288
} ) ;
0 commit comments