PhpStorm typed variable alignment - formatting

I haven't found any good resources for this, so here's the question.
I have the following code:
public function myFunction(
string $name,
int $age
) {}
When I format the code, PhpStorm will align the variables like so:
public function myFunction(
string $name,
int $age
) {}
I want to STOP this behaviour and have it format the code like the first block. Running build #PS-213.7172.28 in case that matters.

If I'm getting this correctly: it is introduced by WI-59669 in PhpStorm 2021.2.3.
Here is a WI-61085 ticket that asks to have such double alignment (by both type and parameter name) optional -- watch it (star/vote/comment) to get notified with any progress.

Related

Kotlin: mark function argument after sanitizing it into a new variable as "do not use this anymore"

To start: this question is already kind of resolved for me. But the discussion might be interesting.
I like code so let's look at this function:
fun foo(path: Path) {
val absPath = path.normalize().absolute() // sanitizing
doSomethingWith(path) // this is unsafe use because path is not sanitized
doSomethingWith(absPath) // this is safe because we are using the sanitized absPath value
}
Kotlin function parameters are always val, therefore we are required to create a new variable if we want to derive from it's value.
We can choose between using a new name or using an old name and annotating it with #Suppress("NAME_SHADOWING") to not get the Name shadowed: ... warning.
I'm looking for something like
fun foo(path: Path) {
val absPath = path.normalize().absolute()
#DoNotUseAnymore path
doSomethingWith(path) // should give a warning/error
doSomethingWith(absPath) // is fine
}
Do you know something like that? Or do you think I'm fiddling around at the wrong end of the equation and should just learn to not feel like doing bad stuff when using the #Suppress-annotation? Since I like to code, this is what I mean:
fun foo(path: Path) {
#Suppress("NAME_SHADOWING")
val path = path.normalize().absolute() // sanitizing
doSomethingWith(path) // there is only one sanitized variable so we are safe
}
In some way this method is the cleanest one... I probably stick to that... Should I publish this question now? Well... maybe :)

IntelliJ IDEA auto insert space after choosing statement from suggested variants

I noticed that every time I made a choice in code completion suggested list I have to manually add a space after every statement, it's annoying. Want to automate this and try to find a solution in settings but nothing.
]
It works just fine here and behaviour depends on where return is used (tested in PhpStorm 2020.1.4 on Windows 10).
1. The space will inserted automatically after return completion in functions where IDE knowns that they can return non empty values, e.g.
where return type is declared via PHPDoc or native PHP type;
based on other/already present non-empty returns in function body.
2. If a function already declare that it will return void then return; will be inserted on completion (notice ; at the end).
3. If no function return type is known in advance (e.g. you are writing first return and no return type declared) or other cases (e.g. return in include file -- a typical case is PHP config files (e.g. Laravel)) then no space will be inserted.
refs: WI-51343, WI-45793, WI-45803.
Here are examples when IDE will insert a space after return keyword completion via completion popup:
A short demo video for one of the cases: https://recordit.co/U90Sx6PPTO
function some1($a)
{
if ($a) {
return 22;
}
ret[COMPLETION]
}
function some2($a): string
{
ret[COMPLETION]
}
/**
* Some func.
*
* #param $a
* #return string
*/
function some3($a)
{
ret[COMPLETION]
}
Here IDE will insert return; (notice ; at the end):
/**
* #param $a
* #return void
*/
function some4($a)
{
ret[COMPLETION]
}
Possible workaround if you ALWAYS want to have a space after return statement: just make custom Live Template that will expand r[TAB] into return [CARET].
For example:

wxDataViewListCtrl and wxVariant

