本文译自: http://blogs.msdn.com/b/vcblog/archive/2007/11/19/controlling-intellisense-through-macros.aspx
当解决方案包含了很多个工程,越来越大之后,VS的智能提示经常会导致VS本身卡死。其实,当安装了VC助手后,VS的智能提示就可以不用开启了。
In general, these advanced settings should be unnecessary except for extremely large solutions or other special situations, especially given the improvements we recently implemented.
VS的一个工程师提供了一种通过宏(Macros)控制智能提示的方法:(以下操作使用的是英文版VS2008,其他版本或语言请自行对应。)
1. 进入Tools -> Macros -> Macro Explorer,右击”Macros”节点,选择”New Macro Project”。选择“Macro Project”,将其重命名为”Intellisense”,保存默认即可。这样就创建了一个名为”Module1”的模块,将其改名为”IntellisenseModule”。右击该模块,选择”Edit”,将会出现一个空模块窗口,然后将以下内容粘贴至该模块并保存退出。
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Enum ISENSE_FLAGS
ISENSE_NORMAL = 0 'normal (Intellisense On)
ISENSE_NOBG = &H1 'no bg parsing (Intellisense Updating Off - although NCB file will be opened r/w and repersisted at shutdown)
ISENSE_NOQUERY = &H2 'no queries (don't run any ISense queries)
ISENSE_NCBRO = &H4 'no saving of NCB (must be set before opening NCB, doesn't affect updating or queries, just persisting of NCB)
ISENSE_OFF = &H7 'no bg parsing, no queries, no saving of NCB, ncb will still be opened, however
End Enum
Public Module IntellisenseModule
Sub Intellisense_NoUpdate()
DTE.Properties("TextEditor", "C/C++ Specific").Item("IntellisenseOptions").Value = ISENSE_FLAGS.ISENSE_NOBG Or ISENSE_FLAGS.ISENSE_NCBRO
End Sub
Sub Intellisense_Off()
DTE.Properties("TextEditor", "C/C++ Specific").Item("IntellisenseOptions").Value = ISENSE_FLAGS.ISENSE_OFF
End Sub
Sub Intellisense_On()
DTE.Properties("TextEditor", "C/C++ Specific").Item("IntellisenseOptions").Value = ISENSE_FLAGS.ISENSE_NORMAL
End Sub
Sub Intellisense_Status()
Dim x
x = DTE.Properties("TextEditor", "C/C++ Specific").Item("IntellisenseOptions").Value
Dim result
If x = ISENSE_FLAGS.ISENSE_NORMAL Then
result = "Intellisense On"
ElseIf x = ISENSE_FLAGS.ISENSE_OFF Then
result = "Intellisense Off"
Else
If x And ISENSE_FLAGS.ISENSE_NOBG Then
result = "No background parsing. "
End If
If x And ISENSE_FLAGS.ISENSE_NOQUERY Then
result = result + "No Intellisense queries in IDE. "
End If
If x And ISENSE_FLAGS.ISENSE_NCBRO Then
result = result + "No saving of NCB file. "
End If
End If
MsgBox(result)
End Sub
Sub DeleteNcbAndReload()
Dim name
Dim namesln
namesln = DTE.Solution.FullName()
If Len(namesln) > 4 Then
name = Left(namesln, Len(namesln) - 4) & ".ncb"
If MsgBox("This may take a while. Closing solution, deleting " & name & ", and reopening solution.", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
DTE.Solution.Close()
Kill(name)
MsgBox("NCB deleted", MsgBoxStyle.OkOnly)
DTE.Solution.Open(namesln)
End If
Else
MsgBox("No solution is currently loaded.", MsgBoxStyle.OkOnly)
End If
End Sub
End Module
2. 进入”Tools -> Customize”,在”Toolbars”选项卡下,点击”New”,并将其命名为”Intellisense”。点击确定后,在右侧会有一个空的toolbar。再选择”Commands”选项卡,在左侧listbox中选择”Macros”,你就能看到你刚才建立的Intellisense宏了。将它们都拖到刚才的空toolbar中。
OK,你就能通过点击Intellisense Toolbar上的button,控制你的Intellisense策略了。
3. 对这五个选项的附加说明:
3.1 Intellisense On
默认打开所有的智能提示。
3.2 Intellisense Off
在该模式禁用了大部分智能提示。
3.3 Intellisense NoUpdate
仅在开始的时候解析智能提示。当文件发生变化后,不再继续解析。(推荐选择该方案)
3.4 Intellisense Status
该模式查询文件状态,然后弹出一个对话框通知当前的智能提示设定。
3.5 DeleteNcbAndReload
当智能提示出现问题时,可以使用该模式删除ncb文件,并重新生成。
4. 两点重要提示:
4.1 这些设置是持久性的,不会随着IDE的关闭而失效,并且它是全局性的,不与解决方案相关。
4.2 在改变设置的时候,请确保有某个VC解决方案打开。(实际上是vcpkg.dll有没有被加载)。