public void PredefinedChecks_ChangeValue_CompareViewToFile() { var settingsHandler = new SettingsHandler(); var settingsProvider = new SettingsProvider(); var tidyChecks = new TidyChecks(); var tidyPredefinedChecks = new List <TidyCheckModel>(tidyChecks.Checks); var checks = new StringBuilder(); tidyPredefinedChecks[0].IsChecked = true; foreach (TidyCheckModel item in tidyPredefinedChecks) { if (item.IsChecked) { checks.Append(item.Name).Append(";"); } } var tidySettingsModel = new TidySettingsModel { PredefinedChecks = checks.ToString() }; settingsProvider.SetTidySettingsModel(tidySettingsModel); settingsHandler.SaveSettings(); settingsHandler.ResetSettings(); settingsHandler.LoadSettings(); Assert.Equal(tidySettingsModel.PredefinedChecks, settingsProvider.GetTidySettingsModel().PredefinedChecks); }
private string GetTidyParameters(TidyOptions aTidyOptions, TidyChecks aTidyChecks) { string parameters = aTidyOptions.Fix ? $" {ScriptConstants.kTidyFix} ''-*," : $" {ScriptConstants.kTidy} ''-*,"; if (null != aTidyOptions.TidyChecks && 0 < aTidyOptions.TidyChecks.Length) { parameters = $"{parameters}{String.Join(",", aTidyOptions.TidyChecks)}''"; } else { foreach (PropertyInfo prop in aTidyChecks.GetType().GetProperties()) { object[] propAttrs = prop.GetCustomAttributes(false); object clangCheckAttr = propAttrs.FirstOrDefault(attr => typeof(ClangCheckAttribute) == attr.GetType()); object displayNameAttrObj = propAttrs.FirstOrDefault(attr => typeof(DisplayNameAttribute) == attr.GetType()); if (null == clangCheckAttr || null == displayNameAttrObj) { continue; } DisplayNameAttribute displayNameAttr = (DisplayNameAttribute)displayNameAttrObj; var value = prop.GetValue(aTidyChecks, null); if (Boolean.TrueString != value.ToString()) { continue; } parameters = $"{parameters},{displayNameAttr.DisplayName}"; } parameters = $"{parameters}''"; } return(parameters); }
public void ConstructParameters(GeneralOptions aGeneralOptions, TidyOptions aTidyOptions, TidyChecks aTidyChecks, TidyCustomChecks aTidyCustomChecks, DTE2 aDte, string aVsEdition, string aVsVersion) { mParameters = GetGeneralParameters(aGeneralOptions); mParameters = null != aTidyOptions ? $"{mParameters} {GetTidyParameters(aTidyOptions, aTidyChecks, aTidyCustomChecks)}" : $"{mParameters} {ScriptConstants.kParallel}"; mParameters = $"{mParameters} {ScriptConstants.kVsVersion} {aVsVersion} {ScriptConstants.kVsEdition} {aVsEdition}"; }
private string GetTidyParameters(TidyOptions aTidyOptions, TidyChecks aTidyChecks, TidyCustomChecks aTidyCustomChecks) { string parameters = string.Empty; if (ComboBoxConstants.kTidyFile == aTidyOptions.UseChecksFrom) { parameters = $"{parameters}{ScriptConstants.kTidyFile}"; mUseTidyFile = true; } else if (ComboBoxConstants.kCustomChecks == aTidyOptions.UseChecksFrom) { if (null != aTidyCustomChecks.TidyChecks && 0 != aTidyCustomChecks.TidyChecks.Length) { parameters = $",{String.Join(",", aTidyCustomChecks.TidyChecks)}"; } } else if (ComboBoxConstants.kPredefinedChecks == aTidyOptions.UseChecksFrom) { foreach (PropertyInfo prop in aTidyChecks.GetType().GetProperties()) { object[] propAttrs = prop.GetCustomAttributes(false); object clangCheckAttr = propAttrs.FirstOrDefault(attr => typeof(ClangCheckAttribute) == attr.GetType()); object displayNameAttrObj = propAttrs.FirstOrDefault(attr => typeof(DisplayNameAttribute) == attr.GetType()); if (null == clangCheckAttr || null == displayNameAttrObj) { continue; } DisplayNameAttribute displayNameAttr = (DisplayNameAttribute)displayNameAttrObj; var value = prop.GetValue(aTidyChecks, null); if (Boolean.TrueString != value.ToString()) { continue; } parameters = $"{parameters},{displayNameAttr.DisplayName}"; } } if (string.Empty != parameters) { parameters = string.Format("{0} ''{1}{2}''", (aTidyOptions.Fix ? ScriptConstants.kTidyFix : ScriptConstants.kTidy), (mUseTidyFile ? "" : "-*"), parameters); } if (!string.IsNullOrWhiteSpace(aTidyOptions.HeaderFilter)) { parameters = string.Format("{0} {1} ''{2}''", parameters, ScriptConstants.kHeaderFilter, ComboBoxConstants.kHeaderFilterMaping.ContainsKey(aTidyOptions.HeaderFilter) ? ComboBoxConstants.kHeaderFilterMaping[aTidyOptions.HeaderFilter] : aTidyOptions.HeaderFilter); } return(parameters); }
protected void RunScript(string aCommandName, TidyOptions mTidyOptions = null, TidyChecks mTidyChecks = null, TidyCustomChecks mTidyCustomChecks = null, ClangFormatPage aClangFormat = null) { try { mCompileTidyScriptBuilder = new ClangCompileTidyScript(); mCompileTidyScriptBuilder.ConstructParameters(mGeneralOptions, mTidyOptions, mTidyChecks, mTidyCustomChecks, aClangFormat, DTEObj, VsEdition, VsVersion); string solutionPath = DTEObj.Solution.FullName; mOutputManager = new OutputManager(DTEObj); InitPowerShell(); ClearWindows(); mOutputManager.AddMessage($"\n{OutputWindowConstants.kStart} {aCommandName}\n"); foreach (var item in mItemsCollector.GetItems) { var script = mCompileTidyScriptBuilder.GetScript(item, solutionPath); if (!mCommandsController.Running) { break; } var process = mPowerShell.Invoke(script, mRunningProcesses); if (mOutputManager.MissingLlvm) { mOutputManager.AddMessage(ErrorParserConstants.kMissingLlvmMessage); break; } } if (!mOutputManager.EmptyBuffer) { mOutputManager.AddMessage(String.Join("\n", mOutputManager.Buffer)); } if (!mOutputManager.MissingLlvm) { mOutputManager.Show(); mOutputManager.AddMessage($"\n{OutputWindowConstants.kDone} {aCommandName}\n"); } if (mOutputManager.HasErrors) { mErrorsManager.AddErrors(mOutputManager.Errors); } } catch (Exception) { mOutputManager.Show(); mOutputManager.AddMessage($"\n{OutputWindowConstants.kDone} {aCommandName}\n"); } }
/// <summary> /// Initializes a new instance of the <see cref="TidyCommand"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> public TidyCommand(Package aPackage, Guid aGuid, int aId) : base(aPackage, aGuid, aId) { mTidyOptions = (TidyOptions)Package.GetDialogPage(typeof(TidyOptions)); mTidyChecks = (TidyChecks)Package.GetDialogPage(typeof(TidyChecks)); mFileOpener = new FileOpener(DTEObj); if (ServiceProvider.GetService(typeof(IMenuCommandService)) is OleMenuCommandService commandService) { var menuCommandID = new CommandID(CommandSet, Id); var menuCommand = new OleMenuCommand(this.MenuItemCallback, menuCommandID); menuCommand.BeforeQueryStatus += mCommandsController.QueryCommandHandler; menuCommand.Enabled = true; commandService.AddCommand(menuCommand); } }
private void SetDefaultTidyPredefindedChecks() { var checks = new StringBuilder(); var tidyCheckModel = new TidyChecks(); var tidyModel = settingsProvider.GetTidySettingsModel(); foreach (TidyCheckModel item in tidyCheckModel.Checks) { if (item.IsChecked) { checks.Append(item.Name).Append(";"); } } checks.Length--; tidyModel.PredefinedChecks = checks.ToString(); }
private string GetTidyParameters(TidyOptions aTidyOptions, TidyChecks aTidyChecks) { string parameters = string.Empty; if (TidyModeConstants.kTidyFile == aTidyOptions.TidyMode) { return(string.Format("{0} {1}", aTidyOptions.Fix ? ScriptConstants.kTidyFix : ScriptConstants.kTidy, ScriptConstants.kTidyFile)); } else if (TidyModeConstants.kCustomChecks == aTidyOptions.TidyMode) { parameters = $",{String.Join(",", aTidyOptions.TidyChecks)}"; } else { foreach (PropertyInfo prop in aTidyChecks.GetType().GetProperties()) { object[] propAttrs = prop.GetCustomAttributes(false); object clangCheckAttr = propAttrs.FirstOrDefault(attr => typeof(ClangCheckAttribute) == attr.GetType()); object displayNameAttrObj = propAttrs.FirstOrDefault(attr => typeof(DisplayNameAttribute) == attr.GetType()); if (null == clangCheckAttr || null == displayNameAttrObj) { continue; } DisplayNameAttribute displayNameAttr = (DisplayNameAttribute)displayNameAttrObj; var value = prop.GetValue(aTidyChecks, null); if (Boolean.TrueString != value.ToString()) { continue; } parameters = $"{parameters},{displayNameAttr.DisplayName}"; } } if (string.Empty != parameters) { parameters = string.Format("{0} ''-*{1}''", (aTidyOptions.Fix ? ScriptConstants.kTidyFix : ScriptConstants.kTidy), parameters); } return(parameters); }
public void ConstructParameters(GeneralOptions aGeneralOptions, TidyOptions aTidyOptions, TidyChecks aTidyChecks, TidyCustomChecks aTidyCustomChecks, ClangFormatPage aClangFormat, DTE2 aDTEObj, string aVsEdition, string aVsVersion) { mParameters = GetGeneralParameters(aGeneralOptions); mParameters = null != aTidyOptions ? $"{mParameters} {GetTidyParameters(aTidyOptions, aTidyChecks, aTidyCustomChecks)}" : $"{mParameters} {ScriptConstants.kParallel}"; if (null != aClangFormat && null != aTidyOptions && true == aTidyOptions.Fix && true == aTidyOptions.FormatAfterTidy) { mParameters = $"{mParameters} {ScriptConstants.kClangFormatStyle} {GetClangFormatParameters(aClangFormat)}"; } mParameters = $"{mParameters} {ScriptConstants.kVsVersion} {aVsVersion} {ScriptConstants.kVsEdition} {aVsEdition}"; }
/// <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) { mCommandsController.Running = true; var task = System.Threading.Tasks.Task.Run(() => { GeneralOptions generalOptions = (GeneralOptions)mPackage.GetDialogPage(typeof(GeneralOptions)); TidyOptions tidyOptions = (TidyOptions)mPackage.GetDialogPage(typeof(TidyOptions)); TidyChecks tidyChecks = (TidyChecks)mPackage.GetDialogPage(typeof(TidyChecks)); ScriptBuiler scriptBuilder = new ScriptBuiler(); scriptBuilder.ConstructParameters(generalOptions, tidyOptions, tidyChecks, mVsEdition, mVsVersion); mItemsCollector = new ItemsCollector(mPackage); mItemsCollector.CollectSelectedFiles(mDte); mOutputManager = new OutputManager(mDte); PowerShellWrapper powerShell = new PowerShellWrapper(); powerShell.DataHandler += mOutputManager.OutputDataReceived; powerShell.DataErrorHandler += mOutputManager.OutputDataErrorReceived; mFileWatcher = new FileChangerWatcher(); try { mDte.Documents.SaveAll(); if (kVs15Version == mVsVersion) { Vs15SolutionLoader solutionLoader = new Vs15SolutionLoader(mPackage); solutionLoader.EnsureSolutionProjectsAreLoaded(); } using (var guard = new SilentFileChangerGuard()) { if (tidyOptions.Fix) { WatchFiles(); SilentFiles(guard); } mOutputManager.Clear(); mOutputManager.Show(); mOutputManager.AddMessage($"\n{OutputWindowConstants.kStart} {OutputWindowConstants.kTidyCodeCommand}\n"); foreach (var item in mItemsCollector.GetItems) { string script = scriptBuilder.GetScript(item.Item1, item.Item1.GetName()); powerShell.Invoke(script); if (mOutputManager.MissingLlvm) { mOutputManager.AddMessage(ErrorParserConstants.kMissingLlvmMessage); break; } } if (!mOutputManager.EmptyBuffer) { mOutputManager.AddMessage(String.Join("\n", mOutputManager.Buffer)); } if (!mOutputManager.MissingLlvm) { mOutputManager.Show(); mOutputManager.AddMessage($"\n{OutputWindowConstants.kDone} {OutputWindowConstants.kTidyCodeCommand}\n"); } if (mOutputManager.HasErrors) { mErrorsManager.AddErrors(mOutputManager.Errors); } } } catch (Exception exception) { VsShellUtilities.ShowMessageBox(mPackage, exception.Message, "Error", OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } }).ContinueWith(tsk => mCommandsController.AfterExecute());; }