Better handling for large files in source code viewer

At the moment, the source code viewer in SonarQube will only display 500 lines before showing a “Load More Code” button, allowing you to display another 500 lines.
While this is a pretty sensible default in codebases where files are limited to ~1000 lines, many codebases do have 10,000+ lines per file.

Here’s a real example of where this can be a problem:

  • You have recently modified a file. This file has 16,000 lines.
  • An issue is raised at the top of the file. Drat, looks like CPD has found duplicate code blocks.
  • You begin scrolling through the file to find these duplicate code blocks. 500 lines later, you click “Load More Code” and keep scrolling.
  • Repeat 32 times.
  • Ah, there it is.

It seems there would be a couple of potential solutions here:

  • Allow SonarQube administrators to update the line threshold from 500 to some other number.
  • In addition to “Load More Code”, have a “Load All Code” button.

Hello @Jonah_IntegraDev,

Your request has been debated several times already and we did not find a solution that would balance both ability to view large files and keep a good user experience, in particular making sure that UI remains responsive when showing a lot of code. And we want to keep SonarQube focus on browsing quality issues, and not making it a full code viewer (gearing towards IDE features)

I wonder if there is not a simple solution for your particular problem of duplication: When a block of code is marked as duplicate, the “duplication bar” in the margin can be clicked to directly browse to that other piece of code that duplicates the current one. Is that not in essence what what you want to achieve ?

Olivier

Hi @OlivierK,

Unfortunately that approach only works if you can find one of the duplicate blocks to begin with. Since a duplicate-code issue itself appears at the top of the file and not at the site of the duplication, that can be problematic. In my example, both duplicate blocks are at the bottom of one file.

While I can understand wanting to have a sensible default (500 lines) for performance and user experience purposes, the lack of flexibility here has caused more than a few hiccups for us when browsing these types of quality issues.

Cheers,
Jonah

What if clicking the duplicate code issue took you to the first copy of the duplicate code and from there Sonarqube linked to the duplicate code?