Skip to content

Code Reviews in IDE

In your IDE Sourcery can provide the same in-depth code reviews that you get on pull requests in GitHub and GitLab. You can also chat with Sourcery's coding assistant and use it to help understand your codebase.

For information on setting up Sourcery in your IDE, please follow our docs for:

Triggering a Review

Open the Sourcery sidebar in your IDE and click on the Review tab in the top left (if it's not already selected).

Sourcery can review the code in a few different ways:

  • Review the current file
  • Compare your current changes with HEAD
  • Compare your current changes with a specific branch

In order to compare the changes with a git branch your project must be connected to a Git repo.

Selecting a review option

Once you've selected what you want Sourcery to review click the Review My Code button to trigger a review.

Sourcery will immediately start to provide a summary of the changes or file (depending on the review type selected) and will then generate the detailed review in the background

Review summary

Once Sourcery has completed the full review it will provide you with an overall review comment, highlighting the areas where it found specific issues. Then it will provide you each individual comment and will underline the relevant sections of the code where the issues occur.

You can hover over any section of code Sourcery has flagged to see the detailed comments from Sourcery.

Hovering over an issue

Applying Suggested Fixes & Resolving Comments

If a Sourcery comment has a Suggested Fix you can hover over the fix and click the Apply Changes icon in the top right to have Sourcery make the change.

Applying a Sourcery change

If you have addressed a change or want to ignore a comment you can click the Resolve button. This will remove the underlining from your code and collapse the suggestion in the Review menu. You can expand the comment to Unresolve it if you decide you want to address it.

Unresolve an issue

Additional Functionality: Chat and Recipes

In addition to code reviews, Sourcery also has a chat option in your IDE. Click on the Sourcery sidebar to bring up the Sourcery tab and select Chat from the top of the page.

You can then talk to Sourcery.

Sourcery's coding assistant

Applying Code Changes

Sourcery's coding assistant provides code changes with a Search/Replace style code suggestion. To apply the changes hover over the suggested change and click the "Apply Change" icon in the top right of the assistant to directly apply the fix to the correct section of code.

Applying a change with Sourcery

Selecting Context for Chat

By default Sourcery will look only at the current open file as context for the chat. If you want to expand the context to all files you currently have open you can navigate to the chat window, select the context dropdown on the bottom right, and choose All Open Files.

Selecting the correct context

Recipes

Recipes are quick commands to tell Sourcery to interact with your codebase in a particular way.

The currently available recipes are:

  • Generate Diagram - Sourcery creates a mermaid diagram of the selected section of code or the current file. You can provide detailed instructions about what type of diagram should be created.

  • Generate Tests - Creates unit tests for the selected function or class. You'll have to manually add these into the correct location for the tests.

  • Generate Docstrings - Creates docstrings for the selected function or class.

  • Explain Code - Sourcery provides a detailed explanation of what the given section of code does.

Selecting a Recipe