@psychelzh Thank you for your issue!
Looks interesting!
Also, Latex has similar function https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop .
I add this issue as help wanted.
Could be done using a DocumentSymbolProvider.
More detail on how this could be done: When a file is saved, look for section lines using a regex. Add these as symbols using DocumentSymbolProvider. They would then appear in the Outline and Breadcrumbs sections.
The language server also provides symbols, so it would be necessary to check that the language server symbols and the section symbols don鈥檛 conflict.
If anyone wants to have a go at implementing this, I鈥檓 happy to provide assistance.
@andycraig I'm not sure if DocumentSymbolProvider is suitable for this because it does not seem to preserve order.
@renkun-ken Oh! Then that might not be a good approach after all.
Markdown document sections are shown in the VSCode Outline in order: https://code.visualstudio.com/docs/languages/markdown#_outline-view The approach used for that might be more suitable.
Just notice that the sorting order can be easily changed to position order so DocumentSymbolProvider should be the solution to this but user needs to use position order.

This should be easy to implement. Do we prefer this to be implemented on vscode-R side or languageserver side? If languageserver is supposed to be pure about the language itself, then vscode-R should be the place this is implemented.
If you鈥檙e keen to implement code sections that would be great!
I鈥檓 inclined to agree that vscode-R seems like the more natural place than languageserver. @randy3k What do you think?
I am open to this.

This can be changed using DocumentSymbolProviderMetadata, but I'm not sure if we should merge the symbols provided by different symbol providers somehow, or maybe we should implement this in languageserver?
To provide unified document symbols, we better implement it in languageserver. https://github.com/REditorSupport/languageserver/pull/163 is the PR for this in languageserver which addresses all above issues.
As requested, moving my comments to REditorSupport/languageserver#163
@mik3y64 Glad to know it works for you. Would you mind putting your comments at https://github.com/REditorSupport/languageserver/pull/163 which seems to be the place we discuss it further since we'll implement this feature in languageserver?
Code sections are implemented by https://github.com/REditorSupport/languageserver/pull/163 and https://github.com/REditorSupport/languageserver/pull/186 in languageserver. Closing now.