Beispiel #1
0
        // todo: rewrite
        private static void SetShowInFindResultsAction(
            [NotNull] GotoWordIndexController controller, [NotNull] LifetimeDefinition definition,
            [NotNull] IShellLocks shellLocks, [NotNull] UITaskExecutor taskExecutor)
        {
            controller.FuncEtcItemExecute.Value = () =>
                                                  shellLocks.ExecuteOrQueueReadLock("ShowInFindResults", () =>
            {
                var filterString = controller.Model.FilterText.Value;
                if (string.IsNullOrEmpty(filterString))
                {
                    return;
                }

                definition.Terminate();

                GotoWordBrowserDescriptor descriptor = null;
                if (taskExecutor.FreeThreaded.ExecuteTask(
                        "Show Files In Find Results", TaskCancelable.Yes, progress =>
                {
                    progress.TaskName = "Collecting words matching '" + filterString + "'";
                    progress.Start(1);

                    var occurrences = new List <IOccurence>();
                    using (ReadLockCookie.Create())
                    {
                        controller.ConsumePresentableItems(
                            filterString, -1, itemsConsumer: (items, behavior) =>
                        {
                            foreach (var item in items)
                            {
                                occurrences.Add(item.Occurence);
                            }
                        });
                    }

                    if (occurrences.Count > 0 && !progress.IsCanceled)
                    {
                        descriptor = new GotoWordBrowserDescriptor(
                            controller.Solution, filterString, occurrences);
                    }

                    progress.Stop();
                }))
                {
                    if (descriptor != null)
                    {
                        FindResultsBrowser.ShowResults(descriptor);
                    }
                }
                else
                {
                    if (descriptor != null)
                    {
                        descriptor.LifetimeDefinition.Terminate();
                    }
                }
            });
        }
        public void Execute(IDataContext context, DelegateExecute nextExecute)
        {
            // Get solution from context in which action is executed
            ISolution solution = context.GetData(ProjectModel.DataContext.DataConstants.SOLUTION);

            if (solution == null)
            {
                return;
            }

            var documentManager = solution.GetComponent <DocumentManager>();
            var shellLocks      = solution.GetComponent <IShellLocks>();
            var settingStore    = solution.GetComponent <ISettingsStore>();
            var mainWindow      = solution.GetComponent <IMainWindow>();

            // Ask user about search string
            FindTextSearchRequest searchRequest;

            using (var dialog = new EnterSearchStringDialog(settingStore.BindToContextTransient(ContextRange.Smart((lt, contexts) => context))))
            {
                if (dialog.ShowDialog(mainWindow) != DialogResult.OK)
                {
                    return;
                }

                // Create request, descriptor, perform search and show results
                searchRequest = new FindTextSearchRequest(solution, dialog.SearchString, dialog.CaseSensitive, dialog.SearchFlags, documentManager);
            }

            using (shellLocks.UsingReadLock())
            {
                var descriptor = new FindTextDescriptor(searchRequest);
                descriptor.Search();
                FindResultsBrowser.ShowResults(descriptor);
            }
        }
Beispiel #3
0
            public void Execute(IDataContext context, DelegateExecute nextExecute)
            {
                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 symbolCollector = new CollectSymbolsAndRefsInSpanAstVisitor(new NSpan(pos));
                    nitraFile.Ast.Accept(symbolCollector);


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

                    var symbols = symbolCollector.Refs.Where(r => r.IsSymbolEvaluated).Select(r => r.Symbol).ToArray();

                    if (symbols.Length == 0)
                    {
                        if (symbolCollector.Names.Count == 0)
                        {
                            return;
                        }

                        symbols = symbolCollector.Names.Where(n => n.IsSymbolEvaluated).Select(n => n.Symbol).ToArray();
                    }

                    List <IOccurence> items = new List <IOccurence>();
                    var s = nitraFile.Project.Solution;

                    foreach (var p in s.Projects)
                    {
                        foreach (var file in p.Files)
                        {
                            foreach (var symbol in symbols)
                            {
                                var collectRefs = new CollectSymbolRefsAstVisitor(symbol);
                                file.Ast.Accept(collectRefs);

                                foreach (var r in collectRefs.FoundSymbols)
                                {
                                    var refNitraFile = r.File as XXLanguageXXFile; // TODO: add INitraReSharperFile
                                    if (refNitraFile == null)
                                    {
                                        continue;
                                    }
                                    items.Add(new RangeOccurence(refNitraFile.PsiSourceFile, new DocumentRange(refNitraFile.Document, new TextRange(r.Span.StartPos, r.Span.EndPos))));
                                }
                            }
                        }
                    }

                    var descriptor = new NitraOccurenceBrowserDescriptor(solution, items);
                    FindResultsBrowser.ShowResults(descriptor);
                }
                nextExecute();
            }