code_junkie

How do I add Debug Breakpoints to lines displayed in a “Find Results” window in Visual Studio

Nov 10th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. Imports System
  2. Imports System.IO
  3. Imports System.Text.RegularExpressions
  4. Imports EnvDTE
  5. Imports EnvDTE80
  6. Imports EnvDTE90
  7. Imports System.Diagnostics
  8.  
  9. Public Module CustomMacros
  10. Sub BreakpointFindResults()
  11. Dim findResultsWindow As Window = DTE.Windows.Item(Constants.vsWindowKindFindResults1)
  12.  
  13. Dim selection As TextSelection
  14. selection = findResultsWindow.Selection
  15. selection.SelectAll()
  16.  
  17. Dim findResultsReader As New StringReader(selection.Text)
  18. Dim findResult As String = findResultsReader.ReadLine()
  19.  
  20. Dim findResultRegex As New Regex("(?<Path>.*?)((?<LineNumber>d+)):")
  21.  
  22. While Not findResult Is Nothing
  23. Dim findResultMatch As Match = findResultRegex.Match(findResult)
  24.  
  25. If findResultMatch.Success Then
  26. Dim path As String = findResultMatch.Groups.Item("Path").Value
  27. Dim lineNumber As Integer = Integer.Parse(findResultMatch.Groups.Item("LineNumber").Value)
  28.  
  29. Try
  30. DTE.Debugger.Breakpoints.Add("", path, lineNumber)
  31. Catch ex As Exception
  32. ' breakpoints can't be added everywhere
  33. End Try
  34. End If
  35.  
  36. findResult = findResultsReader.ReadLine()
  37. End While
  38. End Sub
  39. End Module
  40.  
  41. Sub BreakPointAtString()
  42.  
  43. Try
  44. DTE.ExecuteCommand("Debug.DisableAllBreakpoints")
  45. Catch ex As Exception
  46.  
  47. End Try
  48.  
  49. Dim tsSelection As String = DTE.ActiveDocument.Selection.text
  50. DTE.ActiveDocument.Selection.selectall()
  51. Dim AllText As String = DTE.ActiveDocument.Selection.Text
  52.  
  53. Dim findResultsReader As New StringReader(AllText)
  54. Dim findResult As String = findResultsReader.ReadLine()
  55. Dim lineNum As Integer = 1
  56.  
  57. Do Until findResultsReader.Peek = -1
  58. lineNum += 1
  59. findResult = findResultsReader.ReadLine()
  60. If Trim(findResult) = Trim(tsSelection) Then
  61. DTE.ActiveDocument.Selection.GotoLine(lineNum)
  62. DTE.ExecuteCommand("Debug.ToggleBreakpoint")
  63. End If
  64. Loop
  65.  
  66. End Sub
  67.  
  68. Error
  69. ---------------------------
  70. Error HRESULT E_FAIL has been returned from a call to a COM component.
  71. ---------------------------
  72. OK
  73. ---------------------------
  74.  
  75. Sub BreakPointsFromSearch()
  76. Dim n As Integer = InputBox("Enter the number of search results")
  77.  
  78. For i = 1 To n
  79. DTE.ExecuteCommand("Edit.GoToNextLocation")
  80. DTE.ExecuteCommand("Debug.ToggleBreakpoint")
  81. Next
  82. End Sub
Add Comment
Please, Sign In to add comment