Assuming I have this code
<?php
namespace App\Traits;
use App\Something\Class1;
use App\Something\Class2;
use App\Something\Class3;
trait Helpers {
public function someThingCool( $someVar) {
return $this->checkCoolness( $someVar );
}
}
is there some way I can easily determine and locate where that checkCoolness method originally define without going through each of inherited class?
Use Go to Definition in the context menu
Right click on a desired function and click on go to definition
Setting shortcut.
Press ctrl+shift+p and type in keyboard-shortcuts
Type in go to definition in the search bar
Set desired keybinding to Go to Definition. Say ctrl + B
Now use your keybinding (shortcut) to access the definition of checkCoolness click on checkCoolness and press ctrl + B
Related
--- edit
Let's say that I have the following scenario in vscode:
I have 3 open files, with vscode showing two files at once.
on the left I have 2 tabs: a.js, in foreground, with
import { b } from './b';
import { c } from './c';
b();
c();
and b.js, with
export function b() {
// ...
}
and on the right I have c.js, with
export function c() {
// ...
}
My goal is:
starting from a.js as current focused editor
to have a shortcut - ideally ctrl-click - that
when I click on b() takes the tab with b.js in foreground and focuses on the function b() { definition
when I click on c(), move the focus on the right side, with c.js in foreground, and focuses on the function c() { definition.
keep in mind that I DO NOT want to use different shortcuts. This is a simplified example (normally I have multiple tabs AND multiple columns opened) but normally I don't know where the target is, and definitely I don't want the same file opened multiple times.
Is there a way to get it?
--- original
In vscode, according to https://code.visualstudio.com/docs/editor/editingevolved#_go-to-definition
You can jump to the definition with Ctrl+Click or open the definition to the side with Ctrl+Alt+Click.
Now, I use the side panel a lot, and sometimes the "target" where the definition is, is in another side, and sometimes is a different tab in the same side on where I am now.
If I do the appropriate choice I can go directly to the already opened buffer. If I choose the "wrong" shortcut a new buffer of the same file is opened.
Is there a way to make the "go to definition" smart? I just want to always go to the already opened file (if is available).
You should head to VS Code's settings and select the Reveal If Open option.
You'll be able to find it in the Workbench --> Editor Management section.
Is it possible autocomplete in Eclipse Java project. Something like I type:
public static void clr()
then press something and get:
public static void clr()
{
}
Alt+/ not working in this case.
In your situation, I don't think you will get any shorter than just typing { and Enter.
Alternatively, you could use the template for public_static_method, i.e. start typing pub..., hit Ctrl+Space, select the template (just press down once and then Enter), type in the method's return type and name and then Enter again to get straight to the body.
You can also go to Preferences -> Java -> Editor -> Templates to adapt that template to your own needs (give it a shorter name, or move the { to a separate line) or define your own ones.
Often when I'm writing code I forget to surround a section of code with a method. For example, when printing an array, I realize that I forgot to pass the array into Arrays.toString().
String[] foo(){
return new String[3];
}
main() {
System.out.println(foo());
}
Is there a way in Eclipse that I can select foo() and then use auto complete or something to surround it with Arrays.toString()? So I want to end up with this:
main() {
System.out.println(Arrays.toString(foo()));
}
I know I could use templates, but I would have to make a template for each method I want to use. I'm looking for something like Eclipse's auto complete feature, which knows about every class and method in the build path.
Yes, you could use templates for that:
First, experiment with existing templates:
Go to the source editor and select "foo()".
Open the view General > Templates.
Select some template, for example, Java > toArray and see how it works.
Then, add your own template:
Windows > Preferences > Java > Editor > Templates > New.
I think the right context should be "Java".
Another way of accesing templates is through the content assist: In the source code, in a new line, start typing the first letters of your template, then press [CTRL][SPACE]. A selector will appear with the matching templates. You may find it useful to check the checkbox "Automatically inserted" in the template definition window.
And yet another way to access them is to select a line of code and then Context Menu > Surround With.
A quick way:
Double click or use select enclosing element and its cousins to select the expression you wish to wrap. ctrl-x to temporarily cut it. Type a few characters and ctrl-space to insert your method name and parentheses. Finally, ctrl-v to paste what you just cut.
with templates - under Java Statements: ${method}(${word_selection})${cursor}
You can make a template like the one described by #LittleSanti. If you use a fake template variable for the method name (like ${method} or ${name}) instead of a constant like foo, Eclipse will highlight it and let you paste or type or complete over it. Then when you hit return or tab, it will jump the cursor to the end (the position indicated by ${cursor}
Unfortunately I don't think Eclipse provides a "real" template variable for selecting methods in scope. It would be nice if it would let did completion for you on methods.
Is there a way to show the derived type of something in Intellij's Scala support?
For example if I am fumbling my way through some slick code and want to know what type the "user" val is perhaps by olding down a key and hovering my mouse that would be incredibly usefull.
DB.withSession {
implicit session =>
val user = users.filter(user => user.email === email && user.password === password).first
}
Any idea how to find out the type of "user" in my IDE as easily as possible?
You can:
Make sure the text cursor is within the variable and check the menu View > Type Info for its shortcut. Use that shortcut to display type info. On OS X, it's ctrl-shift-P.
Or set preferences to show the same type info on mouse hover in Preferences > IDE Settings > Scala. Check "Show type info on mouse motion with delay" and change the delay if you want.
Alternatively, instead of just showing type info, you can show the documentation for the type. It will show the type even if there is no scaladoc or javadoc applicable.
Use the Quick Documentation shortcut (seen in View > Quick Documentation) like the type info one. On OS X, it's ctrl-J.
Or set preferences to show quick doc on mouse hover in Preferences > IDE Settings > Editor. Check "Show quick doc on mouse move" and change the delay if you want.
In addition to #CyƤegha approach you can even tell idea to infer the type and add it for you.
On OS X, go on the variable, click alt + enter and you should see this
After you click on it you'll see
val test: String = "dsds"
The short key is at the voice Show Intention Actions.
1) Select the variable or place your cursor within the variable text.
2) Press Ctrl + Q for Windows/ Linux or F1 for macOS.
Select the expression you're interested in, highlight it and use the facility that assigns it to a local variable - Cmd + Alt + V (I think, from memory) on os-x. This will show you the type IntelliJ considers it to be.
There is a nice feature in Visual Studio: you can create special code areas which can be minimized just as class methods in Eclipse are minimized. Like:
#region
//some code
#endregion
Is there a way do make such pleasant feature in Eclipse?
It's called "collapse all", click on the editor view that you want to collapse all your methods in go to
help>
key assist...>
double click "collapse all">, everything is collapsed
Click on ' - (minus)' symbol on the side of the editor, Right click on minus symbol , Go to folding / Collapse All
Keyboard shortcut : Ctrl+Shift+NumbPad_Divide
First check Folding is enable or disable if enabled then you can minimize or collapse code and expand code. You can check Folding through
Folding is configured under Window -> Preferences -> Java -> Editor ->Folding
Please check Enable Folding if its unchecked
Now you can minimize your code
Collapse All (all functions on page) : Ctrl+Shift+NumbPad_Divide
Expand All (all function on page) : Ctrl+Shift+NumbPad_Mulitply
Collapse One function : Ctrl+NumbPad_Minus
Expand One Function : Ctrl+NumbPad_Plus
If you mean by minimizing folding, then I don't think Eclipse has the folding option you want. When I look at the eclipse folding options it tells me that it can fold
Comments
Header Comments
Inner Types
Members
Imports
If you don't mean folding, then I'm sorry for the confusion.
There are some plugins for this, like "Coffee Bytes Java Folding" for Eclipse.
Other IDE like Netbeans as an native equivalent.
It's really IDE dependent in Java, not implemented in the language like in C# for example.
Java Equivalent to #region in c#
Check the second answer
//region MY REGION
code here
//endregion
Heres how I do it:
Create an empty class called Blank
Use this outline for your code:
Blank b = new Blank()
{
public void myCode()
{
/Insert code here/
}
};
b.myCode();