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); }
/// <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 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> /// 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); }