VS Code SonarLint focus mode "Focus on new code" does not work

  • Operating system: Windows 10 21H2 build 19044.3448
  • Visual Studio Code version: 1.82.3
  • SonarLint plugin version: v3.22.0
  • Programming language you’re coding in: Python
  • Is connected mode used:
    • Connected to SonarCloud or SonarQube (and which version): connected to SonarQube v10.1

I am developing Python code in VSCode and I have installed extension “Sonarlint”. In Connected mode, I have configured a binding to my source code root level. I have set my SonarLint focus to “focus on overall code” and this shows (correctly) two issues with my current file. However, when I switch the focus to “focus on new code”, the lower bar keeps showing “Sonarlint focus: overall code”. Also (more importantly), I still see the two old Sonarlint issues of my file. But in new code mode, I should not see any issues as I have not made any changes to the file yet.

Note that when I try to switch to “focus on overall code” again, I can only select “focus on overall code”, which suggests that vs code has tracked my current focus on new code but was not able to process it completely.

1 Like

Hello, thank you for reporting this!

There should be additional info about why SonarLint is not applying the new code definition from the server in a tooltip that appears when hovering over the “SonarLint focus” status bar item. In the case of my test project, here is what I get:


One possibility that can explain the behavior you reported is that the focus mode is correctly set to “on new code” in the settings, but the new code definition for the project cannot be applied - either that it cannot be synchronized from the server, or that it is not supported yet in SonarLint (e.g the “reference branch” new code definition is not supported).

Could you please check if this tooltip mentions anything?

Additionally, could you please check on the server what is the new code definition for your project (and current branch)?

Finally, if you enable verbose logging and reload the IDE, SonarLint should log a few messages during the synchronization with the server; at one point it should log something similar to the lines below:

[Debug - 08:40:33.732] GET 200 https://my.sonarqube.server/api/measures/component.protobuf?additionalFields=period&metricKeys=projects&component=my_project_key | response time=28ms
[Debug - 08:40:33.740] Storing new code definition in /home/username/.sonarlint/storage/646561756c74/projects/626c657672656d6e745f73d706c6644/new_code_definition.pb

Thanks for the tips, this will also help me a lot with future investigations!
For this case, it was indeed the problem that ‘Current new code definition (Reference branch) is not supported’. I assume that there is no workaround for that in VSCode for now. So, we will be working with focus on overall code. Please let me know if there are any other options.

Thank you for your feedback!

Long story short, since the “reference branch” new code definition relies on SCM information, we faced a lot of UX challenges when working on the first iteration of the “focus on new code” feature, so ultimately we decided to cut that branch (pun intended) and come back to it later.

Would you be open to sharing a bit more details about your use of the “reference branch” new code definition? E.g.:

  • What kind of branching policy is used on your project(s)?
  • How often is the reference branch analyzed on SonarQube?
  • How often does it “move forward”?
  • Is this branch usually fetched by developers in their personal environment?


We are working with feature branches on our main (develop) branch
Develop branch is analyzed after every PR merge which typically means about 10-20 times per week.
Every time, we merge a PR the develop branch moves forward automatically (not sure what you would like to know?)
Branch is often fetched in personal dev environments and new feature branch is created from there

Thank you for your input!

Seems that such a branching strategy would indeed increase the probability of having a “fresh enough” reference branch on the dev machines for SonarLint to rely on.