Sensei GUI Overview =================== This section will walk through the main parts of the GUI and how we can use them. For more detailed information, please visit :doc:`../guiref`. .. contents:: Sensei Menu ----------- When Sensei has been installed, we will find the Sensei menu under Tools in the IDE. |image1| Cookbook Manager ---------------- The Cookbook Manager tool window, which can be opened from the Sensei Menu, lists all the cookbooks that you have available. This tool window also allows us to add, remove and edit cookbooks. |image2| The checkboxes in the list can switch cookbooks on and off. 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. Recipe Editor ------------- The Recipe Editor has five main components. - The list of recipes where we can add, delete, and duplicate recipes - The Metadata tab where we can configure the recipe - Search tab where we create the search and matching conditions - Fix tab where we configure the Quick Fix changes to amend or generate code - A documentation tab where additional information about the recipe can be stored |image4| List of Recipes --------------- The list of recipes on the left side of the recipe editor provides an overview of which recipes are present in the cookbook that we are currently editing. At the top of the list several controls are present to add, remove, duplicate, import and export recipes. The list itself displays any folders present in the cookbook along with the recipes present in those folders. |image3| By clicking on a Recipe, you can edit it. .. _recipe-editor-1: Metadata tab ------------ The metadata tab 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| Search tab ---------- The search tab contains the search configuration. This is the search we perform in the code to match coding patterns. In this example the search looks for uses of the equals operator ``==``. The matches are highlighted in the code itself. |image6| Fix tab ------- The fix tab contains the configuration for the Quick Fixes. These are shown in IntelliJ when you use :kbd:`Alt+Enter` or :kbd:`⌘↵` to fix the problem. And you can see at the bottom of the screen a diff view that shows the results of applying a Quick Fix. The recipe shown in the screenshot rewrites the operator we matched in the search tab to ``equals``. It reuses both the left and right operands of the matched operator using moustache syntax. Which variables are available to insert can be seen by clicking `Show variables`. The diff view shows the before and after state in the code. |image7| Documentation tab ----------------- The documentation tab contains the detailed description of the recipe. |image8| Creating a Recipe ----------------- In the code, at the point you want to start a search, pressing :kbd:`Alt+Enter` or :kbd:`⌘↵` shows the context menu that has the :menuselection:`Create a new recipe` option. |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| .. note:: You can customize the color scheme for Sensei markings by navigating to `Preferences` > `Editor` > `Color Scheme` > `General` and editing the color schemes under `Errors and Warnings` in the tree view. |tip-colors| 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 Quick Fix. Using the 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 :kbd:`Alt+Enter` or :kbd:`⌘↵` where we will see any IntelliJ suggestions and Sensei quick fixes. |image16| And if you choose the action then the code will be amended. Fixing Multiple Occurrences ~~~~~~~~~~~~~~~~~~~~~~~~~~~ If there are multiple occurrences of an issue in the same file, then you can fix them all at once. #. Position the caret on one of the issues to be fixed #. Press :kbd:`Alt+Enter` or :kbd:`⌘↵` to bring up the Quick Fix pop-up #. Navigate to the next menu level down on the Quick Fix #. Use the :menuselection:`Fix all 'xxx' problems in file` option |image17| .. |image1| image:: images/gui-overview/sensei-menu.png .. |image2| image:: images/gui-overview/cookbook-manager.png .. |image3| image:: images/gui-overview/recipe-editor-list.png :class: noshadow .. |image4| image:: images/gui-overview/recipe-editor-full.png :class: noshadow .. |image5| image:: images/gui-overview/recipe-editor-metadata.png :class: noshadow .. |image6| image:: images/gui-overview/recipe-editor-search.png :class: noshadow .. |image7| image:: images/gui-overview/recipe-editor-fix.png :class: noshadow .. |image8| image:: images/gui-overview/recipe-editor-documentation.png :class: noshadow .. |image9| image:: images/gui-overview/create-new-recipe.png .. |image10| image:: images/gui-overview/create-new-recipe-start-from-scratch.png .. |image11| image:: images/gui-overview/shown-as-errors-and-warnings.png .. |image12| image:: images/gui-overview/problem-icons.png .. |image13| image:: images/gui-overview/problems-tab.png .. |image14| image:: images/gui-overview/show-quick-fixes.png .. |image15| image:: images/gui-overview/choose-quick-fixes.png .. |image16| image:: images/gui-overview/alt-enter-context-menu.png .. |image17| image:: images/gui-overview/fix-all-context-menu.png .. |tip-colors| image:: images/gui-overview/color_scheme_tip.png :class: noshadow