private IEnumerable <BulbActionKey> GetBulbActionKeys(IDataContext context) { var bulbItems = context.GetComponent <BulbItems>(); if (bulbItems.BulbItemsState.Value == null) { return(null); } var bulbItemsState = bulbItems.BulbItemsState.Value; if (bulbItemsState.BulbItemsStates == BulbItemsStates.Invalidated) { return(null); } if (bulbItemsState.IntentionsBulbItems == null || !bulbItemsState.IntentionsBulbItems.AllBulbMenuItems.Any()) { return(null); } var bulbActionKeys = bulbKeysBuilder.BuildMenuKeys(bulbItemsState.IntentionsBulbItems.AllBulbMenuItems); return(bulbActionKeys); }
private void DumpQuickFixesAvailability( [NotNull] TextWriter writer, [NotNull] IEnumerable <HighlightingInfo> highlightings, [NotNull] ITextControl textControl, [NotNull] ISolution solution) { var sourceFile = textControl.Document.GetPsiSourceFile(solution).NotNull("sourceFile != null"); var quickFixesTable = solution.GetComponent <IQuickFixes>(); var quickFixesProvider = solution.GetComponent <QuickFixesProvider>(); var locks = solution.Locks; var boundSettingsStore = sourceFile.GetLazySettingsStoreWithEditorConfig(Solution); var filteredHighlightings = highlightings.Where( info => info.Highlighting.IsValid() && info.Overlapped != OverlapKind.OVERLAPPED_BY_ERROR && HighlightingPredicate(info.Highlighting, sourceFile, boundSettingsStore)); IList <HighlightingInfo> sourtedHighlightings; IList <TestFrameworkUtil.Position> sortedHighlightingPositions; TestFrameworkUtil.SortItems( filteredHighlightings, HighlightingComparer.Instance, info => info.Range, out sourtedHighlightings, out sortedHighlightingPositions); var text = sourceFile.Document.Buffer; var i = -1; TestFrameworkUtil.DumpReferencePositions(writer, text, sortedHighlightingPositions); foreach (var info in sourtedHighlightings) { ICollection <IQuickFix> quickFixes; using (ReadLockCookie.Create()) { var sourceHighlighting = info.Highlighting; if (sourceHighlighting is IDelegatingHighlighting delegatingHighlighting) { sourceHighlighting = delegatingHighlighting.DelegatesTo; } quickFixes = quickFixesTable.CreateAvailableQuickFixes(sourceHighlighting, new UserDataHolder()); quickFixes = quickFixes.Where(QuickFixPredicate).ToList(); } i++; if (FilterEmptyHighlighting() && quickFixes.IsEmpty()) { continue; } writer.WriteLine("{0}: {1}", i, info.Highlighting.ToolTip); var scopedIntentionsManager = solution.GetComponent <ScopedIntentionsManager>(); var bulbItems = quickFixes .SelectMany( quickFix => scopedIntentionsManager.GetScopedIntentions(quickFix, solution, textControl)) .Select(intentionAction => quickFixesProvider.CreateBulbMenuItem(intentionAction, textControl, info.Highlighting, sourceFile, boundSettingsStore)) .ToList(); if (bulbItems.Count > 0) { var keys = BulbKeysBuilder.BuildMenuKeys(bulbItems); writer.WriteLine("QUICKFIXES:"); using (ReadLockCookie.Create()) { EventHandler <BeforeAcquiringWriteLockEventArgs> assertWriteLock = (sender, args) => { Assert.Fail( "Cannot take WriteLock in QuickFix.IsAvailabe(). WriteLock can be taken only on Primary thread."); }; locks.ContentModelLocks.BeforeAcquiringWriteLock += assertWriteLock; try { BulbMenuTestBase.Write(keys, "", writer); } finally { locks.ContentModelLocks.BeforeAcquiringWriteLock -= assertWriteLock; } } } else { writer.WriteLine("NO QUICKFIXES"); } } }