Skip to content

Commit 084179a

Browse files
author
aiday-mar
committed
1 parent 4595e8f commit 084179a

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

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

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,10 @@ export class StickyLineCandidateProvider extends Disposable {
9090
if (this._editor.hasModel()) {
9191
const model = this._editor.getModel();
9292
const modelVersionId = model.getVersionId();
93-
console.log('this._languageFeaturesService.documentSymbolProvider : ', this._languageFeaturesService.documentSymbolProvider);
94-
// TODO: Actually I should probably check what method to choose in the constructor
9593
const outlineModel = await OutlineModel.create(this._languageFeaturesService.documentSymbolProvider, model, token) as OutlineModel;
9694
if (token.isCancellationRequested) {
9795
return;
9896
}
99-
console.log('outline model : ', outlineModel);
10097
if (outlineModel.children.size !== 0) {
10198
this._outlineModel = StickyOutlineElement.fromOutlineModel(outlineModel);
10299
} else {
@@ -112,7 +109,6 @@ export class StickyLineCandidateProvider extends Disposable {
112109
);
113110
}
114111
}
115-
console.log('this._outlineModel : ', this._outlineModel);
116112
this._modelVersionId = modelVersionId;
117113
}
118114
}
@@ -212,21 +208,41 @@ class StickyOutlineElement {
212208
const regions = foldingModel.getRegions();
213209
const startIndexes = regions.getStartIndexes();
214210
const endIndexes = regions.getEndIndexes();
215-
console.log('startIndexes : ', startIndexes);
216-
console.log('endIndexes : ', endIndexes);
217-
let range = undefined;
218-
const children = [];
219-
const stack = [];
220-
for (let i = 1; i < startIndexes.length; i++) {
221-
range = new StickyRange(startIndexes[i], endIndexes[i]);
211+
if (startIndexes.length === 0) {
212+
return new StickyOutlineElement(
213+
new StickyRange(-1, -1),
214+
[],
215+
undefined
216+
);
222217
}
218+
let range = undefined;
219+
const stackOfParents: StickyRange[] = [];
223220

224-
//
225-
return new StickyOutlineElement(
226-
new StickyRange(-1, -1),
221+
const stickyOutlineElement = new StickyOutlineElement(
222+
undefined,
227223
[],
228224
undefined
229225
);
226+
let parentStickyOutlineElement = stickyOutlineElement;
227+
228+
for (let i = 0; i < startIndexes.length; i++) {
229+
range = new StickyRange(startIndexes[i], endIndexes[i]);
230+
while (stackOfParents.length !== 0 && (range.startLineNumber < (stackOfParents[stackOfParents.length - 1] as StickyRange).startLineNumber || range.endLineNumber > (stackOfParents[stackOfParents.length - 1] as StickyRange).endLineNumber)) {
231+
stackOfParents.pop();
232+
if (parentStickyOutlineElement.parent !== undefined) {
233+
parentStickyOutlineElement = parentStickyOutlineElement.parent;
234+
}
235+
}
236+
const child = new StickyOutlineElement(
237+
range,
238+
[],
239+
parentStickyOutlineElement
240+
);
241+
parentStickyOutlineElement.children.push(child);
242+
parentStickyOutlineElement = child;
243+
stackOfParents.push(range);
244+
}
245+
return stickyOutlineElement;
230246
}
231247

232248
constructor(
@@ -237,7 +253,7 @@ class StickyOutlineElement {
237253
/**
238254
* Must be sorted by start line number
239255
*/
240-
public readonly children: readonly StickyOutlineElement[],
256+
public children: StickyOutlineElement[],
241257
/**
242258
* Parent sticky outline element
243259
*/

0 commit comments

Comments
 (0)