How to exclude files from a project in PhpStorm by pattern? - phpstorm

I'm using PhpStorm 10.0.1. I want to exclude files in directories that match a pattern. I want this exclusion to remove the excluded files from the set of files that PhpStorm uses when - for example - finding duplicate definitions of classes.
I've gotten part of the way through the solution, which involves Scopes:
Open a project in PhpStorm
Go to Settings (File -> Settings)
Navigate to Appearance & Behavior -> Scopes
Create a scope to exclude the appropriate file(s).
Click the + icon
Select either Local or Shared
Give the scope a name
Enter an appropriate pattern
For example, to exclude files in directories that match *-b0*, enter !file:*-b0*/*
Click Exclude Recursively
Verify in the tree view that the appropriate file(s) are excluded.
Click OK.
This is where I'm stuck. I can't find any reference anywhere in the UI to that named scope - except in the settings dialog where I created it.
The documentation is no help:
https://www.jetbrains.com/phpstorm/help/scopes.html - "Scopes" describes how to create scopes but not how to use them
https://www.jetbrains.com/phpstorm/help/configuring-scopes-and-file-colors.html - "Configuring Scopes and File Colors" describes how to color files in a scope differently but not how to apply them to a project
How do I apply that scope to the current project?
(It may be the case that scopes are applied automatically. In that case, the Scopes dialog and the rest of PhpStorm disagree on what is included and what excluded and I'll need to file a bug.)

Scopes can be used in Project tool window - click the Project popup in upper left corner and choose the desired scope. They can only be used for search filtering (in Edit/Find/Find in path dialog), in Inspections profiles, file watchers, etc.
But note that choosing your scope in Project window is just a view option, files excluded from scope are NOT excluded from project - they will still be indexed, used in completion/navigation, etc. If you like to exclude certain files/folders completely, so that they are not included in file index, you need adding them to 'Ignore files and folders' in Settings | Editor | File Types. Folders can also be excluded using Mark directory as/Excluded

I've never heard of the ability to apply a custom scope globally. I believe they can only be used to allow specific components of PhpStorm (like code inspections & find/replace) to operate on a subset of your project's files. Edit: This is not accurate; please see the comments below.
This hacky workaround might just do the trick, if the files you'd like to exclude from your project are never going to change:
(a) Using the pattern you've already identified, create a new custom scope that specifically includes the undesirable files.
(b) Perform a very broad search against that scope (Find in Path > Scope > Custom > Custom Scopes), so that every undesired file is matched. You could potentially search for the text <?php, or use a regular expression like .+
(c) Create a new Favorites list, and add all of the search results to that list.
(d) From the Favorites window, highlight all of the files. Right click them and choose "Mark as plain text". This will prevent PhpStorm from indexing them, so they'll no longer be considered by the IDE's static code analysis.

Related

How to include software in PhpStorm project

I have just started using PhpStorm. In my project I am receiving a lot of undefined variable errors because I am creating a plugin for vBulletin.
I was wondering is there a way to include the main software I am working with in my plugin development, to avoid getting undefined vars, and functions? Kind of how the WordPress plugin development works.
For example I have my projects folder: c://wamp/www/projects/projectname/ and I have vBulletin in c://wamp/www/vb3/
I want to be able to tell PhpStorm "hey the core scripts to this project are here".
As LazyOne said I was able to achieve this using include paths.
Include paths are used for holding third-party code that is used for completion and reference resolution in some functions/methods that use file paths as arguments, for example, require() or include().
Note that the files added via include paths are not meant to be edited within the scope of your project. If you have the existing code that you need to access and modify from within several projects, consider adding it via an additional content root.
Do one of the following:
To configure the include paths for the current project, in the
Settings/Preferences dialog Ctrl+Alt+S, click PHP under Languages &
Frameworks.
To configure the include paths that will be applied to all newly
created projects, use the default new project settings (File | New
Projects Settings | Settings for New Projects ).
On the PHP page that opens, configure the list of include paths on the Include path tab:
Use Add and Remove to add and remove paths.
Use Move up and Move down to reorder the items in the list.
Click the Sort Alphabetically button to sort the paths alphabetically in the ascending order.

How to attach a project without mixing class declarations in PhpStorm?

I like PhpStorm's ability to attach multiple projects to the current window:
I've noticed, however, that all classes declared in both projects are available in both projects, which can lead to duplicate declarations:
I understand how this can be useful at times, however I'd like to attach projects just to navigate easily between them (I prefer this to switching windows), while keeping them separate as if they were in separate windows.
Is this possible?
Currently IDE does not have "scoped indexing" that may be able to resolve this. Right now you would need to exclude such duplicate files or tell IDE to not to treat them as PHP so they do not get indexed as such.
Your current options:
Use Mark Directory As | Excluded via context menu in Project View panel (or manually via Settings (Preferences on macOS) | Directories) for a folder(s) from additional project.
Mark individual files as Plain Text via context menu in Project View panel. The downside: such "marking" is IDE-wide as far as I know, so the same file path will be excluded in another project as well.
Any other exclusion mechanic that is currently available (e.g. Settings (Preferences on macOS) | Editor | File Types | Ignore files and folders -- global as well and based on file name only and file will be completely ignored from all operations... so not really acceptable for your case).
Consider watching after https://youtrack.jetbrains.com/issue/WI-17646 (star/vote/comment) and related tickets to get notified on any progress.
If they are the same classes, have you thought about making a composer package for them? Would be easier to manage it all I think.

PhpStorm searching in project tool window

I'm using PhpStorm 10.0.4
When I start typing characters in project tool window it searchs for files containing typed text.
Is it possible to change this behavior so only files that begins with typed text would be matched?
Is it possible to change this behavior so only files that begins with typed text would be matched?
AFAIK no. There are no GUI settings for this at all.
Plus, this Speed Search is used in many places/tool windows and search logic is the same.
P.S. If you need to search for files .. why not try more appropriate (in general sense) Navigate | File... instead?
Speed Search only finds items in already expanded nodes (as it's a basic search on already displayed text) .. but Navigate | File... will look for files everywhere in the project.
It's not possible directly but you can create and use a scope for that.
Open Settings and go the Appearance & Behaviour -> Scopes. Create a new scope, give it a name (let's say "My Files") and put file:*/c* in the Pattern edit box.
In the big list of files under the Pattern edit box you can preview its effects. The files that are included in the scope are colored in green, the directories that contain included files are colored in blue.
This simple pattern selects only the files whose name start with c, in all directories. You can use slightly more complex filters using wild cards, include or exclude entire directories etc. With a little practice you can create filters that match usual needs pretty well.
When you are pleased with the scope definition, close the Settings box and go back to the Project view. Click on the arrow next to Project and you'll get a list of views of the project files. All the scopes you created should be there. Select "My Files" and only the files (and directories) included in that scope will be displayed in the Project view.
It is not a dynamic filter, you have to work a little to set it up, but it is useful when you work on large projects, with thousands of files, and you need to hide the files not important for your task.

