如何在Visual Studio 2010中自动折叠某些评论?
-
01-10-2019 - |
题
我的同事使用 厌恶 常规留下评论的文本编辑器遍布整个代码。不用说,这让我很生气。评论块看起来像这样:
/* EasyCODE ) */
/* EasyCODE ( 0
WndProc */
/* EasyCODE F */
即他们都从 EasyCODE
其中大多数跨越了几行。值得庆幸的是,VS2010可以崩溃的评论块,所以我不会 不得不 一直见他们。
有没有办法自动化的?一种自动崩溃的方式 EasyCODE
块将是神灵!
解决方案
这是一个应该做的宏。有一些怪异的EasyCode评论,它不会捕获,但大多是解决问题。
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a ' remove for VS2008
Imports EnvDTE100 ' remove for VS2008
Imports System.Diagnostics
Imports System.Collections.Generic
Public Module HideEasyCODEComments
''
'' Collapse all EasyCODE comment blocks
''
Sub ToggleSummaryCommentsOutlineExpansion()
If (DTE.ActiveDocument Is Nothing) Then
Exit Sub
End If
If (DTE.UndoContext.IsOpen) Then
DTE.UndoContext.Close()
End If
DTE.SuppressUI = True
Try
DTE.UndoContext.Open("ToggleSummaryCommentsOutline")
Catch
End Try
Dim objSelection As TextSelection = DTE.ActiveDocument.Selection
Dim line As Integer = objSelection.CurrentLine
objSelection.StartOfDocument()
' find all EasyCODE blocks
While objSelection.FindText("^.*\/\* EasyCODE.*((\n.*\*\/)|(\n.*\/\*.*)|(\n\/\/.*))*", vsFindOptions.vsFindOptionsRegularExpression)
DTE.ExecuteCommand("Edit.HideSelection")
End While
objSelection.StartOfDocument()
objSelection.GotoLine(line)
DTE.UndoContext.Close()
DTE.SuppressUI = False
End Sub
End Module
在宏IDE(工具 - >宏 - >宏IDE)中创建一个新的宏,将上述代码粘贴到其中,然后为其分配键盘快捷键(工具 - >选项 - >“ options-> Environment->键盘”,在列表框)。点击键盘快捷键,所有EasyCode评论将消失。
玩得开心!
其他提示
您不能自动执行此操作。但是,您可以选择一块代码,然后从上下文菜单概述/隐藏选择(CTRL+M CTRL+H)中选择。因此,选择丑陋的评论,然后这样做。
取自 这里.
不隶属于 StackOverflow