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.
Contents
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.
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.
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
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.
Recipe Settings - Search¶
The ‘Recipe Settings’ contains the search configuration.
This is the search we perform in the code to match coding patterns.
In this example the search is for any annotation on a method which are a Junit 5 Test annotation.
And you can see the annotations in the code have been highlighted in the code itself.
If the annotation type was changed then the code would not match, so we can visually see if our searches would match for the code we are working with.
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.
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.
Often we ‘start from scratch’ with an empty recipe.
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.
Problem Icons¶
Issues will also be shown with the Sensei problem icons in the top right corner.
You can click here to fix the problem via the Problems tab.
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”
Then choose the quick fix from the list.
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.
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.