I have a simple setup, a wxDataViewListCtrl, the first column uses wxDataViewCustomRenderer and the second column is just text.
class MyCustomRenderer : public wxDataViewCustomRenderer
I add a line to the wxDataViewListCtrl like this:
wxVector<wxVariant> item;
item.push_back(wxVariant(/*a raw pointer of MyClass goes here*/));
item.push_back(wxVariant("some string goes here"));
m_data_view_list_ctrl->AppendItem(item);
item.clear();
And this is MyClass:
class MyClass final : public wxObject
And this is how my SetValue method looks like:
bool MyCustomRenderer::SetValue(const wxVariant& value)
{
MyClass* temp = static_cast<MyClass*>(value.GetWxObjectPtr());
/*Do stuff with temp here...*/
return true;
}
It worked, now it does not. It fails with the following error:
https://www.dropbox.com/s/acxbzthp3ltadny/wxwidgets.png?dl=0
The only thing I changed is that I updated my static libs of wxWidgets from 3.0.4 to 3.1.2.
Why has it stopped working? What am I missing here?
Please help me :-)
Update
Thank you all for answering. The problem was solved here. In short I needed to change this line like this:
MyCustomRenderer::MyCustomRenderer() : wxDataViewCustomRenderer("void*", wxDATAVIEW_CELL_INERT, wxALIGN_CENTER)
And this one like this:
item.push_back(wxVariant(static_cast<void*>(/*Raw pointer to an instance of MyClass*/)));
I'm not sure which change exactly is responsible for this, but the value, returned by your model for the cell being drawn, is null, so your renderer can't just use it blindly and should check if ( !value.IsNull() ) before doing it (and maybe just return in this case or do whatever is appropriate to show the absence of a value in your case).

differentiate int and double in intellij template

I am defining a custom toString template in IntelliJ. IntelliJ offers a template system based on the Velocity scripting language. Great stuff !
But I am facing a particular issue with it right now. I need to tell the difference between an int field and a double field. Essentially to generate something like (simplified):
public String toString() {
String output = "";
output += "myIntField:" + Util.intDescription(myIntField);
output += "myDblField:" + Util.doubleDescription(myDblField);
return output;
}
For the Integer type it works fine, but I can't seem to get it to work for primitive int.
#if ($member.typeQualifiedName == "java.lang.Integer")
...
#end
#if ($member.typeName == "Integer")
...
#end
I can make constructs with methods like $member.primitive and $member.numeric but none of them makes a distinction between double and int.
The documentation of IntelliJ gives me the impression that I'm at a dead end.
PS: Sure it could be solved, by changing the java code/api, which can simplify the required format for the toString() method. But that's really a last resort for me.
#elseif ( $member.type == 'double' )
output += "myDoubleField:" + Util.doubleDescription(myDoubleField);
#elseif ( $member.type == 'int' )
output += "myIntField:" + Util.intDescription(myIntField);
For whatever reason the $member.isDouble property isn't accessible for me. It's not listed in IntelliJ's docs, the VTL Reference or the VTL User Guide, nor is .type.
I first printed out $member and it listed all the properties on this object. I'm not sure why it listed isDouble though.

Blockly How to create a Variable to the workspace (developer variable)

I want to create a Developer Variable to the workspace in Blockly, but I cannot find the necessary function/method.
I do not want to create the variable over a button. The variable should be included even if there is no block in the workspace.
With these two functions I can get the already created variables:
var variables = workspace.getAllVariables();
var dev_var = Blockly.Variables.allDeveloperVariables(workspace);
But what is the setting function?
Developer variables are variables that will never be visible to the user, but will exist in the generated code. If that's what you're looking for: there's no API for it, but here are some things you can do.
If you want to reserve the name so that users can't accidentally override your variable, call yourGenerator.addReservedWords('var1,var2,...'). You can initialize the variable in your wrapper code.
If you really want Blockly to both reserve and declare the variable for you, you could override the init function on your generator.
On the other hand, if what you want is a user-visible variable that always shows up in the toolbox, without the user creating it, you should call yourWorkspace.createVariable('variable_name').
The unit test blocks all assume that the variable unittestResults exists and can be written to. To indicate this, the block definition includes the function getDeveloperVars, which returns an array of strings. Each string is a variable name.Follow this issue in gtihub
Blockly.Blocks['unittest_fail'] = {
// Always assert an error.
init: function() {
this.setColour(65);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.appendDummyInput()
.appendField(new Blockly.FieldTextInput('test name'), 'MESSAGE')
.appendField('fail');
this.setTooltip('Records an error.');
},
getDeveloperVars: function() {
return ['unittestResults'];
}
};
LINK : https://github.com/google/blockly/issues/1535