예제 #1
0
        private void UpdateWordAdornments()
        {
            //Find the new spans
            try
            {
                var store           = DocumentScriptCosters.GetInstance().GetCoster();
                var yellowWordSpans = new List <SnapshotSpan>();
                var redWordSpans    = new List <SnapshotSpan>();

                if (null != store)
                {
                    var statements = store.GetCosts();
                    if (statements != null)
                    {
                        foreach (var s in statements)
                        {
                            if (s.Band == CostBand.Medium)
                            {
                                var findData = new FindData(s.Text, RequestedPoint.Snapshot);
                                findData.FindOptions = FindOptions.Multiline | FindOptions.Wrap;
                                yellowWordSpans.AddRange(TextSearchService.FindAll(findData));
                            }

                            if (s.Band == CostBand.High)
                            {
                                var findData = new FindData(s.Text, RequestedPoint.Snapshot);
                                findData.FindOptions = FindOptions.Multiline | FindOptions.Wrap;
                                redWordSpans.AddRange(TextSearchService.FindAll(findData));
                            }
                        }
                    }
                }

                var currentRequest = RequestedPoint;
                var word           = TextStructureNavigator.GetExtentOfWord(currentRequest);
                var currentWord    = word.Span;


                //If another change hasn't happened, do a real update
                if (currentRequest == RequestedPoint)
                {
                    SynchronousUpdate(currentRequest, new NormalizedSnapshotSpanCollection(yellowWordSpans),
                                      new NormalizedSnapshotSpanCollection(redWordSpans), currentWord);
                }
            }

            catch (Exception e)
            {
                MessageBox.Show("2 - e : " + e.Message + " \r\n " + e.StackTrace);
            }
        }
예제 #2
0
        private void ToggleQueryCosts(object sender, EventArgs e)
        {
            try
            {
                var dte = (DTE)GetService(typeof(DTE));

                if (dte.ActiveDocument == null)
                {
                    return;
                }

                var doc = dte.ActiveDocument.Object("TextDocument") as TextDocument;
                if (null == doc)
                {
                    return;
                }

                var ep = doc.StartPoint.CreateEditPoint();

                ep.EndOfDocument();

                var length = ep.AbsoluteCharOffset;
                ep.StartOfDocument();

                var originalText = ep.GetText(length);

                DocumentScriptCosters.SetDte(dte);

                var coster = DocumentScriptCosters.GetInstance().GetCoster();
                if (coster == null)
                {
                    return;
                }

                if (coster.ShowCosts)
                {
                    coster.ShowCosts = false;
                }
                else
                {
                    coster.ShowCosts = true;
                    coster.AddCosts(originalText, dte.ActiveDocument);
                }
            }
            catch (Exception ee)
            {
                OutputPane.WriteMessage("ToggleQueryCosts error: {0}", ee.Message);
                Log.WriteInfo("ToggleQueryCosts error: {0}", ee.Message);
            }
        }
예제 #3
0
        public override GlyphDefinition GetDefintions(string fragment, TSqlStatement statement, GlyphDefinition definition, List <QuerySpecification> queries)
        {
            var documentCoster = DocumentScriptCosters.GetInstance();

            if (documentCoster == null)
            {
                return(definition);
            }

            var coster = documentCoster.GetCoster();

            if (null == coster)
            {
                return(definition);
            }

            var statements = coster.GetCosts();

            if (statements == null || statements.Count == 0)
            {
                return(definition);
            }

            var thisStatement = fragment;

            var costedStatement =
                statements.FirstOrDefault(p => p.Text.IndexOf(thisStatement, StringComparison.OrdinalIgnoreCase) > 0);

            if (costedStatement == null)
            {
                return(definition);
            }

            definition.Menu.Add(new MenuDefinition
            {
                Action  = null,
                Caption = "Query Cost: " + costedStatement.Cost,
                Type    = MenuItemType.Header
            });

            return(definition);
        }
 private void ClearQueryCosts(object sender, EventArgs e)
 {
     DocumentScriptCosters.GetInstance().ClearCache();
 }