WalterGR
WalterGR

Reputation: 352

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

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:

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:

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.)

Upvotes: 5

Views: 4344

Answers (2)

lena
lena

Reputation: 93868

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

Upvotes: 4

Nate
Nate

Reputation: 1482

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.

Upvotes: 0

Related Questions