Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
finished useful_ide page
Browse files Browse the repository at this point in the history
  • Loading branch information
JR1811 committed Nov 10, 2023
1 parent 3b2317d commit b230086
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 20 deletions.
88 changes: 68 additions & 20 deletions pages/useful-ide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,30 @@ import { Callout } from "nextra/components"
# Using the IDE to the fullest

This page gives useful bits of information, to speed up and ease the workflow of developers. Incorporate them into yours, to your liking.
It may take some time to learn and get used to the shortcuts and other options. You can use this page as a reference for that.

<Callout type="info">It may take some time to learn and get used to the shortcuts and other options. Use this page as a reference to get used to them.</Callout>
<Callout type="info">Key binds in the text are listed as Windows shortcuts.
Refer to the `File > Setings > Keymap` Settings or search for the functionality elsewhere if you are using a different Keyboard layout.</Callout>

## Traversing projects

### Manually

IntelliJ has many different ways of traversing projects. If you have generated Sources using the...
IntelliJ has many different ways of traversing projects. If you have generated sources using the...

```
./gradleW genSources
```

...command in the terminal
or used the `Tasks > fabric > genSources` Gradle Task in the Gradle Window, you can manually go trough the source files of Minecraft in the
or used the `Tasks > fabric > genSources` Gradle Task in the Gradle Window, you can manually go through the source files of Minecraft in the
Project Window's External Libraries.

![Gradle Task](/useful-ide/traversing_01.png)

<Subtitle>Generate Sources using the Gradle Task</Subtitle>

The Minecraft Source code can be found if you look for `net.minecraft`, but also other sources of projects, which are imported using the `build.gradle` file
The Minecraft Source code can be found if you look for `net.minecraft`, but also other sources of projects, libraries and dependencies, which are imported using the `build.gradle` file
are located in there. This method is often used when browsing for assets, tags and other files.

![External Library](/useful-ide/traversing_02.png)
Expand All @@ -45,17 +47,38 @@ or by pressing `Shift` two times again, the search will look not only in your ow

![Search Window](/useful-ide/traversing_03.png)

### Recent Window

