public void ConvertSpanToRange_StartsOutsideOfDocument_EmptyDocument_NormalizesTo0() { // Arrange var sourceText = SourceText.From(string.Empty); var sourceSpan = new SourceSpan(5, 0, 5, 4); var expectedRange = new Range( new Position(0, 0), new Position(0, 0)); // Act var range = RazorDiagnosticConverter.ConvertSpanToRange(sourceSpan, sourceText); // Assert Assert.Equal(expectedRange, range); }
public void Convert_Converts() { // Arrange var razorDiagnostic = RazorDiagnosticFactory.CreateDirective_BlockDirectiveCannotBeImported("test"); var sourceText = SourceText.From(string.Empty); // Act var diagnostic = RazorDiagnosticConverter.Convert(razorDiagnostic, sourceText); // Assert Assert.Equal(razorDiagnostic.Id, diagnostic.Code); Assert.Equal(razorDiagnostic.GetMessage(CultureInfo.InvariantCulture), diagnostic.Message); Assert.Null(diagnostic.Range); Assert.Equal(DiagnosticSeverity.Error, diagnostic.Severity); }
public void ConvertSpanToRange_ReturnsConvertedRange() { // Arrange var sourceSpan = new SourceSpan(3, 0, 3, 4); var sourceText = SourceText.From("Hello World"); var expectedRange = new Range( new Position(0, 3), new Position(0, 7)); // Act var range = RazorDiagnosticConverter.ConvertSpanToRange(sourceSpan, sourceText); // Assert Assert.Equal(expectedRange, range); }
public void ConvertSpanToRange_EndsOutsideOfDocument_NormalizesToEnd() { // Arrange var sourceText = SourceText.From("Hello World"); var sourceSpan = new SourceSpan(6, 0, 6, 15); var expectedRange = new Range( new Position(0, 6), new Position(0, 10)); // Act var range = RazorDiagnosticConverter.ConvertSpanToRange(sourceSpan, sourceText); // Assert Assert.Equal(expectedRange, range); }
public async Task PublishDiagnosticsAsync_NewDiagnosticsGetPublished() { // Arrange var processedOpenDocument = TestDocumentSnapshot.Create(OpenedDocument.FilePath); var codeDocument = CreateCodeDocument(SingleDiagnosticCollection); processedOpenDocument.With(codeDocument); var languageServerDocument = new Mock <ILanguageServerDocument>(); languageServerDocument.Setup(lsd => lsd.SendNotification(It.IsAny <string>(), It.IsAny <PublishDiagnosticsParams>())) .Callback <string, PublishDiagnosticsParams>((method, diagnosticParams) => { Assert.Equal(processedOpenDocument.FilePath.TrimStart('/'), diagnosticParams.Uri.AbsolutePath); var diagnostic = Assert.Single(diagnosticParams.Diagnostics); var razorDiagnostic = SingleDiagnosticCollection[0]; processedOpenDocument.TryGetText(out var sourceText); var expectedDiagnostic = RazorDiagnosticConverter.Convert(razorDiagnostic, sourceText); Assert.Equal(expectedDiagnostic.Message, diagnostic.Message); Assert.Equal(expectedDiagnostic.Severity, diagnostic.Severity); Assert.Equal(expectedDiagnostic.Range, diagnostic.Range); }).Verifiable(); var languageServer = new Mock <ILanguageServer>(); languageServer.Setup(server => server.Document).Returns(languageServerDocument.Object); using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServer.Object, LoggerFactory)) { publisher._publishedDiagnostics[processedOpenDocument.FilePath] = EmptyDiagnostics; publisher.Initialize(ProjectManager); // Act await publisher.PublishDiagnosticsAsync(processedOpenDocument); // Assert languageServerDocument.VerifyAll(); } }