VS Code

Perform analysis and resolve issues directly from the convenience of your VS Code environment.

DeepSource's integration with Visual Studio Code lets you to run comprehensive analyses, identify and address potential problems, and synchronize existing as well as new issues with DeepSource — all without the need to create a pull request.

In addition to issue detection, we have also introduced support for AI-based Autofix. With this feature, you can automatically generate fixes for your code health issues by harnessing the capabilities of AI.

Installation

  1. Open Visual Studio Code (VS Code).
  2. Go to the VS Code Marketplace by clicking on the Extensions icon in the Activity Bar on the side of the window or using the keyboard shortcut Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X(Mac).
  3. In the Extensions view, search for "DeepSource" in the search bar.
  4. Click on the "Install" button next to the "DeepSource Autofix™ AI" extension in the search results.
  5. Wait for the installation to complete. You should see a notification confirming successful installation.

Alternatively, you can also download and install the extension from the VS Code Marketplace directly.

Activation

  1. Once the extension is installed, you should see the DeepSource icon in VS Code’s sidebar (usually located on the left-hand side).
  2. Click on the DeepSource icon to open the DeepSource panel.

Log-in

  1. Upon opening the DeepSource panel for the first time, you'll be prompted to log in.
  2. For cloud users, click the “Login to DeepSource Cloud” button. This will redirect you to the DeepSource website for authentication.
  3. For enterprise users, click “Login to Enterprise Server”, and you'll be asked to enter the URL for your DeepSource installation in the prompt. After entering the URL, hit "Enter" to proceed.
  1. A browser window will be launched, taking you to the DeepSource login page.

Authentication

  1. In the browser window, enter your DeepSource credentials (username and password) to log in.
  2. If it's your first time logging in, you might need to follow some additional setup steps, such as configuring repositories or setting up analysis preferences. Follow the on-screen instructions to complete the setup.

Extension activation

  1. After successful authentication, the VS Code extension should now be fully activated.
  2. The DeepSource panel in VS Code will display information about your currently open project, and any existing code health issues.

Run analysis in VS Code

Prerequisites

  1. Make sure you have the DeepSource extension installed and activated in your VS Code, as outlined in the previous installation steps.
  2. Ensure that you have a project open in VS Code that meets the following criteria:
    • It should be a git repository.
    • The project should be activated on DeepSource. If it's not already activated, it will run in the Single Player Mode, where no existing issues from DeepSource cloud would be shown. The IDE won't do any baseline issue diffing too, which means you would see all issues present in your file at all time.

Single Player Mode

The extension automatically switches to the Single Player mode in the following cases:

  • When the current directory opened isn't a git repository.
  • When the project you're working on is not activated on DeepSource account you are logged in with.

You'd be shown an info message when this happens

Baseline issue diffing isn't available in this mode, and you'll always see all issues in your current file.

🚧

If you're working on a project which is not activated on DeepSource, the extension won't pull the baseline issues. You can activate analysis from the DeepSource dashboard to keep cloud and local issues always in sync.

Activating analysis would also get rid on the Single Player Mode.

Accessing Commands

To see all available commands provided by the DeepSource extension, press Cmd + Shift + P (Windows/Linux: Ctrl + Shift + P) to open the VS Code command palette. Type "DeepSource" in the command palette search bar, and you'll see a list of DeepSource-specific commands.

Starting Analysis

DeepSource automatically analyses your currently opened file on every save.

You can also trigger an analysis by selecting the "DeepSource: Start analysis" command from the command palette, or click on the Analyze button on VSCode's status bar.

Viewing Results

Once the analysis is complete and the results are available, you should be able to see the results in the DeepSource side pane within VS Code.

The sidebar has two relevant panels for analysis results:

  • ISSUES IN THIS FILE: Shows all issues detected in the file that is currently open.
  • AFFECTED FILES: Shows all files where DeepSource has detected issues.

In both the panels, you can toggle between existing issues and new issues in your code via the switcher.

  • Baseline issues: Shows all issues in the currently open file that were already present in your file. If you're on your repository's baseline branch that's set on DeepSource, these issues would be identical to those shown on your DeepSource dashboard. In other cases, the existing issues would be the ones detected till the last commit pushed on that branch.
  • New issues: Shows all issues that were newly introduced by the programmer in the current branch. You should probably take care of these before pushing your code!

All lines where DeepSource has detected problems are highlighted using squiggly lines by default.
To see the description for issues raised on a line, simply place your cursor on that line, and click on Explain code lens.
You can also do this using VSCode's Quick Fix menu while the cursor is on the line where issue is raised.

Pull Request and Cloud Analysis

  1. When you open a pull request or commit your code to a branch on an existing pull request, DeepSource will automatically schedule a cloud analysis run.
  2. After your pull request is merged, all "New issues" found in the branch will transfer to "Existing issues" in DeepSource cloud and your IDE.

Extension Settings

Configuring issue types to raise issues on

You can configure the issue categories for which you want DeepSource to raise issues on in your IDE.

  1. Click on Configure issue types... in the settings panel
  2. Select the issue categories you want to see issues for and click OK

Supported Analyzers

The IDE Extension only supports analysis for the following analyzers at the moment:

  1. Java
  2. JavaScript
  3. Python
  4. C#
  5. PHP
  6. Ruby
  7. Kotlin
  8. Swift
  9. Scala

We are actively working on adding support for rest of the Analyzers available on DeepSource.

IDE access for Enterprise Server

Since IDE Extension is in beta right now, it needs additional configuration for it to be used.
Follow the following steps to enable IDE extension for your team:

  1. Go to your installation's Admin Console

  2. Click on config → Manage Access to DeepSource → Enable beta features

  3. Enable/Disable the beta features and save the configuration.

    Once the configuration is saved, you'd need to redeploy with the updated config. Click on "Go to updated version" to find the version with updated config.

  1. Deploy the newly available version to apply the new configuration.

Once the deployment is successful, all your team members would be able to use IDE Extension in beta features are enabled.

AI-based Autofix

The VS Code extension offers Autofix, a powerful feature that provides automatic suggestions for fixing code issues. This feature utilizes artificial intelligence to intelligently propose code changes — enabling you to review and select the best-fit options that align with your coding style and preferences.

❗️

Autofix utilizes the capabilities of OpenAI's language model, offering automated suggestions. However, it's important to acknowledge that the results may not always be completely accurate, as the feature is currently in an experimental phase.

How to Use Autofix AI

🚧

Autofix workflow uses VSCode's code lens to take action on them. Please make sure you have them enabled in your workspace.

To fix an issue raised by DeepSource, take your cursor to the span where the issue is raised.
Click on Autofix with DeepSource code lens, on top of the line.

If there are multiple issues in the span of your cursor, you'll also be asked to select which one to fix first.



Once done, DeepSource Autofix AI looks at the issue with surrounding context, and gives you a diff to review the fix.
You can accept or discard each suggestion by clicking on the respective buttons in the editor.

While Autofix offers valuable suggestions, it's essential to carefully review the changes before accepting them to ensure they align with the intended functionality of your code.

📘

You can also trigger Autofix using VSCode's Quick Fix menu

❗️

Autofix AI is disabled for all Enterprise plans at the moment.

Support

Your feedback is invaluable in helping us refine and improve the extension further. If you encounter any bugs, hiccups, or have any questions while using the extension, we are here to assist you. Please don't hesitate to reach out for support by visiting app.deepsource.com/support for cloud users, or <HOST_URL>/support if you are on the Enterprise Server. Our dedicated support team will be glad to address your concerns and ensure a smooth experience with DeepSource. We appreciate your collaboration and look forward to hearing from you.