Skip to content

editor: add experimental fold header detection for sticky scroll#299593

Open
dabravin wants to merge 1 commit intomicrosoft:mainfrom
dabravin:feat/sticky-scroll-fold-header-detection
Open

editor: add experimental fold header detection for sticky scroll#299593
dabravin wants to merge 1 commit intomicrosoft:mainfrom
dabravin:feat/sticky-scroll-fold-header-detection

Conversation

@dabravin
Copy link

@dabravin dabravin commented Mar 5, 2026

Summary

Fixes #238568

Introduces editor.stickyScroll.foldHeaderDetection - an opt-in experimental boolean (default false) that makes folding-based sticky scroll providers walk back from the raw fold-start line to find a more meaningful scope header.

What it does when enabled:

  • Walks past lone Allman-style { lines and any blank lines above them
  • Walks past trailing return-type lines (-> ReturnType) that appear between ) and { in C++/Rust
  • Performs a right-to-left bracket scan (up to 15 lines back) to resolve multi-line signatures to their opening ( line

Result: instead of the sticky strip showing stacked { characters, it shows the actual declaration — void foo(int x, int y) or the if ( that opened a multi-line condition.

What it does not change:

  • K&R style (void foo() {) - fold start is already the header line, no walk-back occurs
  • Python, JSON, etc. - no standalone { lines, no walk-back triggered
  • Default behaviour - flag is false, zero impact on existing users

Scope

File Change
src/vs/editor/common/config/editorOptions.ts New foldHeaderDetection field, default, schema entry with tags: ['experimental'], validate
src/vs/editor/contrib/stickyScroll/browser/stickyScrollModelProvider.ts Guard heuristic behind flag in _fromFoldingRegions; extracted helpers _findFoldHeaderLine and _findSignatureOpeningLine with full JSDoc
src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts 9 indentation-model tests + 1 syntax-provider smoke test covering Allman braces, multi-line signatures, trailing return types, nested scopes, and walk-back safety
src/vs/monaco.d.ts Public API surface updated to include new interface field

Test plan

  • Open a C++ file with Allman-style braces - with flag false (default), sticky scroll unchanged
  • Set "editor.stickyScroll.foldHeaderDetection": true - sticky strip walks back to function signature lines
  • Search stickyScroll in Settings UI - new entry appears tagged (Experimental)

@dabravin dabravin force-pushed the feat/sticky-scroll-fold-header-detection branch from 012480e to cf730d9 Compare March 5, 2026 20:53
@dabravin
Copy link
Author

dabravin commented Mar 5, 2026

@microsoft-github-policy-service agree

Introduce `editor.stickyScroll.foldHeaderDetection` (default: false,
tagged experimental) to walk back from the raw fold-start line to a
more meaningful scope header.

When enabled, the folding-based sticky scroll providers walk past lone
Allman-style `{` lines, blank lines, and trailing return-type lines
(`-> T`) to find the actual declaration line. A right-to-left bracket
scan then resolves multi-line signatures to their opening `(` line,
so the sticky strip shows `void foo(` rather than `{`.

The heuristic is a best-effort aid primarily for C++ and Rust. It has
no effect when the fold start is already the header line (K&R style,
Python, etc.), and falls back to the raw fold start on any ambiguous
structure. The feature flag lets affected users opt in without risk to
unrelated language workflows.

Closes microsoft#238568
@dabravin dabravin force-pushed the feat/sticky-scroll-fold-header-detection branch from 2c13b46 to 3fca507 Compare March 11, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow multiple lines per StickyScroll entry

2 participants