I want to define a live template in IntelliJ. Unfortunatley I cannot use any variables and the "Edit Variables" buttons remains disabled for new templates. Any ideas how to get variable substitution working?
A variable is needed in the "Template Text" in order for the button to become enabled. The variables should start and end with the "$" as depicted in below picture:
Related
I would like to add some other options, like "PHP Enum" or "PHP Interface" directly to this menu. Also, I would like to put PHP-related options first. It is possible tu customize this in PhpStorm? I'm using last version (2022.3.2) with the new UI enabled.
I tried using Appearance & Behaviour -> Menus & Toolbars but that didn't work for me.
Do you know that you can use the universal PHP Class entry and just change the type of the object (and therefore the file template) there? That can be done right away when typing the file or class name -- just use Arrow Up / Down keys:
(GREEN rectangle area is where that Up / Down key will work; RED rectangle shows my custom file templates)
P.S. The template for PHP Enums is also there, it just the screenshot was taken in a project with PHP 8.0 language level (need 8.1 for enums to appear).
P.P.S. The IDE will remember the last used template when you invoke this dialog again.
https://www.jetbrains.com/help/phpstorm/creating-php-classes.html
You can add new entries to this menu by creating custom File Templates at Settings/Preferences | Editor | File and Code Templates
https://www.jetbrains.com/help/phpstorm/settings-file-and-code-templates.html
Here are my test custom file templates:
And this is how they appear in that menu:
Customizing this menu (removing items, changing their order)
This is not possible at the moment. https://youtrack.jetbrains.com/issue/IDEA-143090 -- watch this ticket (star/vote/comment) to get notified with any progress.
Somehow I did something to make IntelliJ indicate a number of usages for each variable on a class. Text such as "1 usage" appears above each variable declaration.
How can I turn this off?
See the Show hints section of Code Vision in Preferences/Settings under Editor > Java. See documentation.
You may uncheck the Usages item as it seen in the screenshot.
IntelliJ 2020.2 gains a new third checkbox, Broken usages, along with the Usages & Inheritors items.
Intellij 2022.2 reorganized the inlay hints preferences, so the option is in a different place:
with ctrl-alt-L I can format the code of a class which works fine.
Is there also a shortcut to automatically sort codelines so the variables comes first and methods later ?
The action for this is Rearrange Code in the Code menu. It does not have a shortcut assigned by default, but you can assign one in Settings | Keymap.
When creating a new java class via new -> Java Class while using IntelliJ IDE, a random Dialog started appearing, and I can't find how to disable it.
This is the strange dialog that started showing, a sort of a wizard. Clicking the help button get's me There is no help for this dialog message.
How can I disable this window in the Intellij IDEA?
I too had the same problem, the exact same dialog. In my case, it actually ended up not being a bug, but IJ acting properly (kinda).
TL;DR: The template code for creating a "Class" object got automagically changed after an IJ update so that it would prompt for answers from the coder when creating a new class file. Changing it back in "Settings/File and Code Templates" to the default template code removes the problem, as the default template code does not use any variables that are prompted for upon class object creation (ex.: ${IMPORT_BLOCK}).
Long version ...
Bring up the Settings dialog for IJ, and in the search field type "template", and then select the "File and Code Templates" option. You'll see on the right side of the dialog the "Editor > File and Code Templates" area. If you select "Class" from the list of template types, to the right of that list of template types you'll see the template used when you create a class ...
Now I don't know why, but after a particular IJ update some months back, via their Toolbox app, the default template text/code was different, so that it looked like this ...
... and that latter template code/text caused the second dialog to appear that you see.
To fix the problem, highlight the "Class" template from the list, then click on the "Reset to Default" button that appears below the Files/Includes/Code/Other tabs (looks like a piece of paper with a 180 degree curving arrow on top of it), so that the template text goes back to what I have showing in the first screenshot, and then select the OK button.
Assuming your "default" template for the Class template is not corrupted/bad, you should no longer see the dialog that you asked about.
Go to Settings/File and Code Templates -> class and change it to:
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} {
}
You can also try hitting the reset to default button, as Adrian Romanelli suggested.
I have defined a local variable
local tSuppressLines
I would like to make sure that local variables are checked so that if I have a typo like
if not tSuppessLines then
-- do something
end if
I get a warning.
Yes, switch on "strict compilation mode" under "script editor" in preferences.
When in the script editor, there is also an item under the "Edit" menu, "Variable Checking", which toggles the same setting, but doesn't make the change persistent - on next launching the IDE, the value set in preferences will be restored.
This can be useful because sometimes you need to edit a script in which variables haven't been consistently declared (and literals haven't been quoted); and don't have time to make and test those changes. So you can temporarily toggle this checking off; and even if you forget to set it back, the corruption won't spread too far.
(This is an improvement on previous behaviour - before version 6, the menu item toggled the preference item, and vice versa)