How to say to PhpStorm/WebStorm where the including file resides?

Any web project consists of lots of partials that are included into the main file. Very often IDE (PhpStorm for my case) doesn’t know where the including partial resides. The thing is sometimes we use absolute path (e.g. in AngularJS to specify where views’ or directive’s templates reside) and relative path in preprocessors’ sources (jade, stylus, coffee, etc.). And all these files can be stored somewhere in the folder structure.
Therefore very often you can’t to open the including file right from the main file using Ctrl+B.
I think there is a way to tell IDE where this file actually resides. Does anybody know how to cope with it?
If there is no way, I suppose we should ask the developer to solve it somehow.
Depending on the particular framework in which you're developing, a PhpStorm plugin might exist to make CTRL+B navigation possible. For instance, using the Symfony plugin (installed via Settings > Plugins), CTRL+B navigation into a partial template becomes possible in code like this:
return $this->render('hello/world/index.html.twig');
If a plugin is not available, try the following steps. It's not a perfect solution, but it's better than nothing! It's also extremely quick once you get the hang of it.
With your cursor inside the string containing the path and filename, use the 'Extend Selection' keyboard shortcut until the entire string is highlighted (excluding any wrapping single/double quotes). If you don't currently have the 'Extend Selection' action mapped, you can do so via Settings > Keymap.
Immediately use the 'Navigate to File' shortcut (CTRL+SHIFT+N) to search for all files matching the path/filename contained in the string you previously highlighted.
A dropdown box will appear containing all matching files. Find the proper one and open it using ENTER.

PhpStorm Ignore files/directories in TODO feature

Is it possible to exclude certain files from the TODO function in PhpStorm? For example, I'm using the highcharts javascript library. I don't want to see the few dozen or so TODO's they have marked mixed in with my own. I don't want to exclude this directory, because I still want to be able to view the files in a convenient manner.
In File > Settings > Scope add a new scope and make sure the files you like are green.
Open TODO Tab View > Tool Windows > TODO (Alt + 6)
In the top of TODOs click on Scope Based
Below select your new scope from step 1 below Custom Local Scopes
Yes, you can -- via custom scope that would include all but unwanted files/folders (Settings | Scopes) and then just choose it in TODO window.
Check these articles for details:
http://blog.jetbrains.com/webide/2012/10/managing-todo/
http://confluence.jetbrains.com/display/PhpStorm/Working+with+todo+comments+and+the+todo+tool+window
P.S.
This functionality is available since v6 only.
For libraries, there is a one click solution as I have just found out.
You can use the "External Libraries" feature to include the specific library folder, after which PHPStorm / IDEA will mark the folder as a library home and exclude it from inspection.
Note that you can include folders inside your project directroy, even though it's called "External" Libraries.
To exclude code (usually composer dependencies) from analysis.
Right click on desired folder
Click 'Mark Directory As'
Click 'Excluded'
Screenshot example below: