private static async Task VerifyTextSpanAsync(string code, int startLine, int startColumn, int endLine, int endColumn, TextSpan span) { using (var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic)) { var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", code); var data = new DiagnosticData( id: "test1", category: "Test", message: "test1 message", enuMessageForBingSearch: "test1 message format", severity: DiagnosticSeverity.Info, defaultSeverity: DiagnosticSeverity.Info, isEnabledByDefault: false, warningLevel: 1, projectId: document.Project.Id, customTags: ImmutableArray <string> .Empty, properties: ImmutableDictionary <string, string> .Empty, location: new DiagnosticDataLocation(document.Id, null, "originalFile1", startLine, startColumn, endLine, endColumn)); var text = await document.GetTextAsync(); var actual = data.GetExistingOrCalculatedTextSpan(text); Assert.Equal(span, actual); } }
private static async Task VerifyTextSpanAsync(string code, int startLine, int startColumn, int endLine, int endColumn, TextSpan span) { using var workspace = new TestWorkspace(composition: EditorTestCompositions.EditorFeatures); var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", code); var data = new DiagnosticData( id: "test1", category: "Test", message: "test1 message", severity: DiagnosticSeverity.Info, defaultSeverity: DiagnosticSeverity.Info, isEnabledByDefault: false, warningLevel: 1, projectId: document.Project.Id, customTags: ImmutableArray <string> .Empty, properties: ImmutableDictionary <string, string> .Empty, location: new DiagnosticDataLocation(document.Id, null, "originalFile1", startLine, startColumn, endLine, endColumn), language: document.Project.Language); var text = await document.GetTextAsync(); var actual = DiagnosticData.GetExistingOrCalculatedTextSpan(data.DataLocation, text); Assert.Equal(span, actual); }
private async Task <LanguageServer.Protocol.Diagnostic[]> GetDiagnosticsAsync(Solution solution, Document document, CancellationToken cancellationToken) { var diagnostics = _diagnosticService.GetDiagnostics(solution.Workspace, document.Project.Id, document.Id, null, false, cancellationToken); var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); return(diagnostics.Select(diagnostic => new LanguageServer.Protocol.Diagnostic { Code = diagnostic.Id, Message = diagnostic.Message, Severity = ProtocolConversions.DiagnosticSeverityToLspDiagnositcSeverity(diagnostic.Severity), Range = ProtocolConversions.TextSpanToRange(DiagnosticData.GetExistingOrCalculatedTextSpan(diagnostic.DataLocation, text), text), // Only the unnecessary diagnostic tag is currently supported via LSP. Tags = diagnostic.CustomTags.Contains("Unnecessary") ? new DiagnosticTag[] { DiagnosticTag.Unnecessary } : Array.Empty <DiagnosticTag>() }).ToArray()); }
private static void VerifyTextSpan(string code, int startLine, int startColumn, int endLine, int endColumn, TextSpan span) { using (var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic)) { var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", code); var data = new DiagnosticData( "test1", "Test", "test1 message", "test1 message format", DiagnosticSeverity.Info, false, 1, workspace, document.Project.Id, new DiagnosticDataLocation(document.Id, null, "originalFile1", startLine, startColumn, endLine, endColumn)); var text = document.GetTextAsync().Result; var actual = data.GetExistingOrCalculatedTextSpan(text); Assert.Equal(span, actual); } }