locked
Find All References RRS feed

  • Question

  • Hello

      i was wanting to write a add-in that would scan a code module and do a find all references on each rotuine, and output the results to a file.

    is that possible? if it is where is the best place to look for examples?  i am not getting too far with the help. 

    Friday, March 26, 2010 7:26 PM

Answers

All replies

  • Friday, March 26, 2010 8:10 PM
  • thanks for the info it helped a lot, i have the serveice, and it looks like it is working, but  it does not return any results when i do the search.  but if i right click on the routine and click find all references it brings back the results i would have expected with my code.  could you look at this and see what i might be doing wrong?  i am using vs 2008 sp1.  the code is in an addin where the user is pressing a command on the tools menu.  for testing the the active window that the routine is in and the routine is always the same.  after i press the menu item it the symbol resutls says nothing, but if i right click on the routine and select find all references it will show me all of the references

     

    Dim

     

    myFCM As FileCodeModel = _applicationObject.ActiveWindow.ProjectItem.FileCodeModel

     

    Dim myClass1 As CodeClass = CType(myFCM.CodeElements.Item(ModuleVBName), CodeClass2)

     

    For Each ce As CodeElement2 In myClass1.Members

     

      If ce.Kind = vsCMElement.vsCMElementFunction Then

     

        If ce.Name.ToLower = RoutineName.ToLower Then

     

          Dim myFunction As CodeFunction2 = CType(myClass1.Members.Item(ce.Name), CodeFunction2)

     

          Dim objService As Object

     

          Dim m_ObjSearch As IVsObjectSearch

    ' this get servrvice routine is from the mztools site

          objService = GetService(_applicationObject,

    GetType(Microsoft.VisualStudio.Shell.Interop.IVsObjectSearch))

          m_ObjSearch =

    CType(objService, Microsoft.VisualStudio.Shell.Interop.IVsObjectSearch)

     

          Dim SRCH(0) As VSOBSEARCHCRITERIA

     

          Dim objList As IVsObjectList = Nothing

     

          With SRCH(0)

             .dwCustom = 0

             .eSrchType = VSOBSEARCHTYPE.SO_ENTIREWORD

             .grfOptions =

    CUInt(_VSOBSEARCHOPTIONS.VSOBSO_CASESENSITIVE)

             .szName = myFunction.

     

           End With

     

           Dim ReturnResult As Integer

     

           Try

           ReturnResult = m_ObjSearch.Find(

    CUInt(__VSOBSEARCHFLAGS.VSOSF_EXPANDREFS), SRCH, objList)

     

           Catch ex As Exception

            MsgBox(ex.Message)

     

            End Try

     

            If ReturnResult = Microsoft.VisualStudio.VSConstants.S_OK Then

               MsgBox(

    "No Error", MsgBoxStyle.Information, SRCH(0).szName)

     

             Else

              MsgBox(

    "error" & vbCrLf & ReturnResult.ToString, MsgBoxStyle.Information, SRCH(0).szName)

     

            End If

     

        End If

     

      End If

     

    Next

    Thursday, April 1, 2010 3:22 PM