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 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 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 static MarkdownDocument ParseToMarkdown(this ITextSnapshot snapshot, string file = null) { lock (_syncRoot) { return(CachedDocuments.GetValue(snapshot, key => { var text = key.GetText(); var markdownDocument = ParseToMarkdown(text); Parsed?.Invoke(snapshot, new ParsingEventArgs(markdownDocument, file, snapshot)); return markdownDocument; })); } }
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)); } }
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); } } } }
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); } } } }
private System.Threading.Tasks.Task ParseAsync() { IsParsing = true; return(System.Threading.Tasks.Task.Run(() => { var items = new List <ParseItem>(); var sections = new List <Section>(); var properties = new List <Property>(); Suppressions = new List <string>(); Section parentSection = null; foreach (ITextSnapshotLine line in TextBuffer.CurrentSnapshot.Lines) { string text = line.GetText(); if (string.IsNullOrWhiteSpace(text)) { continue; } // Suppression if (IsMatch(_suppress, text, out var match)) { ParseItem comment = CreateParseItem(ItemType.Comment, line, match.Groups["comment"]); AddToList(items, comment); Group errorsGroup = match.Groups["errors"]; string value = errorsGroup.Value; var c = new Regex(@"\w+"); foreach (Match code in c.Matches(match.Value, errorsGroup.Index)) { ParseItem errors = CreateParseItem(ItemType.Suppression, line, code); AddToList(items, errors); if (!Suppressions.Contains(code.Value) && ErrorCatalog.All.Any(ec => ec.Code == code.Value)) { Suppressions.Add(code.Value); } } } // Comment else if (IsMatch(_comment, text, out match)) { ParseItem comment = CreateParseItem(ItemType.Comment, line, match); AddToList(items, comment); } // Section else if (IsMatch(_section, text, out match)) { ParseItem section = CreateParseItem(ItemType.Section, line, match.Groups["section"]); AddToList(items, section); var s = new Section(section); sections.Add(s); parentSection = s; } // Property else if (IsMatch(_property, text, out match)) { ParseItem keyword = CreateParseItem(ItemType.Keyword, line, match.Groups["keyword"]); AddToList(items, keyword); var property = new Property(keyword); if (parentSection == null) { properties.Add(property); } else { parentSection.Properties.Add(property); } if (match.Groups["value"].Success) { ParseItem value = CreateParseItem(ItemType.Value, line, match.Groups["value"]); AddToList(items, value); property.Value = value; } if (match.Groups["severity"].Success) { ParseItem severity = CreateParseItem(ItemType.Severity, line, match.Groups["severity"]); AddToList(items, severity); property.Severity = severity; } } if (match.Success && match.Length < text.Length) { string remaining = text.Substring(match.Length); if (!string.IsNullOrEmpty(remaining) && IsMatch(_unknown, remaining, out Match unknownMatch)) { Group group = unknownMatch.Groups["unknown"]; if (!string.IsNullOrWhiteSpace(group.Value)) { var span = new Span(line.Start + match.Length + group.Index, group.Length); var unknown = new ParseItem(this, ItemType.Unknown, span, remaining); AddToList(items, unknown); } } } } ParseItems = items; Sections = sections; Properties = properties; IsParsing = false; Parsed?.Invoke(this, EventArgs.Empty); })); }
virtual protected void OnParsed(DataParserEventArgs e) => Parsed?.Invoke(this, e);