private void Fe_FindDone(vsFindResult findResult, bool Cancelled) { dict = new Dictionary <string, List <string> >(); DTE2 dte = ServiceProvider.GetService(typeof(EnvDTE.DTE)) as DTE2; Window window; TextSelection textSelection; TextPoint textSelectionPointSaved; OutputWindowPane outputWindowPane; EnvDTE.TextDocument textDocument; int lastFoundAt = 0; textDocument = (TextDocument)dte.ActiveDocument.Object(""); textSelection = textDocument.Selection; window = dte.ActiveDocument.Windows.Item(1); // Set up output window pane and loop until no more matches. outputWindowPane = GetOutputWindowPane(dte, "Matching Lines"); textSelection.StartOfDocument(); textSelectionPointSaved = textSelection.ActivePoint.CreateEditPoint(); // GetOutputWindowPane activates Output Window, so re-activate our window. window.Activate(); outputWindowPane.Clear(); while (findResult == vsFindResult.vsFindResultFound) { if (textSelection.AnchorPoint.Line <= lastFoundAt) { break; } textSelection.SelectLine(); string functionName = nofunction; EnvDTE.CodeFunction func = textSelection.AnchorPoint.CodeElement[vsCMElement.vsCMElementFunction] as EnvDTE.CodeFunction; if (func != null) { functionName = func.FullName; } if (!dict.ContainsKey(functionName)) { dict.Add(functionName, new List <string>()); } dict[functionName].Add(textSelection.Text); lastFoundAt = textSelection.AnchorPoint.Line; textSelection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn); findResult = dte.Find.Execute(); } // Restore caret to location before invoking this command. textSelection.MoveToPoint(textSelectionPointSaved); PrintAll(outputWindowPane); }
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 --"); } }
public static void doParameters(EnvDTE.CodeFunction func, string indent) { if (func.Parameters.Count <= 0) { Debug.WriteLine(indent + "..." + "no parameters"); } else { foreach (CodeParameter param in func.Parameters) { Debug.WriteLine(indent + "..." + "parameter: " + param.Name + " type: " + param.Type.AsString); } } }
public static void doFunction(EnvDTE.CodeFunction func, string indent) { Debug.WriteLine(indent + "function: " + func.Name + "() returns: " + func.Type.AsString); Debug.WriteLine(indent + "kind: " + func.FunctionKind.ToString()); }
public static void WalkFunction(EnvDTE.CodeFunction func, string indent) { doFunction(func, indent); doParameters(func, indent); //doCreateXMLDocumentForFunction(func); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { dict = new Dictionary <string, List <string> >(); DTE2 dte = ServiceProvider.GetService(typeof(EnvDTE.DTE)) as DTE2; Window window; TextSelection textSelection; TextPoint textSelectionPointSaved; OutputWindowPane outputWindowPane; EnvDTE.vsFindResult findResult; EnvDTE.TextDocument textDocument; int lastFoundAt = 0; textDocument = (TextDocument)dte.ActiveDocument.Object(""); textSelection = textDocument.Selection; window = dte.ActiveDocument.Windows.Item(1); PrepareDefaultFind(dte, "List Matching Lines"); // Set up output window pane and loop until no more matches. outputWindowPane = GetOutputWindowPane(dte, "Matching Lines"); textSelection.StartOfDocument(); textSelectionPointSaved = textSelection.ActivePoint.CreateEditPoint(); // GetOutputWindowPane activates Output Window, so re-activate our window. window.Activate(); outputWindowPane.Clear(); ((EnvDTE80.Find2)dte.Find).WaitForFindToComplete = true; findResult = dte.Find.Execute(); while (findResult == vsFindResult.vsFindResultFound) { if (textSelection.AnchorPoint.Line <= lastFoundAt) { break; } textSelection.SelectLine(); string functionName = nofunction; EnvDTE.CodeFunction func = textSelection.AnchorPoint.CodeElement[vsCMElement.vsCMElementFunction] as EnvDTE.CodeFunction; if (func != null) { functionName = func.Type.AsString + " " + func.Name + "("; int i = 0; foreach (CodeParameter param in func.Parameters) { functionName += param.Type.AsString + " " + param.Name; if (i < (func.Parameters.Count - 1)) { functionName += ", "; } i++; } functionName += ")"; } if (!dict.ContainsKey(functionName)) { dict.Add(functionName, new List <string>()); } dict[functionName].Add(dte.ActiveDocument.Name + "(" + textSelection.AnchorPoint.Line.ToString() + "): " + textSelection.Text); lastFoundAt = textSelection.AnchorPoint.Line; textSelection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn); findResult = dte.Find.Execute(); } // Restore caret to location before invoking this command. textSelection.MoveToPoint(textSelectionPointSaved); PrintAll(outputWindowPane); }