Ejemplo n.º 1
0
 static public int GetCursorLineNo()
 {
     // EnvDTE.TextPoint point = GetTextDocument().StartPoint;
     // EnvDTE.TextPoint objCursorTextPoint = GetTextDocument().Selection.ActivePoint;
     EnvDTE.TextPoint objCursorTextPoint = GetTextSelection().ActivePoint;
     return(objCursorTextPoint.Line - 1);
 }
Ejemplo n.º 2
0
        //TextEditorEvents
        public void LineChanged(EnvDTE.TextPoint startPoint, EnvDTE.TextPoint endPoint, int hint)
        {
            vsTextChanged textChangedHint = (vsTextChanged)hint;

            _outputWindowPane.OutputString("TextEditorEvents, LineChanged\n");
            _outputWindowPane.OutputString("\tDocument: " + startPoint.Parent.Parent.Name + "\n");
            _outputWindowPane.OutputString("\tChange hint: " + textChangedHint.ToString() + "\n");
        }
Ejemplo n.º 3
0
        public static string GetLineText(this EnvDTE.TextPoint point)
        {
            var start = point.CreateEditPoint();

            start.StartOfLine();
            var endP = point.CreateEditPoint();

            endP.EndOfLine();
            return(start.GetText(endP));
        }
        /// <summary>
        /// Inserts text and format the text (=Format Selection command)
        /// </summary>
        /// <param name="tp"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static EnvDTE.TextPoint InsertAndFormat(this EnvDTE.TextPoint tp, string text)
        {
            var start = tp.CreateEditPoint();
            //preserve editPoint
            var ep = tp.CreateEditPoint();

            ep.Insert(text);
            start.SmartFormat(ep);
            return(ep);
        }
