public static void Run(DTE environment, VsError selectedError) { if (selectedError == null) { throw new ArgumentNullException("selectedError", @"Selected error is null"); } selectedError.Navigate(); // Replace all items that have spaces before the ending brackets // "A closing parenthesis should never be preceded by whitespace." ErrorUtilities.RegExUpdateWholeDocument(@"\s+\)", ")", selectedError, environment); // "If the closing parenthesis is followed by whitespace, the next non-whitespace character must not be an opening or closing parenthesis or square bracket, // or a semicolon or comma." ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+;", @");", selectedError, environment); ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+,", @"),", selectedError, environment); ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+\(", @")(", selectedError, environment); ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+\)", @"))", selectedError, environment); ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+\[", @")\[", selectedError, environment); ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+\]", @")\]", selectedError, environment); // replace all items that have a cariage return between each line ErrorUtilities.RegExUpdateWholeDocument(@"(\s+[a-zA-Z]+\))\s*\r\n(\).*)", "$1$2", selectedError, environment); // In most cases, a closing parenthesis should be followed by a single space, unless the closing parenthesis comes at the end of a cast, // or the closing parenthesis is followed by certain types of operator symbols, such as positive signs, negative signs, and colons. }
public static void Run(DTE dte, VsError selectedError) { var logger = new ConsoleLogger { Trace = true }; Console.WriteLine(); Console.WriteLine(new string('_', 60)); selectedError.Navigate(); string formatString = Properties.StyleRepair.Default.NArrangeUseRegions ? @"{0}\NArrangeConfigWithRegions.xml" : @"{0}\NArrangeConfig.xml"; var fileArranger = new FileArranger( string.Format(formatString, Path.GetDirectoryName(Assembly.GetCallingAssembly().Location)), Logger.Instance); bool success = fileArranger.Arrange(dte.ActiveDocument.FullName, dte.ActiveDocument.FullName, true); if (!success) { logger.LogMessage(LogLevel.Error, "Unable to NArrange {0}.", dte.ActiveDocument.FullName); } }
public static void Run(DTE dte, VsError selectedError) { selectedError.Navigate(); var ep = ErrorUtilities.GetEditPoint(dte); ep.LineDown(); ep.Delete(1); }
public static void Run(DTE dte, VsError selectedError) { selectedError.Navigate(); EditPoint2 ep = ErrorUtilities.GetEditPoint(dte); ep.LineDown(); ep.StartOfLine(); ep.InsertNewLine(); }
public static void Run(DTE dte, VsError selectedError) { selectedError.Navigate(); /* * A violation of this rule occurs when the preprocessor-type keyword in a preprocessor directive is preceded by space */ ErrorUtilities.RegExUpdateWholeDocument(@"#[^\S\n]+(\w)", "#$1", selectedError, dte); }
public static void Run(DTE dte, VsError selectedError) { selectedError.Navigate(); var ep = ErrorUtilities.GetEditPoint(dte); ep.LineUp(); while (ep.LineLength == 0) { ep.Delete(1); ep.LineUp(); } }
/// <summary> /// Fix error SA1600 /// </summary> /// <param name="dte">Current design environment</param> /// <param name="selectedError">Error selected by the user to fix.</param> public static void Run(DTE dte, VsError selectedError) { EditPoint2 ep = ErrorUtilities.GetEditPoint(dte); selectedError.Navigate(); var selection = (TextSelection)dte.ActiveDocument.Selection; var propertyElement = (CodeProperty)selection.ActivePoint.CodeElement[vsCMElement.vsCMElementProperty]; if (propertyElement != null) { ProcessPropertyUpdate(propertyElement, ep); } }
public static void Run(DTE dte, VsError error) { error.Navigate(); EditPoint2 ep = ErrorUtilities.GetEditPoint(dte); ep.StartOfLine(); string variableName = error.Description.Split(" ".ToCharArray())[7]; string replaceString = ep.GetLines(ep.Line, ep.Line + 1); replaceString = Regex.Replace(replaceString, string.Format(@"(\s|\(|\!)({0})(\W)", variableName), "$1this.$2$3", RegexOptions.None); ep.ReplaceText(ep.LineLength, replaceString, (int )vsEPReplaceTextOptions.vsEPReplaceTextAutoformat); }
public static void Run(DTE dte, VsError selectedError) { selectedError.Navigate(); /* * A violation of this rule occurs when the opening parenthesis within a statement is not spaced correctly. * An opening parenthesis should not be preceded by any whitespace, unless it is the first character on the line, or it is preceded * by certain C# keywords such as if, while, or for. In addition, an opening parenthesis is allowed to be preceded by whitespace when * it follows an operator symbol within an expression. * * An opening parenthesis should not be followed by whitespace, unless it is the last character on the line. */ ErrorUtilities.RegExUpdateWholeDocument(@"\([^\S\n]+", "(", selectedError, dte); }
public static void RegExUpdate(string findPattern, string replacePattern, VsError selectedError, DTE dte) { selectedError.Navigate(); EditPoint2 ep = GetEditPoint(dte); ep.StartOfLine(); string textToUpdate = ep.GetLines(ep.Line, ep.Line + 1); textToUpdate = Regex.Replace(textToUpdate, findPattern, replacePattern); // Using the Autoformat option is cheating a little but saves on a lot of work. It basically formats // the text as if you were typing it in the IDE ep.ReplaceText(ep.LineLength, textToUpdate, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat); }
public static void RegExUpdateWholeDocument(string findPattern, string replacePattern, VsError selectedError, DTE dte) { selectedError.Navigate(); Document curDoc = dte.ActiveDocument; var textDoc = (TextDocument)curDoc.Object(); textDoc.Selection.SelectAll(); string allTheText = textDoc.Selection.Text; string formattedText = Regex.Replace(allTheText, findPattern, replacePattern, RegexOptions.Multiline); textDoc.Selection.Cut(); textDoc.Selection.Insert(formattedText); }
public static void Run(DTE dte, VsError selectedError) { selectedError.Navigate(); EditPoint2 ep = ErrorUtilities.GetEditPoint(dte); ep.StartOfLine(); string testString = ep.GetLines(ep.Line, ep.Line + 1); if (Regex.Match(testString, @"\t").Success) { testString = Regex.Replace(testString, @"\t", @" "); ep.ReplaceText(ep.LineLength, testString, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat); } }
public static void Run(DTE dte, VsError selectedError) { selectedError.Navigate(); Document curDoc = dte.ActiveDocument; var textDoc = (TextDocument)curDoc.Object(); TextSelection selection = textDoc.Selection; // Use top point here to take care of collapsed definitions var ep = (EditPoint2)selection.TopPoint.CreateEditPoint(); ep.StartOfLine(); ep.LineUp(); while (ep.GetText(ep.LineLength).Replace(" ", string.Empty).StartsWith("//") || ep.GetText(ep.LineLength).Replace(" ", string.Empty).StartsWith("[")) { ep.LineUp(); } ep.EndOfLine(); ep.InsertNewLine(); }
public static void Run(DTE dte, VsError selectedError) { selectedError.Navigate(); EditPoint2 editPoint = ErrorUtilities.GetEditPoint(dte); editPoint.StartOfDocument(); string fileName = selectedError.FileName.Substring( selectedError.FileName.LastIndexOf(@"\") + 1, selectedError.FileName.Length - (selectedError.FileName.LastIndexOf(@"\") + 1)); editPoint.InsertNewLine(); editPoint.StartOfDocument(); editPoint.Insert( string.Format( @"//----------------------------------------------------------------------- // <copyright file=""{0}"" company=""{1}""> // {2} // </copyright> //-----------------------------------------------------------------------", fileName, StyleRepair.Properties.StyleRepair.Default.CompanyName, StyleRepair.Properties.StyleRepair.Default.CopyrightMessage)); }
public static void Run(DTE dte, VsError selectedError) { selectedError.Navigate(); EditPoint2 ep = ErrorUtilities.GetEditPoint(dte); ep.StartOfLine(); string editLine = ep.GetLines(ep.Line, ep.Line + 1); editLine = editLine.Replace(";", ""); string varName = string.Empty; if (editLine.IndexOf("=") > -1) { varName = editLine.Split("=".ToCharArray()).First().Split(" ".ToCharArray()).Where(item => item.Length > 0).Last(); } else { varName = editLine.Split(" ".ToCharArray()).Last(); } ep.Parent.Selection.CharRight(Count: editLine.IndexOf(varName)); dte.ExecuteCommand("Refactor.Rename"); //// todo }
public static void Run(DTE environment, VsError selectedError) { selectedError.Navigate(); ErrorUtilities.RegExUpdateWholeDocument(@"\/\/([^\/\s])", "// $1", selectedError, environment); }
public static void Run(DTE environment, VsError selectedError) { selectedError.Navigate(); // TODO: verify this works ErrorUtilities.RegExUpdate(@"(?<=\})\s*;", string.Empty, selectedError, environment); }
public static void Run(DTE dte, VsError selectedError) { selectedError.Navigate(); dte.ExecuteCommand("Edit.SortUsings"); }
public static void Run(DTE dte, VsError selectedItem) { selectedItem.Navigate(); ErrorUtilities.RegExUpdateWholeDocument(@"^(\s*\t*\r\n\s*\t*){1,}$", string.Empty, selectedItem, dte); }