is it possible in IntelliJ Idea to code restrictions in console? When I have simple line:
val height = readLine()?.toDouble()
I would like to limit the possible input format only to #.##, where "#" is a prime number.
Related
I have the following AutoHotkey script sample, notice the code is indented by a single space:
#z::
MsgBox The Win-Z hotkey was pressed.
Gosub MySubroutine
return
MySubroutine:
Sleep 1000
return
I searched through the VS Marketplace but didn't find a usable formatter extension for AHK scripts.
I've configured "editor.tabSize": 2, is there a way to format the code to use the specified tabSize with the VSCode built-in formatter?
It looks like there is an AutoHotKey Plus extension that includes formatting that seems to adhere to the Visual Studio Code built-in formatter setting for the tab size. I set my tab size to two and performed the format shortcut using the extension (Shift + Alt + F):
It seems though that certain keywords, such as return will cling to the margin, presumably because the formatter for the extension interprets this as the standard convention for AHK (in my opinion though, I like the way it looks).
This feature request is tracked here.
Is it possible to create a custom IntelliJ IDEA inspections that detects code matching a certain regex? If so: how?
For example I want to spot places in the code where the key for a lookup in a Map is created inside the square brackets:
val x = myMap[SomeKey(a, b)]
^^^^^^^^^^^^^
I don't ask for "structural search and replace", because that is not available for Kotlin today.
I am currently working on a Java project, and I am finding IntelliJ Idea's code style system to be extreamly frustrating as it refuses to accept the settings that I want to give it. Specifically, I want spaces around various operators unless they're inside a for loop's header. For example, the following code should be output:
for(int x=0;x<10;++x){ // no spaces around operators when they're in a for loop's header
System.out.println(x);
}
int a = 10; //spaces around = when not in a for loop's header
int b = 50;
a = b;
if(a < b){ //an if statement is not a for loop's header
doSomething();
}
In essence, I want IntelliJ to make an exception to normal space rules when in the header of a for loop, removing these spaces. It looks absolutely disgusting to me to have what should be a dense construction filled with superfluous spaces, to the point that it is making me not want to use IntelliJ Idea at all, despite its numerous great features. THis, for example, severely diminishes the utility of its automatic refactoring ability because I need to manually go through and fix its formatting errors after every refactor.
When I look in the code style settings, the "around operators" checkboxes seem to have no mechanism for a different setting inside for loops:
How can I get IntelliJ Idea to format my code correctly?
A script as simple as
println("a")
doesn't produce any output in the Scratch output window. I expect an a to appear in the output window.
I'm using IntelliJ 2019.1.2 CE.
EDIT: Information regarding the expected functionality
According to a question I had asked: IntelliJ Ultimate Kotlin Script REPL skips first printed lines - Scratch Output cut off
It seems to be the case that the REPL wants to output per line, and will only overflow into the bottom area after a certain line length is reached.
In the question I state that I generally add some initial padding so that it always flows into the lower area with something similar to:
repeat(10) { println("BLANK ") }
END EDIT
You have to make sure that Interactive Mode is turned off at the top of the scratch window
This will cause prints to be put into the Scratch Output window.
Be warned, atleast in the version I have of IntelliJ ultimate 2019.1.3, the first 5-9 lines generally dont print so I do something like:
repeat(9) { println("blank") }
If you've defined everything inside of a function, the script won't execute the function automatically - you'll need to explicitly call the function.
You can create your own print, like this:
fun <T> myPrint(x: T) : T = x
then calling e.g.:
myPrint(5)
should show 5 in the result window.
Intellij keeps replacing final static variable names with random strings. I get that this idea comes from code style/best practices etc., but I find this very annoying. How do I disable this?
E.g. if I create this variable:
private static final Logger logger
= LoggerFactory.getLogger(AuthController.class);
As soon as I type "logger" and press space/enter, it replaces the name "logger" with some random string e.g. "asdoiasdk"; in the editor it then looks like:
private static final Logger asdoiasdk
= LoggerFactory.getLogger(AuthController.class);
Screenshots below:
I start adding a private static final variable called "logger" - the screenshot shows that state just after I typed the variable name but haven't added " = " yet:
Then I press space and equals (" = ") and the variable name changes to this random string "jmeecp":
I found out why and after having spent a day on this, I'll add the reason in the hope that some other poor soul will benefit from this. Basically, the issue happens if you are using "Fantasque Sans Mono" as your editor font. I think it doesn't play well with the highlighting applied by IntelliJ for typos. E.g.: in the below example, the word "REQUESTSTART" is a typo and thus highlighted by IntelliJ (this font in this screenshot is "Droid Sans Mono"):
When I change the font to "Fantasque Sans Mono", the issue surfaces:
There is a pattern between the original string the one shown with this font - the ascii code seems to be going back two positions e.g. R->P, E->C and so on. Very interesting.
Edit 2019-04-15: See this thread for the workaround that resolved the issue for me.