This includes invocations of the class, import statements, and more. The second opens up the find panel, where you can see all the usages of the class in a tree view. The first and last will popup a window listing all of the usages, where we can click one to be taken to it. To do that, we can either cmd or ctrl click the class’ name, use alt+f7, or alt+shift+f7. Say that we want to find the usages for the class in the code snippet above. PhpStorm comes built-in with a laser-focused strategy for helping us out. Powerful as they are, these approaches are broader, more general ways of searching. Sometimes you need to know where a class or function was used, but to use a file search, or command-line grep would perhaps take to long. Let’s now finish up by making use of a navigation option which has saved me countless time, finding usages. To do so, cmd or ctrl click the function’s name to be taken to its parent’s implementation. Say you’d overridden a method, when you created a class which inherited from another and you need to see what the parent method does, even if for no other reason than jogging your memory. Since I’ve shown all of the various ways (including keyboard, menu, and mouse), I’m just going to focus on the mouse for this example. Navigating to a parent method is rather similar. After doing so, you’ll be move to the class’, specifically in to the constructor, if one is defined. Say that you were working with the following code snippet, and you wanted to have a look at the RedirectResponse object.Ĭlass UserAuthenticationMiddleware Īs with function navigation, you could either cmd+click or ctrl+click the class’ name, or move the cursor in to the class’ name and click cmd+b or ctrl+b. You can also use the symbol popup as well, as both function and class names are symbols. As the list starts to populate, based on the text you are entering, click the one that is the correct match.Īs with function navigation, you’ll be taken to the class, where the caret (or cursor) will be placed at the top of the file. There, as before, start typing in the name of the class which you want to navigate to. Needless to say, it works quite similarly.Īssuming that you know the class’ name, or perhaps even aren’t sure, but have a vague idea of what it’s called, use the keyboard shortcut cmd+o or ctrl+o, which will open a mini popup similar to the function, or symbol, mini popup. Now that we’ve navigated to a function definition, what about navigating to a class definition. Regardless of which approach you take, if PhpStorm’s index is up to date, it will move you to the function’s definition, where you can find out all that you need. You may end up, inadvertently, navigating to the wrong place. Taking this approach will have PhpStorm find any definition that matches the criteria you supply. Note: With this approach is that you will have to ensure that the option you pick from the matching list is the one that you want to view. Regardless of whether you’re in a segment of code that makes a call to the method, or have no files open, use the keyboard shortcut alt+cmd+o or alt+ctrl+o which will open a mini popup, where you can enter the function’s name (or symbol name). Then there’s a third way, one that I’m a huge fan of. In a segment of code which makes a call to the function, move the mouse over the function call, and either cmd+click it on a Mac or ctrl+click it on Windows or Linux (assuming that you’re using the standard keyboard mappings).Īlternatively, you can place the cursor somewhere in the function’s name and use the keyboard shortcut cmd+b (Mac) or ctrl+b (Windows/Linux). Navigate to a function can be performed in several different ways.įirstly, let’s see how to do it with the mouse. Navigating to a function is a very handy thing to do, especially if we’re either not intimately familiar with the function, or are only using it for the first time well that, and if the documentation is rather light on - even non-existent. For right now, let’s get started seeing how to navigate to a function definition. In addition to these, I’m going to show you another kind of navigation, the “show usages” navigation. Whilst there are a range of other navigation types on offer, such as navigating to the previous or next file, type declaration, or Emmet edit point, these are the ones that I do on a regular basis. Specifically, we’re going to see how to perform the following code navigation:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |