Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This question was answered before for a previous version of Visual Studio (VS). The offered solutions involved macros, which are no longer available in VS 2015. Could I get a solution for VS 2015?

I would like to do a "find all" in VS and put a debug-breakpoint on every line with a find match.

Link to previous question asked by Noah: How do I add Debug Breakpoints to lines displayed in a "Find Results" window in Visual Studio

like image 931
matrumz Avatar asked Jun 27 '16 19:06

matrumz


2 Answers

I've converted the old macro to a VB command in Visual Commander (by adding explicit namespaces to classes):

Public Class C
    Implements VisualCommanderExt.ICommand

    Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
        Dim findResultsWindow As EnvDTE.Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindFindResults1)

        Dim selection As EnvDTE.TextSelection
        selection = findResultsWindow.Selection
        selection.SelectAll()

        Dim findResultsReader As New System.IO.StringReader(selection.Text)
        Dim findResult As String = findResultsReader.ReadLine()

        Dim findResultRegex As New System.Text.RegularExpressions.Regex("(?<Path>.*?)\((?<LineNumber>\d+)\):")

        While Not findResult Is Nothing
            Dim findResultMatch As System.Text.RegularExpressions.Match = findResultRegex.Match(findResult)

            If findResultMatch.Success Then
                Dim path As String = findResultMatch.Groups.Item("Path").Value
                Dim lineNumber As Integer = Integer.Parse(findResultMatch.Groups.Item("LineNumber").Value)

                Try
                    DTE.Debugger.Breakpoints.Add("", path, lineNumber)
                Catch ex As System.Exception
                    ' breakpoints can't be added everywhere
                End Try
            End If

            findResult = findResultsReader.ReadLine()
        End While
    End Sub

End Class
like image 84
Sergey Vlasov Avatar answered Sep 21 '22 05:09

Sergey Vlasov


If you have JetBrains Resharper and use one of Reharper's search commands, you can do this directly from Resharper's Find Results window (different from VS Find Results).

Example:

Resharper > Navigate > Go to Text... (Ctrl+T,T,T if using Resharper key map)

And then in Find Results (Resharper), right click any node or container in the tree view and choose "Set Breakpoint." This sets a breakpoint on all sub-nodes.

enter image description here

Reference:

https://blog.jetbrains.com/dotnet/2017/12/04/debugger-features-resharper/

like image 38
Rich Avatar answered Sep 22 '22 05:09

Rich