Sensei GUI Overview

The Sensei IntelliJ plugin lets you create searches to match on code implementing a pattern you want to change, and then create code amendment quickfixes to automatically change the code.

This section will walk through the main parts of the GUI and how we can use them.

Sensei Menu

When Sensei has been installed, we will find the Sensei menu under Tools in the IDE.

image1

Recipe Editor

From here we can show the Recipe Editor tool window which will list all the ‘cookbooks’, or lists of recipes, that you have available.

This tool window also allows us to add and remove cookbooks, and change their location.

image2

The checkboxes on this tool window can switch cookbooks on and off. And you can use the Sensei Cookbook tab on the bottom of the screen to navigate back here when needed. You don’t have to use the main Sensei menu.

Manage Recipes

Recipes in the project's .sensei folder have been automatically loaded.

You can manage them to see what recipes are available by clicking the Manage recipes button.

Cookbook Recipe Editor List

Each recipe has configuration with the name and description and warning level which all configure how they are rendered in the IDE when code matches the pattern in the search.

image3

By clicking on a Recipe, you can edit it.

Recipe Editor

The Recipe Editor has four main components.

  • The list of recipes where we can add, delete, and duplicate recipes

  • The General Settings tab where we can configure the recipe

  • Recipe Settings tab where we create the search and matching conditions

  • QuickFix settings where we configure the Quick Fix changes to amend or generate code

image4

General Settings

General Settings is where we primarily configure the:

  • Name and Description, which are shown in the contextual popup when we hover the mouse over a violation in the code.

  • Level, which defines how the matching Recipe is rendered in the IDE

If you configure a recipe as ‘Error’ then the code will typically have a red underline and show as a syntax error, but a Warning will have a light highlighting. Sensei will use the highlighting properties of the IntelliJ 'Error'/'Warning'/'Info' levels by default.

There are other settings but these are for more advanced use and will be covered later in the documentation.

image5

QuickFix Settings

The QuickFix Settings are the QuickFixes which are shown in IntelliJ when you use Alt + Enter or ⌘ Cmd + ↵ Enter to fix the problem.

And you can see at the bottom of the screen a diff view that shows the results of applying a QuickFix.

The recipe shown in the screenshot adds a Logger into the class and the diff view shows the before and after state in the code.

image8

Creating A Recipe

In the code, usually at the point you want to start a search.

Pressing Alt + Enter or ⌘ Cmd + ↵ Enter shows the context menu to create a recipe.

image9

Often we ‘start from scratch’ with an empty recipe.

image10

A recipe can also be created by clicking the + button in the Recipe Editor.

Spotting Issues in the IDE

In the Code

When recipes have been activated, they will be marked in the editor.

The following code shows some ‘errors’ and some ‘warnings’ have been found in the code.

image11

Problem Icons

Issues will also be shown with the Sensei problem icons in the top right corner.

image12

You can click here to fix the problem via the Problems tab.

image13

Applying a Quick Fix

There are many ways to apply a QuickFix.

Using Problems Tab

In the Problems Tab.

Right click on the reported problem and choose “Show Quick Fixes”

image14

Then choose the quick fix from the list.

image15

Contextual Fix

The most common way to fix code is with Alt + Enter or ⌘ Cmd + ↵ Enter where we will see any Intellij suggestions and Sensei quickfixes.

image16

And if you choose the action then the code will be amended.

Fixing Multiple Actions

If there were multiple occurrences in the file then you could fix them all at once.

Pressing Alt + Enter or ⌘ Cmd + ↵ Enter and navigating to the next menu level down on the QuickFix, we find the option to fix all problems in the current source file.

image17