public void PublishDiagnostics(Uri uri, Buffer buffer) { var text = buffer.GetText(0, buffer.Length); var syntaxTree = Parser.Parse(buffer); var textPositions = new TextPositions(text); var diagnostics = new List <Diagnostic>(); diagnostics.AddRange(ValidateAgainstSchema(text)); diagnostics.AddRange(ValidateTemplatedValues(syntaxTree, textPositions)); _router.Document.PublishDiagnostics(new PublishDiagnosticsParams { Uri = uri, Diagnostics = diagnostics }); }
private IEnumerable <Diagnostic> ValidateTemplatedValues(XmlDocumentSyntax syntaxTree, TextPositions textPositions) { foreach (var node in syntaxTree.DescendantNodesAndSelf().OfType <XmlTextSyntax>()) { if (!TemplatedValues.Any(x => node.Value.Contains(x, StringComparison.OrdinalIgnoreCase))) { continue; } var range = textPositions.GetRange(node.Start, node.End); yield return(new Diagnostic { Message = "Templated value which should be removed", Severity = DiagnosticSeverity.Error, Range = range }); } }