private void AddBraces( TaggerContext <BraceHighlightTag> context, ITextSnapshot snapshot, BraceMatchingResult?braces) { if (braces.HasValue) { context.AddTag(snapshot.GetTagSpan(braces.Value.LeftSpan.ToSpan(), BraceHighlightTag.StartTag)); context.AddTag(snapshot.GetTagSpan(braces.Value.RightSpan.ToSpan(), BraceHighlightTag.EndTag)); } }
private async Task ProduceTagsForBracesAsync(TaggerContext <BraceHighlightTag> context, Document document, ITextSnapshot snapshot, int position, bool rightBrace) { if (position >= 0 && position <= snapshot.Length) { var braces = await _braceMatcherService.GetMatchingBracesAsync(document, position, context.CancellationToken).ConfigureAwait(false); if (braces.HasValue) { if ((!rightBrace && braces.Value.LeftSpan.Start == position) || (rightBrace && braces.Value.RightSpan.Start == position)) { context.AddTag(snapshot.GetTagSpan(braces.Value.LeftSpan.ToSpan(), BraceHighlightTag.StartTag)); context.AddTag(snapshot.GetTagSpan(braces.Value.RightSpan.ToSpan(), BraceHighlightTag.EndTag)); } } } }
private async Task ProduceTagsAsync(TaggerContext <BraceHighlightTag> context, Document document, ITextSnapshot snapshot, int position) { var syntaxTree = await document.GetSyntaxTreeAsync(context.CancellationToken).ConfigureAwait(false); var braceMatcher = document.LanguageServices.GetService <IBraceMatcher>(); if (braceMatcher == null) { return; } var mappedPosition = syntaxTree.MapRootFilePosition(position); var result = braceMatcher.FindBraces(syntaxTree, mappedPosition, context.CancellationToken); if (result == null) { return; } context.AddTag(snapshot.GetTagSpan(result.Value.LeftSpan.ToSpan(), BraceHighlightTag.Tag)); context.AddTag(snapshot.GetTagSpan(result.Value.RightSpan.ToSpan(), BraceHighlightTag.Tag)); }
private static void AddDiagnostics(TaggerContext <IErrorTag> context, IEnumerable <MappedDiagnostic> mappedDiagnostics, ITextSnapshot snapshot) { foreach (var mappedDiagnostic in mappedDiagnostics) { context.CancellationToken.ThrowIfCancellationRequested(); if (!mappedDiagnostic.FileSpan.IsInRootFile) { continue; } var errorType = mappedDiagnostic.Diagnostic.Severity == DiagnosticSeverity.Warning ? PredefinedErrorTypeNames.Warning : (mappedDiagnostic.Source == DiagnosticSource.SyntaxParsing ? PredefinedErrorTypeNames.SyntaxError : PredefinedErrorTypeNames.CompilerError); var tag = new ErrorTag(errorType, mappedDiagnostic.Diagnostic.Message); context.AddTag(snapshot.GetTagSpan(mappedDiagnostic.FileSpan.Span.ToSpan(), tag)); } }