Esempio n. 1
0
        public static void Add(string file, ITextSnapshot snapshot)
        {
            var fileInCache = false;

            lock (CacheLock)
            {
                fileInCache = Cache.ContainsKey(file);
            }

            if (fileInCache)
            {
                Update(file, snapshot);
            }
            else
            {
                // Don't worry about timing this call as it's only repeated calls to analyze a document that might cause a user prompt.
                // This only happens on document open. Repeated analysis of a document will happen through TryUpdate.
                var doc = RapidXamlDocument.Create(snapshot, file, vsa, string.Empty);

                lock (CacheLock)
                {
                    Cache.Add(file, doc);
                }

                Parsed?.Invoke(null, new RapidXamlParsingEventArgs(doc, file, snapshot, ParsedAction.Add));
            }
        }
        public static RapidXamlDocument Create(ITextSnapshot snapshot)
        {
            var result = new RapidXamlDocument();

            try
            {
                var text = snapshot.GetText();

                // TODO: review when to redo tags, etc, while invalid, or remove any tags created previously
                if (text.IsValidXml())
                {
                    result.RawText = text;

                    XamlElementExtractor.Parse(snapshot, text, GetAllProcessors(), result.Tags);
                }
            }
            catch (Exception e)
            {
                result.Tags.Add(new UnexpectedErrorTag(new Span(0, 0), snapshot)
                {
                    Description     = StringRes.Error_XamlAnalysisDescription,
                    ExtendedMessage = StringRes.Error_XamlAnalysisExtendedMessage.WithParams(e),
                });

                RapidXamlPackage.Logger?.RecordException(e);
            }

            return(result);
        }
        public static void Add(string file, ITextSnapshot snapshot)
        {
            var fileInCache = false;

            lock (CacheLock)
            {
                fileInCache = Cache.ContainsKey(file);
            }

            if (fileInCache)
            {
                Update(file, snapshot);
            }
            else
            {
                var doc = RapidXamlDocument.Create(snapshot, file, vsa);

                lock (CacheLock)
                {
                    Cache.Add(file, doc);
                }

                Parsed?.Invoke(null, new RapidXamlParsingEventArgs(doc, file, snapshot, ParsedAction.Add));
            }
        }
        public static void Update(string file, ITextSnapshot snapshot)
        {
            var snapshotText = snapshot.GetText();

            bool alreadyCached = false;

            lock (CacheLock)
            {
                alreadyCached = Cache.ContainsKey(file) && Cache[file].RawText == snapshotText;
            }

            if (!alreadyCached)
            {
                if (!CurrentlyProcessing.Contains(snapshotText))
                {
                    try
                    {
                        CurrentlyProcessing.Add(snapshotText);

                        var doc = RapidXamlDocument.Create(snapshot, file, vsa);

                        lock (CacheLock)
                        {
                            Cache[file] = doc;
                        }

                        Parsed?.Invoke(null, new RapidXamlParsingEventArgs(doc, file, snapshot, ParsedAction.Update));
                    }
                    finally
                    {
                        CurrentlyProcessing.Remove(snapshotText);
                    }
                }
            }
        }
 public RapidXamlParsingEventArgs(RapidXamlDocument document, string file, ITextSnapshot snapshot, ParsedAction action)
 {
     this.Document = document;
     this.File     = file;
     this.Snapshot = snapshot;
     this.Action   = action;
 }
Esempio n. 6
0
        public static void Add(string file, ITextSnapshot snapshot)
        {
            if (Cache.ContainsKey(file))
            {
                Update(file, snapshot);
            }
            else
            {
                var doc = RapidXamlDocument.Create(snapshot);
                Cache.Add(file, doc);

                Parsed?.Invoke(null, new RapidXamlParsingEventArgs(doc, file, snapshot, ParsedAction.Add));
            }
        }
Esempio n. 7
0
        public static void Update(string file, ITextSnapshot snapshot)
        {
            var snapshotText = snapshot.GetText();

            if (Cache[file].RawText != snapshotText)
            {
                if (!CurrentlyProcessing.Contains(snapshotText))
                {
                    try
                    {
                        CurrentlyProcessing.Add(snapshotText);

                        var doc = RapidXamlDocument.Create(snapshot);
                        Cache[file] = doc;

                        Parsed?.Invoke(null, new RapidXamlParsingEventArgs(doc, file, snapshot, ParsedAction.Update));
                    }
                    finally
                    {
                        CurrentlyProcessing.Remove(snapshotText);
                    }
                }
            }
        }
Esempio n. 8
0
        public static void Update(string file, ITextSnapshot snapshot)
        {
            var snapshotText = snapshot.GetText();

            bool alreadyCached = false;

            lock (CacheLock)
            {
                alreadyCached = Cache.ContainsKey(file) && Cache[file].RawText == snapshotText;
            }

            if (!alreadyCached)
            {
                if (!CurrentlyProcessing.Contains(snapshotText))
                {
                    try
                    {
                        CurrentlyProcessing.Add(snapshotText);

                        RapidXamlDocument doc;

                        var sw = new Stopwatch();
                        try
                        {
                            sw.Start();

                            doc = RapidXamlDocument.Create(snapshot, file, vsa, string.Empty);
                        }
                        finally
                        {
                            sw.Stop();

                            var elapsed   = sw.Elapsed;
                            var threshold = TimeSpan.FromSeconds(1.5);

                            Debug.WriteLine($"Document anlaysis took:  {elapsed}");

                            var analyzeOnSave = true;
#if VSIXNOTEXE
                            analyzeOnSave = RapidXamlAnalysisPackage.Options?.AnalyzeWhenDocumentSaved ?? false;
#endif

                            // Don't prompt about a single execution time greater than the threshold
                            if (elapsed > threshold &&
                                lastAnalysisTime > threshold &&
                                analyzeOnSave == true &&
                                !havePromptedForSaveAnalysisPerformance)
                            {
                                SharedRapidXamlPackage.Logger?.RecordFeatureUsage(MiscellaneousFeatures.PromptToDisableAnalysisOnSave, quiet: true);
                                RxtOutputPane.Instance.Write(StringRes.Info_PromptToDisableAnalysisOnSave);
                                RxtOutputPane.Instance.Activate(); // To increase the likelihood that it's seen

                                havePromptedForSaveAnalysisPerformance = true;
                            }

                            lastAnalysisTime = elapsed;
                        }

                        lock (CacheLock)
                        {
                            Cache[file] = doc;
                        }

                        Parsed?.Invoke(null, new RapidXamlParsingEventArgs(doc, file, snapshot, ParsedAction.Update));
                    }
                    finally
                    {
                        CurrentlyProcessing.Remove(snapshotText);
                    }
                }
            }
        }