When viewing a file in a repo, be able to fold/collapse sections of code (functions/methods/blocks)

Problem to solve

As a developer who's browsing a large or unfamiliar source code file, it can be difficult to get an overview of the structure of the file. Many code editors (e.g. Visual Studio Code) offer the ability to "fold" or "collapse" sections of the source code by clicking on a chevron/arrow in the gutter, which temporarily hides the contents of the section next to the arrow. ("Section" here could mean a function/method, or a block within a function, an entire class definition, or another language-specific range of lines.)

It would be nice if GitLab offered a similar feature when viewing source code files (blob pages) in a repo.

Intended users

  • Delaney (Development Team Lead)
  • Sasha (Software Developer)
  • Simone (Software Engineer in Test)

User experience goal

Improve navigation within a single source code file.

Proposal

Make use of existing GitLab source code analysis infrastructure (Rouge? GKG? Zoekt?) to figure out the structure of a source code file. Use that to populate a frontend for collapsing sections.

Example of a Ruby source file viewed in Visual Studio Code:

Screenshot of a source code file in Visual Studio Code, with a pink arrow pointing to the chevron that can collapse/expand the contents of a method implementation

Permissions and Security

No permission/security changes; this would only show existing information.

What is the competitive advantage or differentiation for this feature?

GitHub already provides this feature. Example of a Java source file viewed on GitHub:

Screenshot of a source code file in GitHub, showing a chevron that can collapse/expand the contents of a method implementation

Edited Feb 03, 2026 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading