locked
how to capture/access the words entered/typed in the VisualStudio editor? RRS feed

  • Question

  • Hi

    I am trying to develop an add-in for VisualStudio (similar to ReSharper). I want to know how to capture the keywords/identifiers which we enter (while coding certain application)  in the VS Editor and store it an array?

    Thanks,
    Nayana


    Monday, November 24, 2008 10:36 AM

Answers

  •  Discovering Code by Using the Code Model (Visual C#)
    Return to the source, learn the way!
    • Marked as answer by Nayna Wednesday, December 10, 2008 9:47 AM
    Tuesday, November 25, 2008 3:38 AM
  • OnConnection is probably not going to work for this type of method call.  The reason is that when OnConnection is called, there may or may not be any open documents in the IDE.

    It is difficult to answer your question of where to call this method without knowing what your goal is.  What do you want to accomplish after you find out what the code element is at the cursor?

    In general, this type code would probably be executed from a command.  Probably a context menu.

    Also, you will need to add some exception handling to this method and check for nulls in some of your chained method calls because some of these objects can be null at times.

    Insertion point is where text will appear next if it is added to the buffer.
    • Proposed as answer by FengChen Wednesday, November 26, 2008 1:45 PM
    • Marked as answer by Nayna Thursday, November 27, 2008 4:03 AM
    • Unmarked as answer by Nayna Thursday, November 27, 2008 6:35 AM
    • Marked as answer by Nayna Wednesday, December 10, 2008 9:48 AM
    Wednesday, November 26, 2008 12:26 PM

All replies

  •  Discovering Code by Using the Code Model (Visual C#)
    Return to the source, learn the way!
    • Marked as answer by Nayna Wednesday, December 10, 2008 9:47 AM
    Tuesday, November 25, 2008 3:38 AM
  • thanks for the help! :)


    where should i place the code which gets the code element? should i call the function from onConnection method? (Below is the function to capture codeElement)
    what does insertion point mean?

    public
    void CodeElementFromPointFunction(DTE dte)

    {

    TextSelection sel = (TextSelection)dte.ActiveDocument.Selection;

    TextPoint pnt=(TextPoint)sel.ActivePoint;

    FileCodeModel fcm=dte.ActiveDocument.ProjectItem.FileCodeModel;

    string elems = "";

    vsCMElement scopes = 0;

    foreach (vsCMElement scope in Enum.GetValues(scopes.GetType()))

    {

    CodeElement elem = fcm.CodeElementFromPoint(pnt, scope);

    if (elem != null)

    elems += elem.Name + " (" + scope.ToString() + ")\n";

    }

    }



    Wednesday, November 26, 2008 9:17 AM
  • OnConnection is probably not going to work for this type of method call.  The reason is that when OnConnection is called, there may or may not be any open documents in the IDE.

    It is difficult to answer your question of where to call this method without knowing what your goal is.  What do you want to accomplish after you find out what the code element is at the cursor?

    In general, this type code would probably be executed from a command.  Probably a context menu.

    Also, you will need to add some exception handling to this method and check for nulls in some of your chained method calls because some of these objects can be null at times.

    Insertion point is where text will appear next if it is added to the buffer.
    • Proposed as answer by FengChen Wednesday, November 26, 2008 1:45 PM
    • Marked as answer by Nayna Thursday, November 27, 2008 4:03 AM
    • Unmarked as answer by Nayna Thursday, November 27, 2008 6:35 AM
    • Marked as answer by Nayna Wednesday, December 10, 2008 9:48 AM
    Wednesday, November 26, 2008 12:26 PM