示例#1
0
        void RefreshSymbolDatabase()
        {
            if (null == mFiles || !mFiles.Any())
            {
                return;
            }

            ReadSymbolDatabase();

            List <string> lToGenerate = new List <string>();

            foreach (FileData fileData in mFiles.Values)
            {
                if (fileData.LastSymbolsGeneration == DateTime.MinValue ||
                    fileData.LastSymbolsGeneration < System.IO.File.GetLastWriteTime(fileData.Path)
                    )
                {
                    lToGenerate.Add(fileData.Path);
                }
            }

            EnvDTE.StatusBar  sbar           = Common.Instance.DTE2.StatusBar;
            Action <int, int> progressAction = (current, total) =>
            {
                if ((current % 5) == 0)
                {
                    sbar.Progress(true, "QuickNavigation Scan solution " + current + "/" + total, current, total);
                }
            };
            IEnumerable <SymbolData> symbols = CTagsGenerator.GeneratorFromFiles(lToGenerate, progressAction);


            sbar.Progress(false, "QuickNavigation Analysing solution ...", 0, 0);

            //Associate symbols to DileData
            symbols
            .AsParallel()
            .GroupBy(symbol => symbol.AssociatedFile)
            .ForAll(pair => pair.Key.SetSymbols(pair));

            sbar.Progress(false);

            WriteSymbolDatabase();
        }
        private void GotoCurrentWord(object sender, EventArgs e)
        {
            string sCurrentWord = CommonUtils.GetCurrentWord();
            int    iCurrentLine = CommonUtils.GetCurrentLine();
            string sCurrentFile = Common.Instance.DTE2.ActiveDocument.FullName.ToLower();

            Data.SymbolData originSymbol = null;
            Data.SymbolData symbol       = null;
            //Search in local file
            IEnumerable <Data.SymbolData> documentSymbols = CTagsGenerator.GeneratorFromDocument(Common.Instance.DTE2.ActiveDocument);

            IEnumerable <Data.SymbolData> solutionSymbols = Common.Instance.SolutionWatcher.Files
                                                            .AsParallel()
                                                            .Where(file => file != null && file.Symbols != null)
                                                            .SelectMany(file => file.Symbols)
            ;

            if (documentSymbols != null)
            {
                originSymbol = documentSymbols.Where(s => s.StartLine == iCurrentLine && s.Symbol.Contains(sCurrentWord)).FirstOrDefault();
            }

            if (originSymbol != null)
            {
                if (originSymbol.Type == Data.SymbolData.ESymbolType.Method)
                {
                    //Search prototype
                    symbol = solutionSymbols.Where(s => s.Type == Data.SymbolData.ESymbolType.MethodPrototype && s.Class == originSymbol.Class && s.Symbol == originSymbol.Symbol).FirstOrDefault();
                }
                else if (originSymbol.Type == Data.SymbolData.ESymbolType.MethodPrototype)
                {
                    //Search method
                    symbol = solutionSymbols.Where(s => s.Type == Data.SymbolData.ESymbolType.Method && s.Class == originSymbol.Class && s.Symbol == originSymbol.Symbol).FirstOrDefault();
                }
            }

            if (symbol == null && documentSymbols != null)
            {
                IEnumerable <Data.SymbolData> filtered = documentSymbols.Where(s => s.StartLine < iCurrentLine && s.Symbol.Contains(sCurrentWord));
                int iCount = filtered.Count();
                if (iCount == 1)
                {
                    symbol = filtered.First();
                }
                else if (iCount > 1)
                {
                    symbol = filtered.OrderBy(s => s.Type).First();
                }
            }

            // Search in solution
            if (symbol == null)
            {
                IEnumerable <Data.SymbolData> filtered = solutionSymbols
                                                         .Where(s => s.Symbol.Contains(sCurrentWord) && (s.StartLine != iCurrentLine || s.AssociatedFile.Path.ToLower() != sCurrentFile));
                int iCount = filtered.Count();
                if (iCount == 1)
                {
                    symbol = filtered.First();
                }
                else if (iCount > 1)
                {
                    symbol = filtered.OrderBy(s => s.Type).First();
                }
            }

            if (symbol != null)
            {
                CommonUtils.GotoSymbol(symbol);
            }
        }
示例#3
0
 public void GenerateSymbols()
 {
     SetSymbols(CTagsGenerator.GeneratorFromFile(Path));
 }
        private void RefreshResults()
        {
            if (null != mToken)
            {
                mToken.Cancel();
            }
            mToken = new CancellationTokenSource();

            string sSearch = textBox.Text;

            System.Threading.Tasks.Task.Run(() =>
            {
                lock (mSymbolLocker)
                {
                    if (!mToken.IsCancellationRequested)
                    {
                        if (!mSearchInSolution && mSymbols == null)
                        {
                            mSymbols = CTagsGenerator.GeneratorFromDocument(Common.Instance.DTE2.ActiveDocument);
                        }

                        try
                        {
                            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                            //sw.Start();

                            ParallelQuery <SymbolData> source = null;
                            if (mSearchInSolution)
                            {
                                source = Common.Instance.SolutionWatcher.Files
                                         .AsParallel()
                                         .WithCancellation(mToken.Token)
                                         .Where(file => file != null && file.Symbols != null)
                                         .SelectMany(file => file.Symbols)
                                ;
                            }
                            else
                            {
                                source = mSymbols
                                         .AsParallel()
                                         .WithCancellation(mToken.Token)
                                ;
                            }

                            ParallelQuery <SearchResultData <SymbolData> > results = source
                                                                                     .Where(symbol => (symbol.Type & mSupportedSymbolTypes) != 0)
                                                                                     .Select(symbolData => new SearchResultData <SymbolData>(symbolData, sSearch, symbolData.Symbol, null, symbolData.Class, symbolData.Parameters));

                            int total = results.Count();

                            if (!string.IsNullOrWhiteSpace(sSearch))
                            {
                                int searchStringLen = sSearch.Length;
                                results             = results.Where(resultData => resultData.SearchScore > searchStringLen);
                            }

                            results = results
                                      .OrderByDescending(resultData => resultData.SearchScore)
                            ;

                            int count = results.Count();

                            //EnvDTE.FontsAndColorsItems fontsAndColor = Common.Instance.DTE2.Properties.Item("FontsAndColorsItems") as EnvDTE.FontsAndColorsItems;
                            //fontsAndColor.Item("Line Number").Foreground
                            //fontsAndColor.Item("Keywords").Foreground

                            /*Action<IEnumerable> refreshMethod = (res) =>
                             * {
                             *      results.ForAll(result => result.RefreshSearchFormatted());
                             * };
                             * Dispatcher.BeginInvoke(refreshMethod, results);*/

                            Action <IEnumerable> setMethod = (res) =>
                            {
                                listView.ItemsSource = res;

                                string title = mQuickMethodToolWindow.Title;
                                int pos      = title.IndexOf(" [");
                                if (pos != -1)
                                {
                                    title = title.Substring(0, pos);
                                }
                                mQuickMethodToolWindow.Title = title + " [" + count + "/" + total + "]";
                            };
                            Dispatcher.Invoke(setMethod, results.ToList());


                            //sw.Stop();
                            //System.Diagnostics.Debug.WriteLine("PLINQ time " + sw.Elapsed.TotalMilliseconds);
                        }
                        catch (Exception) { }
                    }
                }
            });
        }