Удалить комментарии из файла

4861
Ejaz

Я использую PHPStorm и имею очень основную проблему. Я хочу удалить одиночные / multi / phpdoc комментарии из моих файлов. Я хочу, чтобы этот процесс был одним щелчком мыши и легко отменяемым. Я пробовал просматривать Интернет и справку PHPStorm, но не смог найти ни одной функции, подобной этой.

Может быть плагин PHPStorm, который выполняет эту функцию? Я исчерпал свои ресурсы, пытаясь найти ответ.

Я знаю, что могу использовать поиск с заменой регулярных выражений в PHPStorm и других текстовых редакторах, чтобы добиться этого, но я ищу более или менее удачное решение.

Любая помощь будет оценена.

Спасибо

0

3 ответа на вопрос

6
Ejaz

Since the problem in this question hasn't received any solutions, I; for documentation and readers' help, am going to present the way I currently do it. The ideal solution has to be one-click and do following

  1. remove all comments in one click
  2. restore all comments back in one click

So my less than ideal solution is as follows

Remove all comments
1. use following regexp in find tool to replace all multi-line comments with empty /\*(\*)?(((?!\*/)[\s\S])+)?\*/
2. then use following regexp to replace all single-line comments with empty //.*$

Restore all comments
1. Open VCS > Local History > Show History and restore to the version with comments.

I'm still hoping to find a true one-click solution.

thanks

0
duDE

Take a look at PhpStorm 9.0.0 Help / Commenting and Uncommenting Blocks of Code:

Commenting and uncommenting lines of code

Do one of the following:

On the main menu, choose Code | Comment with Line Comment. Press Ctrl+Slash. 

Commenting and uncommenting blocks of code

To add or remove a block comment, do one of the following:

On the main menu, choose Code | Comment with Block Comment. Press Ctrl+Shift+Slash. 
Это служит другой цели, чем я заявил в вопросе. Я хочу удалить содержимое комментария, которое отличается от раскомментирования блока и его включения в код. Ejaz 8 лет назад 0
0
lena

PHPStorm doesn't come with any predefined functions/plugins for deleting comments. The most obvious solution is regexp replacement. See also https://stackoverflow.com/questions/503871/best-way-to-automatically-remove-comments-from-php-code, https://stackoverflow.com/questions/22819768/removing-php-comments-with-replace-tool-using-regex-in-phpstorm for some hints.

Вот как я сейчас это делаю. Ejaz 8 лет назад 0

Похожие вопросы