Qodana 2024.1 Help

Visual Studio Code

Visual Studio Code is a source code editor available for Windows, macOS and Linux. This section shows you can use Qodana in Visual Studio Code:

Before you start

Make sure that you have a Qodana Cloud project, and this project has at least one analysis report related to the project opened by Visual Studio Code. Also, check whether Java 11 or later is installed on your machine by running the java -version command. If necessary, install Java on your local machine.

Download and install Qodana the extension from the Visual Studio Marketplace website, or by navigating to the Extensions view in Visual Studio Code.

UI overview

In the command palette, type View: Show Qodana and select the Qodana view.

Navigating to Qodana

This will open the Qodana view in left part of your Visual Studio Code UI.

The Qodana view

This view contains buttons leading to Qodana functionalities in Visual Studio Code.

Alternatively, in the command palette type Qodana to see the list of options present in the Qodana view.

Navigating to Qodana through a command palette

Run Qodana locally

You can run Qodana locally and then forward inspection reports to Qodana Cloud for storage and analysis purposes.

  1. In Visual Studio Code, navigate to the Qodana view and then click Run Locally.

    Clicking the Run Locally button in the Qodana view
  2. In the dialog that opens, enter the project token that was generated by Qodana Cloud.

    Specifying the Qodana Cloud project token
  3. If you have not previously specified a linter in the qodana.yaml file, choose it in the Select a linter list that opens.

    Specifying a linter

After Qodana runs, you can explore analysis results on the PROBLEMS tab of Visual Studio Code.

To see the history of local runs of Qodana and load analysis reports, in the Qodana view click the View History button and then choose the report you would like to explore.

To return the PROBLEMS tab to the default state, in the Qodana view click the Turn Analysis Off button.

Connect to Qodana Cloud

To forward Qodana reports to Qodana Cloud and get the latest Qodana reports, log in to Qodana Cloud and connect your project opened in the IDE to a specific Qodana Cloud project as shown below.

  1. In Visual Studio Code, navigate to the Qodana view, click the Log in to Cloud button and follow the instructions for redirecting to the authentication page.

    Logging in to Qodana Cloud
  2. In the Qodana view, select a project in Qodana Cloud that you would like to link your local project with, and then click Link. If the project is not present in the list, then click Other project and specify the project identifier in the dialog that opens.

    Selecting a project for linking
  3. Navigate to the PROBLEMS tab, or in the Qodana view click the Open Report button to explore analysis results.

Explore analysis results

You can explore analysis report of Qodana using the PROBLEMS tab of Visual Studio Code.

On this tab, you can click problem items and navigate to code fragments where Qodana detected them.

The PROBLEMS in VS Code

You can also view analysis reports generated after local Qodana runs using the View History button in the Qodana view.

Configure Qodana

Here is an overview of the Qodana configuration page.

Qodana settings in VS Code

You can configure the extension using the following settings:

Setting

Description

Path Prefix

If necessary, you can override the project path prefix. Here is the rule how the full path to project files is composed:

Full Path = Workspace + Path Prefix + Path in a SARIF file

Here are examples of how to define the correct path prefix:

Full path

Path in SARIF

Workspace

Path prefix

/foo/bar/baz/file

baz/file

/foo/bar

(empty, no value)

/foo/bar/baz/file

baz/file

/foo/bar/baz

..

/foo/bar/baz/file

file

/foo/bar

baz

In a Qodana Cloud report, you can check with the Files section to see how the path in a SARIF file is set.

Feel free to commit the .vscode/settings.json to your repository to share the Qodana settings with your team!

Project ID

You can get the Project ID value by opening the project from the Qodana Cloud report using the Open file in ... button and choosing Visual Studio Code as the tool for opening.

Alternatively, the Project ID value is contained in your Qodana Cloud project URL. This URL has the following structure: https://qodana.cloud/projects/PROJECT_ID/reports/REPORT_ID. From this URL, use only PROJECT_ID. For example, from the URL https://qodana.cloud/projects/AGvmx/reports/EDKYd you will need AGvmx.

In the status bar of the Visual Studio Code UI, you can find the Qodana icon. This icon can have the following states:

  • Settings are not valid means that you need to configure the extension. To do it, you can click this icon, which will redirect you to the extension configuration page.

  • Not attached to report means that you have configured the extension, but the report has not been downloaded yet. To download the report, click the icon.

  • Attached to report means that the report was downloaded from Qodana Cloud, and now you can view it using Visual Studio Code.

Troubleshooting

I need to switch to another Qodana Cloud account

You can use the Qodana: Reset authentication command to switch between Qodana Cloud accounts without clearing settings. This can be useful in case you have several organizations under different Qodana Cloud accounts.

I cannot get Qodana reports using current settings

You can use the Qodana: Reset all settings command to reset all settings and credentials and try to configure the extension again, or use other settings.

Last modified: 26 July 2024