简体   繁体   English

如何通过模式从PhpStorm中的项目中排除文件?

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

I'm using PhpStorm 10.0.1. 我正在使用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. 我希望此排除从PhpStorm使用的文件集中删除被排除的文件,例如,当找到类的重复定义时。

I've gotten part of the way through the solution, which involves Scopes: 在解决方案中,我已经涉及到范围:

  • Open a project in PhpStorm 在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*/* 例如,要排除与*-b0*匹配的目录中的!file:*-b0*/* ,请输入!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.) (可能是自动应用范围的情况。在这种情况下,“范围”对话框和PhpStorm的其余部分在包含的内容和排除的内容上存在分歧,因此我需要提交错误。)

Scopes can be used in Project tool window - click the Project popup in upper left corner and choose the desired scope. 范围可以在“项目”工具窗口中使用-单击左上角的“ Project弹出窗口,然后选择所需的范围。 They can only be used for search filtering (in Edit/Find/Find in path dialog), in Inspections profiles, file watchers, etc. 它们只能用于检查过滤(在“ Edit/Find/Find in path对话框中的“ Edit/Find/Find in path ),“检查”配置文件,文件监视程序等中。

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 TypesSettings | Editor | File Types ”中的“忽略文件和文件夹”中Settings | Editor | File Types Settings | Editor | File Types Settings | Editor | File Types . Settings | Editor | File Types Folders can also be excluded using Mark directory as/Excluded 也可以使用“ 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. 我相信它们只能用于允许PhpStorm的 特定组件(例如代码检查和查找/替换)在项目文件的子集上运行。 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. (a)使用您已经确定的模式,创建一个新的自定义范围,专门包含不需要的文件。

(b) Perform a very broad search against that scope ( Find in Path > Scope > Custom > Custom Scopes ), so that every undesired file is matched. (b)针对该范围执行非常广泛的搜索( Find in Path > Scope > Custom > Custom Scopes ),以便匹配每个不需要的文件。 You could potentially search for the text <?php , or use a regular expression like .+ 您可以搜索文本<?php ,或使用正则表达式,例如.+

(c) Create a new Favorites list, and add all of the search results to that list. (c)创建一个新的收藏夹列表,并将所有搜索结果添加到该列表。

(d) From the Favorites window, highlight all of the files. (d)在“收藏夹”窗口中,突出显示所有文件。 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. 这将防止PhpStorm为它们建立索引,因此IDE的静态代码分析将不再考虑它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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