Visual Studio提供了许多导航热键: 当前面板中的下一个项目 F8 (搜索结果,错误...), 控制 + K , N 用于书签, Alt + - 返回等等。
有一个我找不到的热键,我甚至找不到它的菜单命令,所以我不能自己创建热键。
我不知道是否存在:Previous和Next call-stack frame。
我在编程时尝试不使用鼠标,但是当我需要返回堆栈时,我必须使用它来双击前一帧。
任何?这样做的宏怎么样?
答案 0 :(得分:18)
我写了2个宏来获取它:PreviousStackFrame
和NextStackFrame
并分配了快捷方式
Function StackFrameIndex(ByRef aFrames As EnvDTE.StackFrames, ByRef aFrame As EnvDTE.StackFrame) As Long
For StackFrameIndex = 1 To aFrames.Count
If aFrames.Item(StackFrameIndex) Is aFrame Then Exit Function
Next
StackFrameIndex = -1
End Function
Sub NavigateStack(ByVal aShift As Long)
If DTE.Debugger.CurrentProgram Is Nothing Then
DTE.StatusBar.Text = "No program is currently being debugged."
Exit Sub
End If
Dim ind As Long = StackFrameIndex(DTE.Debugger.CurrentThread.StackFrames, DTE.Debugger.CurrentStackFrame)
If ind = -1 Then
DTE.StatusBar.Text = "Stack navigation failed"
Exit Sub
End If
ind = ind + aShift
If ind <= 0 Or ind > DTE.Debugger.CurrentThread.StackFrames.Count Then
DTE.StatusBar.Text = "Stack frame index is out of range"
Exit Sub
End If
DTE.Debugger.CurrentStackFrame = DTE.Debugger.CurrentThread.StackFrames.Item(ind)
DTE.StatusBar.Text = "Stack frame index: " & ind & " of " & DTE.Debugger.CurrentThread.StackFrames.Count
End Sub
Sub PreviousStackFrame()
NavigateStack(1)
End Sub
Sub NextStackFrame()
NavigateStack(-1)
End Sub
答案 1 :(得分:3)
我用AutoHotkey解决了这个问题。我几个月前做过这个。 假设你想使用Control + 1和Control + 2,并且Control + Alt + C必然会显示Call Stack窗口:
^1::SendInput !^c{down}{enter}
^2::SendInput !^c{up}{enter}
它看起来效果很好。如果您还没有使用AutoHotkey来显示Visual Studio的老板,请试一试。你的问题表明你会从中受益匪浅。这是一个改变游戏规则的人。祝你好运。
答案 2 :(得分:2)
我认为这不是一个明确的下一帧/上一帧键绑定,而是我所做的。
CTRL-ALT-C已绑定到“Debug.CallStack” 这将使您专注于调用堆栈工具窗口
一旦专注于Callstack窗口...... Up&amp;向下箭头将引导您完成调用堆栈帧
然后我绑定了
CTRL-C,CTRL-S到“DebuggerContextMenus.CallStackWindow.SwitchToFrame” 和 CTRL-C,CTRL-C到“DebuggerContextMenus.CallStackWindow.SwitchToCode”
这两个将带您回到特定帧的代码窗口。
希望有所帮助。
答案 3 :(得分:0)
非常感谢@Oleg Svechkarenko的回答,这为我提供了制定此解决方案的起点。由于Visual Studio的现代版本不再提供官方的宏支持,因此使用Visual Commander插件的用户应该可以使用它,但很可能可以轻松地将其用于任何其他宏扩展。
这是命令的代码,我创建了一个用于导航调用堆栈的代码,并创建了一个用于导航的代码,除了传递给MoveStackIndex()
的参数外,然后将它们的快捷键绑定了:
using EnvDTE;
using EnvDTE80;
using System;
public class C : VisualCommanderExt.ICommand
{
enum MoveDirection
{
Up,
Down,
}
private bool IsValidFrame(StackFrame frame)
{
string language = frame.Language;
bool result = (language == "C#" ||
language == "C++" ||
language == "VB" ||
language == "Python");
return result;
}
private void MoveStackIndex(EnvDTE80.DTE2 DTE, MoveDirection direction)
{
StackFrame currentFrame = DTE.Debugger.CurrentStackFrame;
bool foundTarget = false;
bool pastCurrent = false;
StackFrame lastValid = null;
foreach (StackFrame frame in DTE.Debugger.CurrentThread.StackFrames)
{
bool isCurrent = frame == currentFrame;
if (direction == MoveDirection.Down)
{
if (isCurrent)
{
if (lastValid == null)
{
// No valid frames below this one
break;
}
else
{
DTE.Debugger.CurrentStackFrame = lastValid;
foundTarget = true;
break;
}
}
else
{
if (IsValidFrame(frame))
{
lastValid = frame;
}
}
}
if (direction == MoveDirection.Up && pastCurrent)
{
if (IsValidFrame(frame))
{
DTE.Debugger.CurrentStackFrame = frame;
foundTarget = true;
break;
}
}
if (isCurrent)
{
pastCurrent = true;
}
}
if (!foundTarget)
{
DTE.StatusBar.Text = "Failed to find valid stack frame in that direction.";
}
}
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
if (DTE.Debugger.CurrentProgram == null)
{
DTE.StatusBar.Text = "Debug session not active.";
}
else
{
// NOTE: Change param 2 to MoveDirection.Up for the up command
MoveStackIndex(DTE, MoveDirection.Down);
}
}
}
答案 4 :(得分:-2)
查看工具 - &gt;选项 - &gt;环境 - &gt;键盘。输入“堆栈”或“框架”,将出现相关菜单。似乎没有下一个和之前的调用堆栈帧。