Skip to content

Commit af08b4f

Browse files
author
aiday-mar
committed
Tests committed
1 parent 930de55 commit af08b4f

File tree

1 file changed

+34
-65
lines changed

1 file changed

+34
-65
lines changed

src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts

Lines changed: 34 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55
import * as assert from 'assert';
6-
import { withAsyncTestCodeEditor, withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
6+
import { withAsyncTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
77
import { StickyScrollController } from 'vs/editor/contrib/stickyScroll/browser/stickyScroll';
88
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
99
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
1010
import { createTextModel } from 'vs/editor/test/common/testTextModel';
1111
import { LanguageFeaturesService } from 'vs/editor/common/services/languageFeaturesService';
1212
import { DocumentSymbol, SymbolKind } from 'vs/editor/common/languages';
13-
import { CoreEditingCommands, CoreNavigationCommands } from 'vs/editor/browser/coreCommands';
1413
import { StickyLineCandidate, StickyLineCandidateProvider } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollProvider';
1514
import { EditorOption } from 'vs/editor/common/config/editorOptions';
1615

@@ -22,7 +21,7 @@ suite('Sticky Scroll Tests', () => {
2221
[ILanguageFeaturesService, new LanguageFeaturesService()]
2322
);
2423

25-
const model = createTextModel([
24+
const text = [
2625
'function foo() {',
2726
'',
2827
'}',
@@ -37,7 +36,7 @@ suite('Sticky Scroll Tests', () => {
3736
'}}',
3837
'function bar() { function insideBar() {}',
3938
'}'
40-
].join('\n'));
39+
].join('\n');
4140

4241
function documentSymbolProviderForTestModel() {
4342
return {
@@ -103,51 +102,39 @@ suite('Sticky Scroll Tests', () => {
103102
}
104103

105104
test('Testing the function getCandidateStickyLinesIntersecting', async () => {
105+
const model = createTextModel(text);
106106
await withAsyncTestCodeEditor(model, { serviceCollection }, async (editor, _viewModel, instantiationService) => {
107107
const languageService = instantiationService.get(ILanguageFeaturesService);
108108
languageService.documentSymbolProvider.register('*', documentSymbolProviderForTestModel());
109109
const provider: StickyLineCandidateProvider = new StickyLineCandidateProvider(editor, languageService);
110110

111-
/*
112-
provider.onStickyScrollChange(() => {
113-
console.log('resolve');
114-
});
115-
*/
116-
117-
// TODO: The below times out doesn't return after 5000 ms
118-
/*
119-
await new Promise<void>(resolve => {
120-
const disposable = provider.onStickyScrollChange(() => {
121-
console.log('resolve');
122-
resolve();
123-
});
124-
disposable.dispose();
125-
});
126-
*/
127-
128-
// console.log('before update of provider');
129111
await provider.update();
130112

131113
assert.deepStrictEqual(provider.getCandidateStickyLinesIntersecting({ startLineNumber: 1, endLineNumber: 4 }), [new StickyLineCandidate(1, 2, 1)]);
132114
assert.deepStrictEqual(provider.getCandidateStickyLinesIntersecting({ startLineNumber: 1, endLineNumber: 10 }), [new StickyLineCandidate(1, 2, 1), new StickyLineCandidate(7, 11, 1), new StickyLineCandidate(9, 11, 2), new StickyLineCandidate(10, 10, 3)]);
133115
assert.deepStrictEqual(provider.getCandidateStickyLinesIntersecting({ startLineNumber: 1, endLineNumber: 13 }), [new StickyLineCandidate(1, 2, 1), new StickyLineCandidate(7, 11, 1), new StickyLineCandidate(9, 11, 2), new StickyLineCandidate(10, 10, 3), new StickyLineCandidate(13, 13, 1)]);
134116

135117
provider.dispose();
118+
model.dispose();
136119
});
137120
});
138121

139122
test('issue #157180: Render the correct line corresponding to the scope definition', async () => {
140123

124+
const model = createTextModel(text);
141125
await withAsyncTestCodeEditor(model, { serviceCollection }, async (editor, _viewModel, instantiationService) => {
142126

143127
const stickyScrollController: StickyScrollController = editor.registerAndInstantiateContribution(StickyScrollController.ID, StickyScrollController);
144128
await stickyScrollController.stickyScrollCandidateProvider.update();
145-
146129
const lineHeight: number = editor.getOption(EditorOption.lineHeight);
147130
const languageService: ILanguageFeaturesService = instantiationService.get(ILanguageFeaturesService);
148131
languageService.documentSymbolProvider.register('*', documentSymbolProviderForTestModel());
149132
let state;
150133

134+
editor.setScrollTop(1);
135+
state = stickyScrollController.getScrollWidgetState();
136+
assert.deepStrictEqual(state.lineNumbers, [1]);
137+
151138
editor.setScrollTop(lineHeight + 1);
152139
state = stickyScrollController.getScrollWidgetState();
153140
assert.deepStrictEqual(state.lineNumbers, [1]);
@@ -169,67 +156,49 @@ suite('Sticky Scroll Tests', () => {
169156
assert.deepStrictEqual(state.lineNumbers, [7]);
170157

171158
stickyScrollController.dispose();
159+
stickyScrollController.stickyScrollCandidateProvider.dispose();
160+
model.dispose();
172161
});
173162
});
174163

175-
test('issue #157809: Reveal the correct range taking into account the widget height', async () => {
164+
test('issue #156268 : Do not reveal sticky lines when they are in a folded region ', async () => {
176165

166+
const model = createTextModel(text);
177167
await withAsyncTestCodeEditor(model, { serviceCollection }, async (editor, viewModel, instantiationService) => {
178168

179-
const stickyScrollController = editor.registerAndInstantiateContribution(StickyScrollController.ID, StickyScrollController);
169+
const stickyScrollController: StickyScrollController = editor.registerAndInstantiateContribution(StickyScrollController.ID, StickyScrollController);
180170
await stickyScrollController.stickyScrollCandidateProvider.update();
181171
const lineHeight = editor.getOption(EditorOption.lineHeight);
182172

183173
const languageService = instantiationService.get(ILanguageFeaturesService);
184174
languageService.documentSymbolProvider.register('*', documentSymbolProviderForTestModel());
185175

186-
// editor.setPosition({ lineNumber: 5, column: 1 }, 'test');
187-
editor.setScrollTop(11 * lineHeight);
188-
189-
/*
190-
CoreNavigationCommands.CreateCursor.runCoreEditorCommand(viewModel, {
191-
source: 'mouse',
192-
position: new Position(2, 1),
193-
viewPosition: new Position(2, 1),
194-
wholeLine: true
195-
});
196-
*/
197-
// CoreNavigationCommands.MoveTo.runCoreEditorCommand(viewModel, { position: new Position(2, 1) });
198-
199-
200-
console.log('visible ranges : ', editor.getVisibleRanges()[0].startLineNumber);
201-
console.log('scroll top : ', Math.floor(editor.getScrollTop() / lineHeight));
202-
console.log('position : ', editor.getPosition().lineNumber);
203-
204-
/*
205-
editor.trigger('keyboard', Handler.Type, { text: 'd' });
206-
CoreNavigationCommands.RevealLine.runCoreEditorCommand(viewModel, { lineNumber: 5, source: undefined });
207-
*/
208-
CoreEditingCommands.Tab.runEditorCommand(null, editor, null);
209-
210-
console.log('visible ranges : ', editor.getVisibleRanges()[0].startLineNumber);
211-
console.log('scroll top : ', Math.floor(editor.getScrollTop() / lineHeight));
212-
console.log('position : ', editor.getPosition().lineNumber);
213-
214-
stickyScrollController.dispose();
176+
editor.setHiddenAreas([{ startLineNumber: 2, endLineNumber: 2, startColumn: 1, endColumn: 1 }, { startLineNumber: 10, endLineNumber: 11, startColumn: 1, endColumn: 1 }]);
177+
let state;
215178

216-
});
217-
});
179+
editor.setScrollTop(1);
180+
state = stickyScrollController.getScrollWidgetState();
181+
assert.deepStrictEqual(state.lineNumbers, [1]);
218182

219-
test('issue #156268 : Do not reveal sticky lines when they are in a folded region ', async () => {
183+
editor.setScrollTop(lineHeight + 1);
184+
state = stickyScrollController.getScrollWidgetState();
185+
assert.deepStrictEqual(state.lineNumbers, []);
220186

221-
await withAsyncTestCodeEditor(model, { serviceCollection }, async (editor, viewModel, instantiationService) => {
187+
editor.setScrollTop(6 * lineHeight + 1);
188+
state = stickyScrollController.getScrollWidgetState();
189+
assert.deepStrictEqual(state.lineNumbers, [7, 9]);
222190

223-
const stickyScrollController = editor.registerAndInstantiateContribution(StickyScrollController.ID, StickyScrollController);
224-
await stickyScrollController.stickyScrollCandidateProvider.update();
225-
const lineHeight = editor.getOption(EditorOption.lineHeight);
191+
editor.setScrollTop(7 * lineHeight + 1);
192+
state = stickyScrollController.getScrollWidgetState();
193+
assert.deepStrictEqual(state.lineNumbers, [7]);
226194

227-
const languageService = instantiationService.get(ILanguageFeaturesService);
228-
languageService.documentSymbolProvider.register('*', documentSymbolProviderForTestModel());
195+
editor.setScrollTop(10 * lineHeight + 1);
196+
state = stickyScrollController.getScrollWidgetState();
197+
assert.deepStrictEqual(state.lineNumbers, []);
229198

230199
stickyScrollController.dispose();
231-
200+
stickyScrollController.stickyScrollCandidateProvider.dispose();
201+
model.dispose();
232202
});
233203
});
234204
});
235-

0 commit comments

Comments
 (0)