Another useful tool in IntelliJ is the `Recent` window. You can open it with the Shortcut `CTRL + E`. In there you can jump to the files, which you have already visited and open tool windows, such as the [`Structure`](useful-ide#structure-of-a-class) or [`Bookmarks`](useful-ide#bookmarks) window.

![Recent window](/useful-ide/traversing_04.png)

## Traversing code

### Jump to Definition / Usage

If you need to check out either the definition or the usage of variables, methods, classes, and other things, you can press `CTRL + Left Click`
or use `Middle Mouse Button` (pressing Mouse wheel) on their name. This way you can avoid long scrolling sessions or a manual
or use `Middle Mouse Button` (pressing mouse wheel) on their name. This way you can avoid long scrolling sessions or a manual
search for a definition which is located in another file.

### Bookmarks

You can bookmark lines of code, files or even opened Editor tabs.
Especially when researching source codes, it can help out to mark spots which you want to find again quickly in the future.

Either right click a file in the `Project` window, an editor tab or the line number in a file.
Creating `Mnemonic Bookmarks` enables you to quickly switch back to those bookmarks using their hotkeys, `CTRL` and the digit, which you have chosen for it.

![set Bookmark](/useful-ide/traversing_05.png)

<Subtitle>Right-click on a line number to set a Bookmark</Subtitle>

It is possible to create multiple Bookmark lists at the same time if you need to separate or order them, in the `Bookmarks` window.
[`Breakpoints`](basic-problem-solving#breakpoint) will also be displayed in there.

![Bookmark window](/useful-ide/traversing_06.png)

<Subtitle>Get an overview over all Bookmarks using the `Bookmarks` window</Subtitle>

## Analyzing classes

Expand Down Expand Up @@ -92,25 +115,53 @@ Displaying parameters should be activated by default. You will automatically get
If you closed them by accident or just moved your cursor to a new place, you can use `CTRL + P` to open them up again.

Methods and classes can have multiple implementations with different parameters (also known as Overloading). This way you can decide on which
implementation you want to use, while writing method the call.
implementation you want to use, while writing the method call.

![Displaying method parameters](/useful-ide/util_02.png)

### Refactoring

Refactoring is the process of restructuring code without changing its functionality. Renaming and Deleting parts of the code safely is a part of that,
but things like extracting parts of the code into separate methods and introducing new variables for repeated code statements are also called "refactoring".

Many IDEs have an extensive tool kit to aid in this process. In IntelliJ simply right click files or parts of the code to get access to the available refactoring tools.

![Refactoring](/useful-ide/refactoring_01.png)

It is especially useful to get used to the `Rename` refactoring tool's key bind, `SHIFT + F6`, since you will rename many things in the future. Using this feature,
every code occurrence of the renamed code will be renamed and will stay functionally the same.

### Search and Replace file content

Sometimes simpler tools are needed to edit code occurrences.

| Key bind | Function |
|--|--|
| `CTRL + F` | Find in current file |
| `CTRL + R` | Replace in current file |
| `CTRL + SHIFT + F` | Find in a bigger scope (can set specific file type mask) |
| `CTRL + SHIFT + R` | Replace in a bigger scope (can set specific file type mask) |

If enabled, all of those tools allow for a more specific pattern matching using "[Regex](https://regex101.com/)" (regular expression).

![Regex-replace](/useful-ide/search-and-replace_01.png)


## Comments

### Prepare Shortcuts

Good code should be easily readable and [self-documenting](https://bytedev.medium.com/code-comment-anti-patterns-and-why-the-comment-you-just-wrote-is-probably-not-needed-919a92cf6758). Picking expressive names for variables, classes and methods can help a lot, but sometimes
comments are neccessary to leave notes and <b>temporarily</b> disable code for testing.
comments are necessary to leave notes or <b>temporarily</b> disable code for testing.

To comment out code faster, open IntelliJ's Settings, look for the `Comment with Line Comment`
and the `Comment with Block Comment` entries, and set their Keybinds to your preferences.
and the `Comment with Block Comment` entries, and set their Key binds to your preferences.

![Keymap settings](/useful-ide/comments_01.png)

<Subtitle>Open IntelliJ Settings (`File > Setings > Keymap`)</Subtitle>

Now you can highlight the neccessary code and use the shortcuts, to comment the section out.
Now you can highlight the necessary code and use the shortcuts, to comment the section out.

```java
// private static final int PROTECTION_BOOTS = 2;
Expand Down Expand Up @@ -158,8 +209,8 @@ If you notice that you are using too many of them, consider refactoring your cod

### TODO and FIXME notes

When working on code it can come in handy to leave notes, on what still needs to be taken care of. Sometimes you may also spot
a potential issue in the code but you don't want to stop focusing on the current problem. In this case use the
When working on code, it can come in handy to leave notes, on what still needs to be taken care of. Sometimes you may also spot
a potential issue in the code, but you don't want to stop focusing on the current problem. In this case, use the
`TODO` or `FIXME` comments.

![TODO and FIXME comments](/useful-ide/comments_03.png)
Expand All @@ -175,7 +226,7 @@ which uses those type of comments.

### Javadocs

A great way of documenting your code is the usage of JavaDoc. JavaDocs not only provide useful infomration for implementation of methods and classes, but are also
A great way of documenting your code is the usage of JavaDoc. JavaDocs not only provide useful information for implementation of methods and classes, but are also
deeply integrated into IntelliJ.

When hovering over method or class names, which have JavaDoc comments added to them, they will display this information in their information window.
Expand All @@ -191,14 +242,11 @@ Minecraft's `ScreenHandler` class has some examples. To toggle the render view,

![JavaDoc editing](/useful-ide/comments_07.png)

## Refactoring Tools

[WIP]
## Optimizing IntelliJ further

### SHIFT + F6
There are many more shortcuts and handy little tricks which would go above the scope of this wiki.
Jetbrains has many good talks and videos about how to further customize your workspace.

[WIP]

### CTRL + SHIFT + R
---

[WIP]
<iframe width="560" height="315" src="https://www.youtube.com/embed/V8lss58zBPI?si=ok_SBjYiD7SjpX5f&amp;start=126" frameborder="500" allow="accelerometer; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
Binary file added public/useful-ide/refactoring_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/useful-ide/search-and-replace_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/useful-ide/traversing_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/useful-ide/traversing_05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/useful-ide/traversing_06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b230086

Please sign in to comment.