Ejemplo n.º 5
0
        public static void doCreateXMLDocumentForFunction(EnvDTE.CodeFunction func)
        {
            // probably should use StringBuilder here for better performance/memory use
            // but am not as readability is main purpose of example
            string xmlComments = "";

            xmlComments +=
                "\t\t/// <summary> " + func.Name + "()";

            switch (func.FunctionKind)
            {
            case vsCMFunction.vsCMFunctionConstructor:
                xmlComments += " constructor"; break;

            case vsCMFunction.vsCMFunctionDestructor:
                xmlComments += " destructor"; break;

            default: break;
            }

            if (func.Parameters.Count <= 0)
            {
                xmlComments += ".  No parameters";
            }
            xmlComments += ". </summary> \n";

            foreach (CodeParameter param in func.Parameters)
            {
                xmlComments +=
                    "\t\t/// <param name=\"" + param.Name + "\"> type: " +
                    param.Type.AsString + "</param> \n";
            }
            xmlComments +=
                "\t\t/// <returns> " + func.Type.AsString + "</returns>\n";


            Debug.WriteLine(xmlComments);

            if (func.DocComment.Length <= 1)
            {
                // this does not work: func.DocComment = xmlComments;
                // editing does work
                Debug.WriteLine("writing XML comments to source file...");
                EnvDTE.TextPoint tp = func.GetStartPoint(EnvDTE.vsCMPart.vsCMPartWholeWithAttributes);
                EnvDTE.EditPoint ep = tp.CreateEditPoint();
                ep.StartOfLine();
                ep.Insert(xmlComments);
            }
            else
            {
                Debug.WriteLine("XML comments already present in source file:");
                Debug.WriteLine(func.DocComment);
                Debug.WriteLine("-- end doc comment --");
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public string GetCurrentMethodName()
 {
     try{
         EnvDTE.TextSelection   SelectedText    = this.Application.ActiveDocument.Selection as EnvDTE.TextSelection;
         EnvDTE.TextPoint       tp              = SelectedText.TopPoint as EnvDTE.TextPoint;
         EnvDTE.CodeElement     c               = this.Application.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint(tp, EnvDTE.vsCMElement.vsCMElementFunction);
         EnvDTE80.CodeFunction2 CurrentFunction = c as EnvDTE80.CodeFunction2;
         return(c.Name);
     }
     catch {
         return("");
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Get to the beginning of doc comments for startPoint
        /// </summary>
        /// <param name="startPoint"></param>
        /// <returns></returns>
        /// <remarks>
        /// EnvDte does not have a way to get to the starting point of a code element doc comment.
        /// If we need to insert some text before a code element that has doc comments we need to go to the beggining of the comments.
        /// </remarks>
        public static EditPoint GetCommentStartPoint(this EnvDTE.TextPoint startPoint)
        {
            var sp = startPoint.CreateEditPoint();

            //keep going 1 line up until the line does not start with doc comment prefix
            do
            {
                sp.LineUp();
            } while (DocCommentRegex.IsMatch(sp.GetLineText()));
            //Go to the beginning of first line of comment, or element itself
            sp.LineDown();
            sp.StartOfLine();
            return(sp);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Inserts text and format the text (=Format Selection command)
        /// </summary>
        /// <param name="tp"></param>
        /// <param name="text"></param>
        /// <param name="formatEndPoint"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static EnvDTE.TextPoint InsertAndFormat(this EnvDTE.TextPoint tp, string text, EnvDTE.TextPoint formatEndPoint = null)
        {
            //preserve editPoint
            var start = tp.CreateEditPoint();

            var activePoint = tp.CreateEditPoint();

            start.DeleteWhitespace(vsWhitespaceOptions.vsWhitespaceOptionsVertical);
            activePoint.Insert(text);
            var endPoint = formatEndPoint ?? activePoint;

            endPoint.CreateEditPoint().DeleteWhitespace(vsWhitespaceOptions.vsWhitespaceOptionsVertical);
            start.SmartFormat(endPoint);
            return(activePoint);
        }
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
    {
        EnvDTE.TextSelection ts = DTE.ActiveWindow.Selection as EnvDTE.TextSelection;
        if (ts == null)
        {
            return;
        }

        EnvDTE.CodeClass c = ts.ActivePoint.CodeElement[vsCMElement.vsCMElementClass]
                             as EnvDTE.CodeClass;
        if (c == null)
        {
            return;
        }

        foreach (EnvDTE.CodeElement e in c.Members)
        {
            if (e.Kind == vsCMElement.vsCMElementFunction)
            {
                EnvDTE.TextPoint p = (e as EnvDTE.CodeFunction).GetStartPoint();
                DTE.Debugger.Breakpoints.Add("", p.Parent.Parent.FullName, p.Line);
            }
        }
    }
        private static CodeElement GetCodeElementAtTextPoint(vsCMElement eRequestedCodeElementKind, CodeElements colCodeElements, EnvDTE.TextPoint objTextPoint)
        {
            CodeElement objResultCodeElement = null;


            if (colCodeElements == null)
            {
                return(null);
            }
            foreach (var objCodeElement in colCodeElements.Cast <CodeElement>())
            {
                if (objCodeElement.StartPoint.GreaterThan(objTextPoint))
                {
                    // The code element starts beyond the point
                }
                else if (objCodeElement.EndPoint.LessThan(objTextPoint))
                {
                    // The code element ends before the point

                    // The code element contains the point
                }
                else
                {
                    if (objCodeElement.Kind == eRequestedCodeElementKind)
                    {
                        // Found
                        objResultCodeElement = objCodeElement;
                    }

                    // We enter in recursion, just in case there is an inner code element that also
                    // satisfies the conditions, for example, if we are searching a namespace or a class
                    var colCodeElementMembers = GetCodeElementMembers(objCodeElement);

                    var objMemberCodeElement = GetCodeElementAtTextPoint(eRequestedCodeElementKind, colCodeElementMembers, objTextPoint);

                    if ((objMemberCodeElement != null))
                    {
                        // A nested code element also satisfies the conditions
                        objResultCodeElement = objMemberCodeElement;
                    }

                    break;
                }
            }

            return(objResultCodeElement);
        }
Ejemplo n.º 11
0
 public VirtualPoint(EnvDTE.TextPoint point)
 {
     Line           = point.Line;
     LineCharOffset = point.LineCharOffset;
 }
Ejemplo n.º 12
0
        /*public void GetCodeElementAtCursor()
         * {
         *      EnvDTE.CodeElement objCodeElement = default(EnvDTE.CodeElement);
         *      EnvDTE.TextPoint objCursorTextPoint = default(EnvDTE.TextPoint);
         *
         *      try
         *      {
         *              objCursorTextPoint = GetCursorTextPoint();
         *
         *              if ((objCursorTextPoint != null))
         *              {
         *                      // Get the class at the cursor
         *                      objCodeElement = GetCodeElementAtTextPoint(vsCMElement.vsCMElementClass, DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements, objCursorTextPoint);
         *              }
         *
         *              if (objCodeElement == null)
         *              {
         *                      MessageBox.Show("No class found at the cursor!");
         *              }
         *              else
         *              {
         *                      MessageBox.Show("Class at the cursor: " + objCodeElement.FullName);
         *              }
         *      }
         *      catch (System.Exception ex)
         *      {
         *              MessageBox.Show(ex.ToString);
         *      }
         * }*/

        /*private EnvDTE.TextPoint GetCursorTextPoint()
         * {
         *      EnvDTE.TextDocument objTextDocument = default(EnvDTE.TextDocument);
         *      EnvDTE.TextPoint objCursorTextPoint = default(EnvDTE.TextPoint);
         *
         *      try
         *      {
         *              objTextDocument = (EnvDTE.TextDocument)DTE.ActiveDocument.Object;
         *              objCursorTextPoint = objTextDocument.Selection.ActivePoint();
         *      }
         *      catch (System.Exception ex)
         *      {
         *      }
         *
         *      return objCursorTextPoint;
         * }*/

        public static EnvDTE.CodeElement GetCodeElementAtTextPoint(EnvDTE.vsCMElement eRequestedCodeElementKind, EnvDTE.CodeElements colCodeElements, EnvDTE.TextPoint objTextPoint)
        {
            EnvDTE.CodeElement  objResultCodeElement  = default(EnvDTE.CodeElement);
            EnvDTE.CodeElements colCodeElementMembers = default(EnvDTE.CodeElements);
            EnvDTE.CodeElement  objMemberCodeElement  = default(EnvDTE.CodeElement);

            if ((colCodeElements != null))
            {
                foreach (CodeElement objCodeElement in colCodeElements)
                {
                    /*if (objCodeElement.StartPoint.GreaterThan(objTextPoint))
                     * {
                     *      // The code element starts beyond the point
                     * }
                     * else if (objCodeElement.EndPoint.LessThan(objTextPoint))
                     * {
                     *      // The code element ends before the point
                     *
                     *      // The code element contains the point
                     * }
                     * else*/
                    {
                        if (objCodeElement.Kind == eRequestedCodeElementKind)
                        {
                            // Found
                            objResultCodeElement = objCodeElement;
                        }

                        // We enter in recursion, just in case there is an inner code element that also
                        // satisfies the conditions, for example, if we are searching a namespace or a class
                        colCodeElementMembers = GetCodeElementMembers(objCodeElement);

                        objMemberCodeElement = GetCodeElementAtTextPoint(eRequestedCodeElementKind, colCodeElementMembers, objTextPoint);

                        if ((objMemberCodeElement != null))
                        {
                            // A nested code element also satisfies the conditions
                            objResultCodeElement = objMemberCodeElement;
                        }

                        break;                         // TODO: might not be correct. Was : Exit For
                    }
                }
            }

            return(objResultCodeElement);
        }