简体   繁体   中英

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:

  • 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:

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 Settings | Editor | File Types 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM