How to fold arrays in the editor Android Studio - android-studio

I'm trying to set change the Android Studio editor settings so that when I press format it doesn't place each element in the array in a new line as seen on this screenshot:
Android Studio array
But folds it nicely, like Rider does seen in the following screenshot:
Rider array
Any ideas?

It seems to me the difference is due to languages (Kotlin vs Java), and not IDEs (Android Studio vs Rider). The culprit of your formatting problem is Kotlin's language feature to use arrayOf() function instead of array initializer to create arrays with known list of elements. Elements in arrayOf(...) are considered Function call arguments, so you may want to look at the corresponding setting.
In File -> Settings -> Editor -> Code Style -> Kotlin -> Wrappings and Braces, the default value of Function call arguments is Do not wrap. This means the formatter respects your code and will never add new lines between arguments. Option Wrap if long means if one line exceeds hard wrap limit (default: 120 chars), \n or \n\r will be inserted. I think switching to this option is one thing you can do but wrapping at 120 chars may be too long for arrays. The other options, in my opinion, don't help much in your case.
By comparsion, Java has an extra Array initializer setting in Wrappings and Braces section.
As I have said, the formatter respects your code. Since "one element in one line" doesn't violate your wrapping rule, your code doesn't get reformatted. You can manually edit your code by searching and replacing (CTRL + R on Windows, possibly COMMAND + R on macOS) related lines using regular expressions :-)

Related

Visual Studio Code surround/wrap selected with custom function (Python)

Android Studio Code (and I assume many other great editors) gives the option to select code and wrap either a custom function around or the most commonly used functions. For the custom functions, a window with a text line could appear in which you write the wrapping function.
Is there any comparable solution for Python in Visual Studio Code? It would increase the workflow significantly .
"Hello" -> print("Hello") # Functions with a single parameter are wrapped around the selected text "Hello"
3+10 -> np.random.uniform(3+10,,) # The function is filled as much as possible with selected values
3+10,5,3 -> np.random.uniform(3+10,5,3) # Tuples are inserted directly into the function
The answer to the common question
Visual Studio Code Surround With
brought the answer that it is language dependent and I a solutions for Javascript and for C in VisualCode.

Is there a way to enable interactive search in properties window?

