PhpStorm IDE。折叠 custom/debug 代码
PhpStorm IDE. Collapse custom/debug code
是否可以在 PhpStorm 中折叠自定义代码?
就像您在设置模式中设置:
[START]$this->debugOutput(*)[END]
概念是在开发完成后隐藏调试代码。
在下面的示例中,所有带有 $this->debugOutput
的行都应该被隐藏
class Foo {
public function bar()
{
$x = 1 + 2;
$this->debugOutput($x);
$y = 3 + 3;
$z = 5 + 5;
$this->debugOutput($y);
$this->debugOutput($z);
}
public function debugOutput($msg, $dump = false)
{
if($this->config->debug !== true){
return;
}
@ob_end_flush();
@ob_flush();
@flush();
@ob_start();
if($dump){
var_dump($msg);
} else {
echo $msg . PHP_EOL;
}
}
}
无法通过 settings/matching 模式自动折叠此类代码。
但是你可以用custom folding blocks包围这样的代码——下次打开时会记住折叠状态,如果第一次打开它也会折叠(感谢defaultstate="collapsed"
部分)。
//<editor-fold defaultstate="collapsed" desc="My debug code description">
... debug code here
//</editor-fold>
除此之外:只能通过手动折叠选择(例如进行选择然后 Code | Folding | Fold Selection / Remove region
)——但我不确定它是否会在下一次会话(IDE 重新启动)之前存在,因为不会添加折叠注释。
是否可以在 PhpStorm 中折叠自定义代码? 就像您在设置模式中设置:
[START]$this->debugOutput(*)[END]
概念是在开发完成后隐藏调试代码。
在下面的示例中,所有带有 $this->debugOutput
的行都应该被隐藏
class Foo {
public function bar()
{
$x = 1 + 2;
$this->debugOutput($x);
$y = 3 + 3;
$z = 5 + 5;
$this->debugOutput($y);
$this->debugOutput($z);
}
public function debugOutput($msg, $dump = false)
{
if($this->config->debug !== true){
return;
}
@ob_end_flush();
@ob_flush();
@flush();
@ob_start();
if($dump){
var_dump($msg);
} else {
echo $msg . PHP_EOL;
}
}
}
无法通过 settings/matching 模式自动折叠此类代码。
但是你可以用custom folding blocks包围这样的代码——下次打开时会记住折叠状态,如果第一次打开它也会折叠(感谢defaultstate="collapsed"
部分)。
//<editor-fold defaultstate="collapsed" desc="My debug code description">
... debug code here
//</editor-fold>
除此之外:只能通过手动折叠选择(例如进行选择然后 Code | Folding | Fold Selection / Remove region
)——但我不确定它是否会在下一次会话(IDE 重新启动)之前存在,因为不会添加折叠注释。