Skip to content

Commit e5eb53a

Browse files
authored
Candidate: Fix nb outline recompute + nb stickyscroll OutlineTarget (#211741)
* fix outline recompute event + nb stickyscroll target * exclude code cell from quickpick, maintain stable behavior
1 parent eec9689 commit e5eb53a

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class NotebookQuickPickProvider implements IQuickPickDataSource<OutlineEntry> {
288288

289289
constructor(
290290
private _getEntries: () => OutlineEntry[],
291+
@IConfigurationService private readonly _configurationService: IConfigurationService,
291292
@IThemeService private readonly _themeService: IThemeService
292293
) { }
293294

@@ -299,7 +300,25 @@ class NotebookQuickPickProvider implements IQuickPickDataSource<OutlineEntry> {
299300
const result: IQuickPickOutlineElement<OutlineEntry>[] = [];
300301
const { hasFileIcons } = this._themeService.getFileIconTheme();
301302

302-
for (const element of bucket) {
303+
const showSymbols = this._configurationService.getValue<boolean>(NotebookSetting.gotoSymbolsAllSymbols);
304+
for (let i = 0; i < bucket.length; i++) {
305+
const element = bucket[i];
306+
const nextElement = bucket[i + 1];
307+
308+
// this logic controls the following for code cells entries in quick pick:
309+
if (element.cell.cellKind === CellKind.Code) {
310+
// if we are showing all symbols, and
311+
// - the next entry is a symbol, we DO NOT include the code cell entry (ie continue)
312+
// - the next entry is not a symbol, we DO include the code cell entry (ie push as normal in the loop)
313+
if (showSymbols && element.level === NotebookOutlineConstants.NonHeaderOutlineLevel && (nextElement?.level > NotebookOutlineConstants.NonHeaderOutlineLevel)) {
314+
continue;
315+
}
316+
// if we are not showing all symbols, skip all entries with level > NonHeaderOutlineLevel (ie 8+)
317+
else if (!showSymbols && element.level > NotebookOutlineConstants.NonHeaderOutlineLevel) {
318+
continue;
319+
}
320+
}
321+
303322
const useFileIcon = hasFileIcons && !element.symbolKind;
304323
// todo@jrieken it is fishy that codicons cannot be used with iconClasses
305324
// but file icons can...

src/vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineEntryFactory.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ export class NotebookOutlineEntryFactory {
8787
// Gathering symbols from the model is an async operation, but this provider is syncronous.
8888
// So symbols need to be precached before this function is called to get the full list.
8989
if (cachedEntries) {
90-
// push code cell that is a parent of cached symbols if we are targeting the outlinePane
91-
if (target === OutlineTarget.OutlinePane) {
92-
entries.push(new OutlineEntry(index++, NotebookOutlineConstants.NonHeaderOutlineLevel, cell, preview, !!exeState, exeState ? exeState.isPaused : false));
93-
}
90+
// push code cell entry that is a parent of cached symbols, always necessary. filtering done elsewhere.
91+
entries.push(new OutlineEntry(index++, NotebookOutlineConstants.NonHeaderOutlineLevel, cell, preview, !!exeState, exeState ? exeState.isPaused : false));
9492
cachedEntries.forEach((cached) => {
9593
entries.push(new OutlineEntry(index++, cached.level, cell, cached.name, false, false, cached.range, cached.kind));
9694
});

src/vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineProvider.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,10 @@ export class NotebookCellOutlineProvider {
260260
}
261261
}));
262262

263-
this._recomputeActive();
263+
const { changeEventTriggered } = this._recomputeActive();
264+
if (!changeEventTriggered) {
265+
this._onDidChange.fire({});
266+
}
264267
}
265268

266269
private _recomputeActive(): { changeEventTriggered: boolean } {

src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorStickyScroll.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class NotebookStickyScroll extends Disposable {
202202
}
203203

204204
private init() {
205-
const { object: notebookOutlineReference } = this.notebookOutlineReference = this.instantiationService.invokeFunction((accessor) => accessor.get(INotebookCellOutlineProviderFactory).getOrCreate(this.notebookEditor, OutlineTarget.QuickPick));
205+
const { object: notebookOutlineReference } = this.notebookOutlineReference = this.instantiationService.invokeFunction((accessor) => accessor.get(INotebookCellOutlineProviderFactory).getOrCreate(this.notebookEditor, OutlineTarget.OutlinePane));
206206
this._register(this.notebookOutlineReference);
207207
this.updateContent(computeContent(this.notebookEditor, this.notebookCellList, notebookOutlineReference.entries, this.getCurrentStickyHeight()));
208208

src/vs/workbench/contrib/notebook/test/browser/contrib/notebookSymbols.test.ts

+23-19
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ suite('Notebook Symbols', function () {
8181
await entryFactory.cacheSymbols(cell, outlineModelService, CancellationToken.None);
8282
const entries = entryFactory.getOutlineEntries(cell, OutlineTarget.QuickPick, 0);
8383

84-
assert.equal(entries.length, 2, 'wrong number of outline entries');
85-
assert.equal(entries[0].label, 'var1');
84+
assert.equal(entries.length, 3, 'wrong number of outline entries');
85+
assert.equal(entries[0].label, '# code');
86+
assert.equal(entries[1].label, 'var1');
8687
// 6 levels for markdown, all code symbols are greater than the max markdown level
87-
assert.equal(entries[0].level, 8);
88-
assert.equal(entries[0].index, 0);
89-
assert.equal(entries[1].label, 'var2');
9088
assert.equal(entries[1].level, 8);
9189
assert.equal(entries[1].index, 1);
90+
assert.equal(entries[2].label, 'var2');
91+
assert.equal(entries[2].level, 8);
92+
assert.equal(entries[2].index, 2);
9293
});
9394

9495
test('Cell with nested symbols', async function () {
@@ -102,17 +103,18 @@ suite('Notebook Symbols', function () {
102103
await entryFactory.cacheSymbols(cell, outlineModelService, CancellationToken.None);
103104
const entries = entryFactory.getOutlineEntries(createCellViewModel(), OutlineTarget.QuickPick, 0);
104105

105-
assert.equal(entries.length, 5, 'wrong number of outline entries');
106-
assert.equal(entries[0].label, 'root1');
107-
assert.equal(entries[0].level, 8);
108-
assert.equal(entries[1].label, 'nested1');
109-
assert.equal(entries[1].level, 9);
110-
assert.equal(entries[2].label, 'nested2');
106+
assert.equal(entries.length, 6, 'wrong number of outline entries');
107+
assert.equal(entries[0].label, '# code');
108+
assert.equal(entries[1].label, 'root1');
109+
assert.equal(entries[1].level, 8);
110+
assert.equal(entries[2].label, 'nested1');
111111
assert.equal(entries[2].level, 9);
112-
assert.equal(entries[3].label, 'root2');
113-
assert.equal(entries[3].level, 8);
114-
assert.equal(entries[4].label, 'nested1');
115-
assert.equal(entries[4].level, 9);
112+
assert.equal(entries[3].label, 'nested2');
113+
assert.equal(entries[3].level, 9);
114+
assert.equal(entries[4].label, 'root2');
115+
assert.equal(entries[4].level, 8);
116+
assert.equal(entries[5].label, 'nested1');
117+
assert.equal(entries[5].level, 9);
116118
});
117119

118120
test('Multiple Cells with symbols', async function () {
@@ -129,10 +131,12 @@ suite('Notebook Symbols', function () {
129131
const entries2 = entryFactory.getOutlineEntries(createCellViewModel(1, '$2'), OutlineTarget.QuickPick, 0);
130132

131133

132-
assert.equal(entries1.length, 1, 'wrong number of outline entries');
133-
assert.equal(entries1[0].label, 'var1');
134-
assert.equal(entries2.length, 1, 'wrong number of outline entries');
135-
assert.equal(entries2[0].label, 'var2');
134+
assert.equal(entries1.length, 2, 'wrong number of outline entries');
135+
assert.equal(entries1[0].label, '# code');
136+
assert.equal(entries1[1].label, 'var1');
137+
assert.equal(entries2.length, 2, 'wrong number of outline entries');
138+
assert.equal(entries2[0].label, '# code');
139+
assert.equal(entries2[1].label, 'var2');
136140
});
137141

138142
});

0 commit comments

Comments
 (0)