public virtual void Execute([NotNull] Lifetime lifetime, [NotNull] ITextControl textControl,
                                    [NotNull] IList <PrefixExpressionContext> expressions,
                                    [NotNull] string postfixText, [NotNull] string chooserTitle,
                                    [NotNull] Action <int> continuation)
        {
      #pragma warning disable 618
            if (Shell.Instance.IsTestShell)
      #pragma warning restore 618
            {
                continuation(0);
                return;
            }

            var popupMenu = myPopupMenus.CreateWithLifetime(lifetime);

            popupMenu.Caption.Value      = WindowlessControl.Create(chooserTitle);
            popupMenu.PopupWindowContext = new TextControlPopupWindowContext(
                lifetime, textControl, myShellLocks, myActionManager);

            // advise selected element to highlight expression
            popupMenu.SelectedItemKey.Change.Advise(lifetime, args =>
            {
                if (!args.HasNew)
                {
                    return;
                }

                var menuItem = args.New as SimpleMenuItem;
                if (menuItem == null)
                {
                    return;
                }

                var range = menuItem.Tag as TextRange?;
                if (range != null)
                {
                    UpdateHighlighting(textControl, range.Value);
                }
            });

            // build menu items from expressions
            var items = new LocalList <SimpleMenuItem>(expressions.Count);
            var index = 0;

            foreach (var expressionContext in expressions)
            {
                TextRange range;
                var       expressionText = PresentExpression(expressionContext, postfixText, out range);

                var itemIndex = index++;
                // ReSharper disable once UseObjectOrCollectionInitializer
                var menuItem = new SimpleMenuItem(
                    expressionText, BulbThemedIcons.YellowBulb.Id, () => continuation(itemIndex));

                menuItem.Tag = range;
                items.Add(menuItem);
            }

            popupMenu.SetItems(items.ToArray());

            var definition = Lifetimes.Define(lifetime);

            // handle menu close
            definition.Lifetime.AddAction(() =>
            {
                UpdateHighlighting(textControl, TextRange.InvalidRange);
            });

            popupMenu.Show(JetPopupMenu.ShowWhen.AutoExecuteIfSingleItem, definition);
        }
            public void Execute(IDataContext context, DelegateExecute nextExecute)
            {
                var callNext = true;

                try
                {
                    var solution = context.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
                    if (solution != null)
                    {
                        var documentOffset = context.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT_OFFSET);
                        if (documentOffset == null)
                        {
                            return;
                        }

                        //var psiServices = solution.GetPsiServices();
                        var psiFile = documentOffset.Document.GetPsiSourceFile(solution);
                        if (psiFile == null)
                        {
                            return;
                        }
                        var projectFile = psiFile.ToProjectFile();
                        if (projectFile == null)
                        {
                            return;
                        }
                        var project = projectFile.GetProject();
                        if (project == null)
                        {
                            return;
                        }
                        var nitraProject = _nitraSolution.GetProject(project);
                        if (nitraProject == null)
                        {
                            return;
                        }
                        var nitraFile = nitraProject.TryGetFile(projectFile);
                        if (nitraFile == null)
                        {
                            return;
                        }

                        var pos     = documentOffset.Value;
                        var visitor = new CollectSymbolsAndRefsInSpanAstVisitor(new NSpan(pos));
                        nitraFile.Ast.Accept(visitor);

                        var popupWindowContext = context.GetData(JetBrains.UI.DataConstants.PopupWindowContextSource);
                        if (popupWindowContext == null)
                        {
                            return;
                        }

                        var decls = visitor.Refs.Where(r => r.IsSymbolEvaluated).SelectMany(r => r.Symbol.Declarations).Where(d => !d.File.IsFake).ToArray();

                        if (decls.Length == 0)
                        {
                            if (visitor.Names.Count == 0)
                            {
                                return;
                            }

                            decls = visitor.Names.Where(n => n.IsSymbolEvaluated).SelectMany(n => n.Symbol.Declarations).Where(d => !d.File.IsFake).ToArray();
                        }

                        if (decls.Length == 0)
                        {
                            return;
                        }
                        if (decls.Length == 1)
                        {
                            Navigate(decls[0], solution, project, popupWindowContext);
                        }
                        else
                        {
                            callNext = false;
                            var jetPopupMenus = _nitraSolution._jetPopupMenus;
                            jetPopupMenus.Show(_lifetime, JetPopupMenu.ShowWhen.NoItemsBannerIfNoItems, (lifetime, menu) =>
                            {
                                menu.ItemKeys.AddRange(Sorter(decls));
                                menu.PopupWindowContext = popupWindowContext.Create(lifetime);
                                menu.Caption.Value      = WindowlessControl.Create("Declaration of " + string.Join(", ", decls.Select(d => d.Name.Text)));
                                menu.NoItemsBanner      = WindowlessControl.Create("There are no declarations.");
                                menu.DescribeItem.Advise(lifetime, args =>
                                {
                                    var decl = (Declaration)args.Key;
                                    var loc  = decl.Name.ToLocation();

                                    //args.Descriptor.Style |= MenuItemStyle.Enabled;
                                    args.Descriptor.Style  |= visitor.Names.Contains(decl.Name) ? MenuItemStyle.None : args.Descriptor.Style = MenuItemStyle.Enabled;
                                    args.Descriptor.Text    = new RichText(Path.GetFileName(decl.File.FullName)).Append(" ").Append("(" + loc.EndLineColumn + ")", TextStyle.FromForeColor(Color.RoyalBlue));
                                    args.Descriptor.Tooltip =
                                        new RichText(decl.Symbol.Kind, TextStyle.FromForeColor(Color.Blue))
                                        .Append(" ")
                                        .Append(decl.Name.Text, new TextStyle(FontStyle.Bold));
                                    //args.Descriptor.ShortcutText = XamlToRichText(decl.ToXaml());
                                    //args.Descriptor.Icon = ;
                                });
                                menu.ItemClicked.Advise(lifetime, arg => _shellLocks.ExecuteOrQueueReadLock("Nitra GoTo Declaration", () =>
                                {
                                    var decl = (Declaration)arg;
                                    Navigate(decl, solution, project, popupWindowContext);
                                }));
                            });
                        }
                    }
                }
                finally
                {
                    if (callNext)
                    {
                        nextExecute();
                    }
                }
            }