I just started to use Android Studio and wondering if there is a way to search interactively in property window.
I mean like Xcode does. (It's not a properties, though.)
Is there a plugin or configuration for the function like this?
Android Studio actually has a search tool for properties similar to the one in Xcode. But it's implemented in a very unusual and un-intuitive way. Which makes it hard to find.
In Android Studio version 1.5.1, you have to click either on the 'Properties' header or any property-name below the header, and then you need to start typing the property you want, even though there is no text-box or any other indication that your typing will produce any effect.
When you do this, then a text-box appears with the characters you've typed in. And Android Studio highlights all the properties that contain your character sequence. You can then look only at the highlighted properties to find the one you want.
There is no filter like in Xcode, but if you start typing property name the selection will jump to the first match and the rest of the matches will be highlighted.

How to set max line length in Android Studio code editor?

How can I set a maximum length for Android Studio's code editor, or may be set a word wrap?
In my Android Studio, no matter how long a statement I type on a single line, it never automatically goes to the next line, but rather a horizontal scroll bar appears.
When I autoformat using the Ctrl+Alt+L (reference), nothing happens.
My SO or Google search found a lot of material on this for Eclipse, but not for Android Studio.
If you need not a soft wrap,
but actually, brake one long line onto several lines you need:
Go to Preferences(mac) or Settings(windows) -> Editor -> Code style -> Java/Kotlin -> Wrapping and braces (tab) -> Check "Ensure that right margin is not exceeded"
Now try to reformat your code:
press
OPTION (ALT) + CMD + L on your Mac
(or CTRL + ALT + L on PC)
Edit 13.02.19
As noted in comments this option seems not available in settings for Kotlin.
However, there is a workaround to manually add it.
Here is what it takes to make it work:
Export the settings scheme.
Open saved xml file.
Find <codeStyleSettings language="kotlin"> tag (or create)
Add the WRAP_LONG_LINES setting manually:
<codeStyleSettings language="kotlin">
...
<option name="WRAP_LONG_LINES" value="true" />
</codeStyleSettings>
Save edits and and import back the scheme.
Here you go!
MacOS:
Click on Android Studio ( left top corner )
Click Preferences
Type Code Style in search
Click on Code Style
There is a filed right to the 'Hard wrap at' - you can enter needed about of symbols you need
In File | Settings, select "Editor", then "Code Style". There is an option "Wrap when typing reaches right margin".
Edit: Just tried it, and it doesn't seem to work. Anyway, maybe the option "Use soft wrap" in the "General" group is more what you want.
#Solace, actually #Fahim Faysal's answer is quite close to what you need, but since you want to solve the problem no matter how long a statement I type on a single line, it never automatically goes to the next line, 2 more steps you need to follow:
[Step 9] type the max length you prefer at `"Hard wrap at" ()
[Step 10] change "Wrap on typing" from Default: No or No to Yes
With version 4.1.2 and with Dart language you need to go to "File/Settings/Editor/Code Style/Dart" and modify the "Line length" to the preferred number.
In Android Studio:
File->Setting->
Editor->code Style->java->Wrapping and braces(tab:right side)->keep when reformatting->Line break(make unchecked)
You can change the max column width from:
File > Settings > Editor > Code Style > Right Margin (columns)
Android Studio 3.5:
Mac -
Android Studio > Preferences > Editor > CodeStyle > HardWrap at: ____
The existing answers already answer the question in straight forward way. As a different approach you could set the style guide to kotlin style guide code style. Then if you do alt + ctrl + l as you did, you'll see auto wrap as you expected.
Just open the settings, search for kotlin and look for kotlin under code style.
On the top right hand side of the settings window you'll see Set from..., click on it.
Then on predifined style > kotlin style guide
If you'd like to follow the kotlin formatting style this could reduce more effort. For more information: https://developer.android.com/kotlin/style-guide
My Environment:
Ubuntu 18.04
AndroidStudio 3.3.2
My operate:
File -> Settings -> Editor -> Code Style
Scheme -> select Project
Hard wrap at '120'
Apply
To move the grey vertical line, that tells Android Studio where to wrap your code, go to
Settings- Editor- Code Style- Java or Kotlin- Wrapping and Braces- Hard wrap at
and enter the number of characters, where the line should be.
For dart
settings => code style => Dart => Line length
In settings/code style/kotlin/wrapping and braces replace the "do not wrap" values with "wrap if long"
You can change the Hard wrap at param

Any way to surround selection with braces automatically on typing {, using VS2012 and ReSharper 8?

I know I can make a selection and use the ReSharper action-menu to surround with braces, or use one of the many "Surround with..." keyboard shortcuts.
What I am looking for is a way to do the following (aka the laziest possible way):
Select some code
Press {
The selected text is now surrounded with braces.
This works in e.g. Xamarin Studio (for [,{,( braces).
Is there any way to achieve this in Visual Studio, either using built-in functionality or a plugin?
You should be able to write a resharper plugin to do it. You can register a typing assist handler for a particular character (such as '{') by calling ITypingAssistManager.AddTypingHandler. Your handler should look to see if the document has a selection, and modify the document to insert the open and closing character around the selection contents.
The only problem might be precedence - the '{' character will already have a handler for C# documents. Adding another handler will add it to the end of the chain of handlers, and the existing handler might jump in first. In which case, you could register yourself with ITextControlManager.AddTypingHandler, which is what TypingAssistManager does, but it allows specifying a priority, so you can be called before TypingAssistManager.
As ever, point dotPeek at the ReSharper bin folder and start spelunking for usages of AddTypingHandler, or look at the implementation of TypingAssistManager.

Tab behavior Resharper Intellisense Options

A product like Resharper has many settings, and I can't seem to find the right settings to get the exact behavior I desire from it.
The behavior I am trying to change is this:
Suppose the endresult I want is
but the line currently is
As you expect I start typing:
and after a tab I get this
but I wanted it to become
Does anyone know how I can change the Resharper settings in such a manner that my desired behavior is realized?
Thank you.
EDIT: Note that tab does perform the desired behavior in the default VS Intellisense.
In this particular case, here's what you should do:
Go to ReSharper > Options > Environment > IntelliSense > IntelliSense Behavior, and set Automatically insert parentheses after completion to Opening only.
Now, with the caret right before SomeMethod(), type in Math.Ab, and complete Abs with Enter, as correctly suggested by Rob H. You'll end up with Math.Abs(SomeMethod();
Finally, press Ctrl+Shift+Enter to invoke the Complete Statement, which in this case will insert the required parenthesis at the end of the statement, and put the caret on the next line.
Keep in mind though that this might not be the optimal solution provided that you probably have plenty of other usages of code completion that could conflict with this kind of settings change.
If that kind of similar code modification is required in multiple places, you should possibly create a search and replace pattern instead.
Hitting Enter instead of Tab will insert without overwriting, although you then end up with
Math.Abs()SomeMethod();

Resources